public BlockChain(Hash chainId, IChainManagerBasic chainManager, IBlockManagerBasic blockManager, ITransactionManager transactionManager, ITransactionTraceManager transactionTraceManager, IStateStore stateStore, IDataStore dataStore) : base( chainId, chainManager, blockManager, dataStore) { _transactionManager = transactionManager; _transactionTraceManager = transactionTraceManager; _stateStore = stateStore; _doingRollback = false; _prepareTerminated = false; _terminated = false; _logger = LogManager.GetLogger(nameof(BlockChain)); MessageHub.Instance.Subscribe <TerminationSignal>(signal => { if (signal.Module == TerminatedModuleEnum.BlockRollback) { if (!_doingRollback) { _terminated = true; MessageHub.Instance.Publish(new TerminatedModule(TerminatedModuleEnum.BlockRollback)); } else { _prepareTerminated = true; } } }); }
public SubFieldInfo(IStateStore stateStore, BinaryReader reader, Func <string, Type> typeResolver) { string typeName; int fixedBufferSize; Type type = reader.ReadType(typeResolver, out typeName, out fixedBufferSize); string name = reader.ReadString(); MemberInfo mmbr = type.GetProperty(name, TypeUtils.AllInstanceMembers) ?? (MemberInfo)type.GetField(name, TypeUtils.AllInstanceMembers); if (mmbr == null) { throw new SerializerException( "Unable to locate the field or property {0} on type {1}", name, type.ToDebugStr()); } Type fldType = reader.ReadType(typeResolver, out typeName, out fixedBufferSize); Type subFldType = mmbr.PropOrFieldType(); if (subFldType != fldType) { throw new SerializerException( "The type of {0} {1} on type {2} was expected to be {3}, but was {4}", mmbr is FieldInfo ? "field" : "property", name, type.ToDebugStr(), fldType, subFldType.ToDebugStr()); } MemberInfo = mmbr; Field = BaseField.FieldFromReader(stateStore, reader, typeResolver); }
public void Register(IStateStore store, StateRestoreCallback callback) { string storeName = store.Name; log.LogDebug("{LogPrefix}Registering state store {StoreName} to its state manager", logPrefix, storeName); if (registeredStores.ContainsKey(storeName)) { throw new ArgumentException($"{logPrefix} Store {storeName} has already been registered."); } var metadata = IsChangelogStateStore(storeName) ? new StateStoreMetadata { Store = store, ChangelogTopicPartition = GetStorePartition(storeName), RestoreCallback = callback, RecordConverter = StateManagerTools.ConverterForStore(store), Offset = null } : new StateStoreMetadata { Store = store, Offset = null }; registeredStores.Add(storeName, metadata); if (IsChangelogStateStore(storeName)) { changelogRegister.Register(GetStorePartition(storeName), this); } log.LogDebug($"{logPrefix}Registered state store {storeName} to its state manager"); }
public static async Task MoveAsync( IStateStore stateStore, CancellationToken cancellationToken) { long totalMoves = 0; long successfulMoves = 0; while (!cancellationToken.IsCancellationRequested) { totalMoves++; var obj = await ReadObjectAsync(stateStore, cancellationToken); if (obj != null) { if (await DataSender.SendData(obj.Name, obj.ToJson(), cancellationToken)) { obj.Move(Rotate); await WriteObjectAsync(stateStore, obj, cancellationToken); successfulMoves++; } } if ((totalMoves % 1000) == 0) { Console.WriteLine($"Completed {successfulMoves}/{totalMoves} sucessful moves."); } await Task.Delay(MoveSpeed); } }
public InMemoryStateStoreEntryReaderActorTest(ITestOutputHelper output) { var converter = new Converter(output); Console.SetOut(converter); var testWorld = TestWorld.StartWithDefaults("test-store"); var world = testWorld.World; _interest = new MockStateStoreResultInterest(); _dispatcher = new MockStateStoreDispatcher <IEntry <string>, TextState>(_interest); var stateAdapterProvider = new StateAdapterProvider(world); _entryAdapterProvider = new EntryAdapterProvider(world); stateAdapterProvider.RegisterAdapter(new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default _store = world.ActorFor <IStateStore <IEntry <string> > >(typeof(InMemoryStateStoreActor <TextState, IEntry <string> >), _dispatcher); var completes = _store.EntryReader("test"); _reader = completes.Await(); StateTypeStateStoreMap.StateTypeToStoreName(typeof(Entity1).FullName, typeof(Entity1)); StateTypeStateStoreMap.StateTypeToStoreName(typeof(Entity2).FullName, typeof(Entity2)); }
private void Initialize() { _transactionManager = new TransactionManager(_dataStore, _logger); _transactionReceiptManager = new TransactionReceiptManager(_database); _smartContractManager = new SmartContractManager(_dataStore); _transactionResultManager = new TransactionResultManager(_dataStore); _transactionTraceManager = new TransactionTraceManager(_dataStore); _functionMetadataService = new FunctionMetadataService(_dataStore, _logger); _chainManagerBasic = new ChainManagerBasic(_dataStore); _chainService = new ChainService(_chainManagerBasic, new BlockManagerBasic(_dataStore), _transactionManager, _transactionTraceManager, _dataStore, StateStore); _smartContractRunnerFactory = new SmartContractRunnerFactory(); /*var runner = new SmartContractRunner("../../../../AElf.SDK.CSharp/bin/Debug/netstandard2.0/"); * _smartContractRunnerFactory.AddRunner(0, runner);*/ var runner = new SmartContractRunner(ContractCodes.TestContractFolder); _smartContractRunnerFactory.AddRunner(0, runner); _concurrencyExecutingService = new SimpleExecutingService( new SmartContractService(_smartContractManager, _smartContractRunnerFactory, StateStore, _functionMetadataService), _transactionTraceManager, StateStore, new ChainContextService(_chainService)); _chainCreationService = new ChainCreationService(_chainService, new SmartContractService(new SmartContractManager(_dataStore), _smartContractRunnerFactory, StateStore, _functionMetadataService), _logger); _binaryMerkleTreeManager = new BinaryMerkleTreeManager(_dataStore); _chainContextService = new ChainContextService(_chainService); _stateStore = new StateStore(_database); }
private void NewStorage() { var db = new InMemoryDatabase(); StateStore = new StateStore(db); _dataStore = new DataStore(db); }
private static void RegisterStateStore(this IServiceCollection services, Action <IStateStoreOptionsBuilder> options) { if (options == null) { services.AddSingleton <IStateStore, FileStateStore>(); return; } StateStoreOptionsBuilder optionsBuilder = new StateStoreOptionsBuilder(); options.Invoke(optionsBuilder); IStateStore instance = optionsBuilder.GetStateStoreInstance(); if (instance != null) { services.AddSingleton(instance); return; } Type type = optionsBuilder.GetStateStoreType(); if (type != null) { services.AddSingleton(typeof(IStateStore), type); } }
/// <summary> /// Initializes this state store and open rocksdb database. /// </summary> /// <param name="context">Processor context</param> /// <param name="root">Root state (always itself)</param> public void Init(ProcessorContext context, IStateStore root) { OpenDatabase(context); // TODO : batch restoration behavior context.Register(root, (k, v, t) => Put(k, v)); }
public InMemoryStateStoreTest(ITestOutputHelper output) { var converter = new Converter(output); Console.SetOut(converter); var testWorld = TestWorld.StartWithDefaults("test-store"); _world = testWorld.World; _interest = new MockStateStoreResultInterest(); _dispatcher = new MockStateStoreDispatcher <TextEntry, TextState>(_interest); var stateAdapterProvider = new StateAdapterProvider(_world); new EntryAdapterProvider(_world); stateAdapterProvider.RegisterAdapter(new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default _store = _world.ActorFor <IStateStore <TextEntry> >(typeof(InMemoryStateStoreActor <TextState, TextEntry>), _dispatcher); StateTypeStateStoreMap.StateTypeToStoreName(_storeName1, typeof(Entity1)); StateTypeStateStoreMap.StateTypeToStoreName(_storeName2, typeof(Entity2)); }
public Benchmarks(IStateStore stateStore, IChainCreationService chainCreationService, IChainContextService chainContextService, ISmartContractService smartContractService, ILogger logger, IFunctionMetadataService functionMetadataService, BenchmarkOptions options, IExecutingService executingService) { ChainId = Hash.Generate(); _stateStore = stateStore; _chainCreationService = chainCreationService; _smartContractService = smartContractService; _logger = logger; _options = options; _executingService = executingService; _servicePack = new ServicePack { ChainContextService = chainContextService, SmartContractService = _smartContractService, ResourceDetectionService = new ResourceUsageDetectionService(functionMetadataService), StateStore = _stateStore }; _dataGenerater = new TransactionDataGenerator(options); byte[] code; using (FileStream file = File.OpenRead(Path.GetFullPath(options.DllDir + "/" + options.ContractDll))) { code = file.ReadFully(); } _contractHash = Prepare(code).Result; }
public static async Task TestParallelFunctionalityAsync( this IStateStore store, int activeChannelCount = 10, int stepBlockcount = 100, int passiveChannelCount = 1000) { await Task.WhenAll(Enumerable .Range(0, passiveChannelCount) .Select(i => store.AddAsync($"passive_{i}", "state0"))) .ConfigureAwait(false); await Task.WhenAll(Enumerable .Range(0, activeChannelCount) .Select(async i => { for (int j = 0; j < stepBlockcount; j++) { await TestBasicFunctionalityAsync(store, i.ToString()).ConfigureAwait(false); } })) .ConfigureAwait(false); await Task.WhenAll(Enumerable .Range(0, passiveChannelCount) .Select(i => store.RemoveAsync($"passive_{i}", "state0"))) .ConfigureAwait(false); }
public InMemoryStateStoreRedispatchControlTest(ITestOutputHelper output) { var converter = new Converter(output); Console.SetOut(converter); _world = World.StartWithDefaults("test-store"); _interest = new MockStateStoreResultInterest(); _interest.AfterCompleting <string, Entity1>(0); _dispatcher = new MockStateStoreDispatcher <TextState>(_interest); var stateAdapterProvider = new StateAdapterProvider(_world); new EntryAdapterProvider(_world); stateAdapterProvider.RegisterAdapter(new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default StateTypeStateStoreMap.StateTypeToStoreName(typeof(Entity1).FullName, typeof(Entity1)); _store = _world.ActorFor <IStateStore>(typeof(InMemoryStateStoreActor <TextState>), new List <IDispatcher> { _dispatcher }); }
// Copied from BlockChain<T>.SetStates(). private static void SetStates( Guid chainId, IStateStore stateStore, Block <NCAction> block, IReadOnlyList <ActionEvaluation> actionEvaluations, bool buildStateReferences ) { IImmutableSet <Address> stateUpdatedAddresses = actionEvaluations .SelectMany(a => a.OutputStates.StateUpdatedAddresses) .ToImmutableHashSet(); IImmutableSet <(Address, Currency)> updatedFungibleAssets = actionEvaluations .SelectMany(a => a.OutputStates.UpdatedFungibleAssets .SelectMany(kv => kv.Value.Select(c => (kv.Key, c)))) .ToImmutableHashSet(); if (!stateStore.ContainsBlockStates(block.Hash)) { var totalDelta = GetTotalDelta(actionEvaluations, ToStateKey, ToFungibleAssetKey); stateStore.SetStates(block, totalDelta); } if (buildStateReferences && stateStore is IBlockStatesStore blockStatesStore) { IImmutableSet <string> stateUpdatedKeys = stateUpdatedAddresses .Select(ToStateKey) .ToImmutableHashSet(); IImmutableSet <string> assetUpdatedKeys = updatedFungibleAssets .Select(ToFungibleAssetKey) .ToImmutableHashSet(); IImmutableSet <string> updatedKeys = stateUpdatedKeys.Union(assetUpdatedKeys); blockStatesStore.StoreStateReference(chainId, updatedKeys, block.Hash, block.Index); } }
public DefaultAuthServer( IClientValidator clientValidator , ITokenGenerator tokenGenerator , IAuthCodeStore authCodeStore , ITokenInfoStore tokenStore , IStateStore stateStore , IAuthCodeGenerator authCodeGenerator , IResourceOwnerValidator resourceOwnerValidator , ILogger <DefaultAuthServer> logger , AuthServerOptions options , IPkceValidator pkceValidator , IConfiguration configuration ) { _clientValidator = clientValidator; _tokenGenerator = tokenGenerator; _resourceOwnerValidator = resourceOwnerValidator; _logger = logger; _authCodeStore = authCodeStore; _tokenStore = tokenStore; _stateStore = stateStore; _authCodeGenerator = authCodeGenerator; _pkceValidator = pkceValidator; _configuration = configuration; TokenRequestHandler = HandleTokenRequestAsync; AuthorizeRequestHandler = HandleAuthorizeRequestAsync; EndSessionRequestHandler = HandleEndSessionRequestAsync; ClearTokenRequestHandler = HandleClearTokenRequestAsync; AuthServerOptions = options; }
public ProjectionDispatcherTest(ITestOutputHelper output) { var converter = new Converter(output); Console.SetOut(converter); World = World.StartWithDefaults("test-store"); var stateAdapterProvider = new StateAdapterProvider(World); stateAdapterProvider.RegisterAdapter(new Entity1StateAdapter()); new EntryAdapterProvider(World); StateTypeStateStoreMap.StateTypeToStoreName(nameof(Entity1), typeof(Entity1)); StateTypeStateStoreMap.StateTypeToStoreName(nameof(Entity2), typeof(Entity2)); var dispatcherProtocols = World.Stage.ActorFor( new[] { DispatcherInterfaceType, typeof(IProjectionDispatcher) }, ProjectionDispatcherType); var dispatchers = Protocols.Two <IDispatcher, IProjectionDispatcher>(dispatcherProtocols); Dispatcher = dispatchers._1; ProjectionDispatcher = dispatchers._2; var storeProtocols = World.ActorFor( new[] { StateStoreInterfaceType, typeof(IDispatcherControl) }, typeof(InMemoryStateStoreActor <TextState>), Dispatcher); var storeWithControl = Protocols.Two <IStateStore, IDispatcherControl>(storeProtocols); Store = storeWithControl._1; DispatcherControl = storeWithControl._2; }
public void RegisterAll(IStateStore stateStore, Type[] types) { foreach (var type in types) { Register(new Info(stateStore, type, type.Name)); } }
internal static IStateStoreService Create() { IStateStore stateStore = Substitute.For <IStateStore>(); IStateStoreService stateStoreSvc = new StateStoreService(stateStore); return(stateStoreSvc); }
public async Task GlobalSetup() { _chains = GetRequiredService <IBlockchainStore <Chain> >(); _chainStateInfoCollection = GetRequiredService <IStateStore <ChainStateInfo> >(); _blockchainStateService = GetRequiredService <IBlockchainStateService>(); _blockStateSetManger = GetRequiredService <IBlockStateSetManger>(); _blockchainService = GetRequiredService <IBlockchainService>(); _osTestHelper = GetRequiredService <OSTestHelper>(); _chainManager = GetRequiredService <IChainManager>(); _blockManager = GetRequiredService <IBlockManager>(); _transactionManager = GetRequiredService <ITransactionManager>(); _transactionPoolService = GetRequiredService <ITransactionPoolService>(); _blockStateSets = new List <BlockStateSet>(); _blocks = new List <Block>(); _chain = await _blockchainService.GetChainAsync(); var blockHash = _chain.BestChainHash; while (true) { var blockState = await _blockStateSetManger.GetBlockStateSetAsync(blockHash); _blockStateSets.Add(blockState); var blockHeader = await _blockchainService.GetBlockHeaderByHashAsync(blockHash); blockHash = blockHeader.PreviousBlockHash; if (blockHash == _chain.LastIrreversibleBlockHash) { break; } } await _blockchainStateService.MergeBlockStateAsync(_chain.BestChainHeight, _chain.BestChainHash); for (var i = 0; i < BlockCount; i++) { var transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount); await _osTestHelper.BroadcastTransactions(transactions); var block = await _osTestHelper.MinedOneBlock(); _blocks.Add(block); var blockState = await _blockStateSetManger.GetBlockStateSetAsync(block.GetHash()); _blockStateSets.Add(blockState); } var chain = await _blockchainService.GetChainAsync(); await _chainManager.SetIrreversibleBlockAsync(chain, chain.BestChainHash); _chainStateInfo = await _chainStateInfoCollection.GetAsync(chain.Id.ToStorageKey()); }
/// <summary> /// Answer a new <see cref="StatefulTypeRegistry"/> after registering all all <paramref name="types"/> with <paramref name="stateStore"/> /// using the default store name for each of the <paramref name="types"/>. /// </summary> /// <param name="world">The World to which I am registered.</param> /// <param name="stateStore"><see cref="IStateStore"/>.</param> /// <param name="types">The native type of states to be stored.</param> /// <returns>The registry</returns> public static StatefulTypeRegistry RegisterAll(World world, IStateStore stateStore, params Type[] types) { var registry = ResolveStatefulTypeRegistry(world); registry.RegisterAll(stateStore, types); return(registry); }
/// <summary> /// Construct my default state. /// </summary> /// <param name="stateType">The type of state store state</param> /// <param name="storeName">The string name of the Store</param> /// <param name="store">The store</param> public Info(IStateStore store, Type stateType, string storeName) { Store = store; StoreType = stateType; StoreName = storeName; EntryAdapterProvider = new EntryAdapterProvider(); StateAdapterProvider = new StateAdapterProvider(); }
public ComplexField([NotNull] IStateStore stateStore, [NotNull] Type fieldType, string stateName) : base(Versions.Ver1, stateStore, fieldType, stateName) { if (fieldType.IsArray || fieldType.IsPrimitive) { throw new SerializerException("Unsupported type {0}", fieldType); } }
public SmartContractService(ISmartContractManager smartContractManager, ISmartContractRunnerFactory smartContractRunnerFactory, IStateStore stateStore, IFunctionMetadataService functionMetadataService) { _smartContractManager = smartContractManager; _smartContractRunnerFactory = smartContractRunnerFactory; _stateStore = stateStore; _functionMetadataService = functionMetadataService; }
static Func <IEvent[], Task> OnPublish(this IStateStore stateManager, Func <IEvent[], Task> publish) => events => Task.WhenAll(events .GroupBy(x => x.GetKey()) .Select(async x => { await publish(x.ToArray()); await stateManager.CompleteOutBoxAsync(x.ToArray()); }));
public AElfDPoSHelper(Hash chainId, Miners miners, Address contractAddressHash, IStateStore stateStore) { _chainId = chainId; _miners = miners; _contractAddressHash = contractAddressHash; _stateStore = stateStore; _logger = LogManager.GetLogger(nameof(AElfDPoSHelper)); }
public SimpleExecutingService(ISmartContractService smartContractService, ITransactionTraceManager transactionTraceManager, IStateStore stateStore, IChainContextService chainContextService) { _smartContractService = smartContractService; _transactionTraceManager = transactionTraceManager; _chainContextService = chainContextService; _stateStore = stateStore; }
public DaprDateTimeCache( ILogger <DaprDateTimeCache> logger, IStateStore <DateTime> stateStore, IOptions <InfrastructureDaprOptions> opt) { _logger = logger; _stateStore = stateStore; _opt = opt.Value; }
/// <summary> /// Integer and Float delta serializer. /// </summary> /// <param name="stateStore">Serializer with the state</param> /// <param name="fieldType">Type of value to store</param> /// <param name="stateName">Name of the value (for debugging)</param> public ScaledDeltaField([NotNull] IStateStore stateStore, [NotNull] Type fieldType, string stateName) : base(Versions.Ver0, stateStore, fieldType, stateName) { // Floating point numbers must manually initialize Multiplier _multiplier = fieldType.IsPrimitive && (fieldType == typeof(float) || fieldType == typeof(double)) ? 0 : 1; }
public BlockStateSetManger(IStateStore <VersionedState> versionedStates, INotModifiedCachedStateStore <BlockStateSet> blockStateSets, IStateStore <ChainStateInfo> chainStateInfoCollection, IOptionsSnapshot <ChainOptions> options) { _versionedStates = versionedStates; _blockStateSets = blockStateSets; _chainStateInfoCollection = chainStateInfoCollection; _chainId = options.Value.ChainId; }
/// <summary> /// Construct my final state with the <see cref="IStateStore"/>, which must /// be provided by my concrete extenders, as well as with a /// <see cref="IStateAdapter"/> and a <see cref="IEntryAdapter{TSource,TEntry}"/>. /// </summary> /// <param name="stateStore">The <see cref="IStateStore"/> from which previous state is read and merged current state is written</param> /// <param name="stateAdapter">The <see cref="IStateAdapter"/> used by my extenders to adapt persistent state</param> /// <param name="entryAdapter">The <see cref="IEntryAdapter{TSource,TEntry}"/> used by my extenders to adapt persistent entries</param> public StateStoreProjectionActor(IStateStore stateStore, IStateAdapter stateAdapter, IEntryAdapter entryAdapter) { _stateStore = stateStore; _stateAdapter = stateAdapter; _entryAdapter = entryAdapter; _readInterest = SelfAs <IReadResultInterest>(); _writeInterest = SelfAs <IWriteResultInterest>(); _adaptedSources = new List <ISource>(); }
/// <param name="version"></param> /// <param name="stateStore"></param> /// <param name="fieldType">Type of value to store</param> /// <param name="stateName">Name of the value (for debugging)</param> protected BaseField( Version version, [NotNull] IStateStore stateStore, [NotNull] Type fieldType, string stateName = null) { if (stateStore == null) throw new ArgumentNullException("stateStore"); if (fieldType == null) throw new ArgumentNullException("fieldType"); _version = version; FieldType = fieldType; _stateStore = stateStore; _stateName = stateName; }
public StateManager(IStateStore stateStore) { log.InfoFormat("st mgr created with store at {0}", DateTime.Now.ToShortTimeString()); this.stateStore = stateStore; }
// TODO : Convert StateManager to work with IOC public StateManager() { log.InfoFormat("st mgr created {0}", DateTime.Now.ToShortTimeString()); this.stateStore = new StateStore(); }
public static BaseField FieldFromReader( IStateStore stateStore, BinaryReader reader, Func<string, Type> typeResolver) { var fld = reader.ReadTypeAndInstantiate<BaseField>(typeResolver, true); fld.StateStore = stateStore; fld.InitExistingField(reader, typeResolver); fld.EnsureReadonly(); return fld; }
// ReSharper restore UnusedMember.Local /// <summary> /// IncrementalIndex custom serializer. /// Keep the parameters intact, the field creator will call it through reflection in case /// [Field(typeof(IncrementalIndex))] attribute is set on a field or a type. /// </summary> /// <param name="stateStore">Serializer with the state</param> /// <param name="fieldType">Type of value to store</param> /// <param name="stateName">Name of the value (default state variable in the form "root.SubField.SubSubField...")</param> public IncrementalIndex(IStateStore stateStore, Type fieldType, string stateName) : base(Versions.Ver0, stateStore, fieldType, stateName) { }
public ObjectStateManager(IHashHelper hashHelper, IStateStore stateStore) { _hashHelper = Guard.EnsureIsNotNull("hashHelper", hashHelper); //InitialObjectStates = new ConcurrentDictionary<string, InitialObjectState>(); }