public BlockValidationProviderTests() { _blockValidationService = GetRequiredService <IBlockValidationService>(); _blockValidationProvider = GetRequiredService <BlockValidationProvider>(); _transactionBlockIndexService = GetRequiredService <ITransactionBlockIndexService>(); _kernelTestHelper = GetRequiredService <KernelTestHelper>(); }
public BlockAttachService(IBlockchainService blockchainService, IBlockchainExecutingService blockchainExecutingService, IBlockValidationService blockValidationService) { _blockchainService = blockchainService; _blockchainExecutingService = blockchainExecutingService; _blockValidationService = blockValidationService; Logger = NullLogger <BlockAttachService> .Instance; }
// 这里如果直接传入ChainId,会发现构造器受限,这个依赖太具体了,改成用IChainIdProvider会好一些 // 组合根可以决定用哪个IChainIdProvider的实现 // 用IChainIdProvider的最大的好处是可以直接为BlockChainService注入别的依赖而不用再次修改组合根的代码(使用DI容器的时候) // 没理解可以看看提交历史 public BlockChainService(IChainIdProvider chainIdProvider, IBlockValidationService blockValidationService) { _blockValidationService = blockValidationService; ChainId = chainIdProvider.ChainId; // Null Object Pattern Logger = NullLogger.Instance; }
public BlockSyncValidationService(IAnnouncementCacheProvider announcementCacheProvider, IBlockValidationService blockValidationService, ITransactionManager transactionManager, ITransactionValidationService transactionValidationService) { Logger = NullLogger <BlockSyncValidationService> .Instance; _announcementCacheProvider = announcementCacheProvider; _blockValidationService = blockValidationService; _transactionManager = transactionManager; _transactionValidationService = transactionValidationService; }
public FullBlockchainExecutingService(IChainManager chainManager, IBlockchainService blockchainService, IBlockValidationService blockValidationService, IBlockExecutingService blockExecutingService, IBlockchainStateManager blockchainStateManager) { _chainManager = chainManager; _blockchainService = blockchainService; _blockValidationService = blockValidationService; _blockExecutingService = blockExecutingService; _blockchainStateManager = blockchainStateManager; LocalEventBus = NullLocalEventBus.Instance; }
public BlockSyncAttachService(IBlockchainService blockchainService, IBlockAttachService blockAttachService, IBlockValidationService validationService, IBlockSyncQueueService blockSyncQueueService) { Logger = NullLogger <BlockSyncAttachService> .Instance; _blockchainService = blockchainService; _blockAttachService = blockAttachService; _validationService = validationService; _blockSyncQueueService = blockSyncQueueService; }
public FullBlockchainExecutingService(IBlockchainService blockchainService, IBlockValidationService blockValidationService, IBlockExecutingService blockExecutingService, ITransactionResultService transactionResultService, IBlockStateSetManger blockStateSetManger) { _blockchainService = blockchainService; _blockValidationService = blockValidationService; _blockExecutingService = blockExecutingService; _transactionResultService = transactionResultService; _blockStateSetManger = blockStateSetManger; LocalEventBus = NullLocalEventBus.Instance; }
public Miner(IMinerConfig config, ITxHub txHub, IChainService chainService, IExecutingService executingService, ITransactionResultManager transactionResultManager, ILogger logger, ClientManager clientManager, IBinaryMerkleTreeManager binaryMerkleTreeManager, ServerManager serverManager, IBlockValidationService blockValidationService, IChainContextService chainContextService, IChainManagerBasic chainManagerBasic, IStateStore stateStore) { Config = config; _txHub = txHub; _chainService = chainService; _executingService = executingService; _transactionResultManager = transactionResultManager; _logger = logger; _clientManager = clientManager; _binaryMerkleTreeManager = binaryMerkleTreeManager; _serverManager = serverManager; _blockValidationService = blockValidationService; _chainContextService = chainContextService; _chainManagerBasic = chainManagerBasic; _txFilter = new TransactionFilter(); _dpoSInfoProvider = new DPoSInfoProvider(stateStore); _maxMineTime = ConsensusConfig.Instance.DPoSMiningInterval * NodeConfig.Instance.RatioMine; }
public BlockSynchronizer(IChainService chainService, IBlockValidationService blockValidationService, IBlockExecutor blockExecutor, IBlockSet blockSet, IBlockHeaderValidator blockHeaderValidator) { _chainService = chainService; _blockValidationService = blockValidationService; _blockExecutor = blockExecutor; _blockSet = blockSet; _blockHeaderValidator = blockHeaderValidator; _stateFSM = new NodeStateFSM().Create(); _logger = LogManager.GetLogger(nameof(BlockSynchronizer)); _terminated = false; _executeNextBlock = true; _syncHeight = ulong.MaxValue; MessageHub.Instance.Subscribe <StateEvent>(e => { _stateFSM.ProcessWithStateEvent(e); _logger?.Trace($"BlockSynchronizer CurrentState: {CurrentState}"); MessageHub.Instance.Publish(new FSMStateChanged(CurrentState)); }); MessageHub.Instance.Subscribe <EnteringState>(async inState => { if (inState.NodeState.ShouldLockMiningWhenEntering()) { MessageHub.Instance.Publish(new LockMining(true)); } switch (inState.NodeState) { case NodeState.Catching: await ReceiveNextValidBlock(); break; case NodeState.Caught: await ReceiveNextValidBlock(); break; case NodeState.ExecutingLoop: // This node is free to mine a block during executing maybe-incorrect block again and again. MessageHub.Instance.Publish(new LockMining(false)); break; case NodeState.GeneratingConsensusTx: MessageHub.Instance.Publish(new LockMining(false)); break; case NodeState.Reverting: await HandleFork(); break; } }); MessageHub.Instance.Subscribe <LeavingState>(inState => { if (inState.NodeState.ShouldUnlockMiningWhenLeaving()) { MessageHub.Instance.Publish(new LockMining(false)); } }); MessageHub.Instance.Subscribe <HeadersReceived>(async inHeaders => { if (inHeaders?.Headers == null || !inHeaders.Headers.Any()) { _logger?.Warn("Null headers or header list is empty."); return; } var headers = inHeaders.Headers.OrderByDescending(h => h.Index).ToList(); foreach (var blockHeader in headers) { // Get previous block from the chain var correspondingBlockHeader = await BlockChain.GetBlockByHeightAsync(blockHeader.Index - 1); // If the hash of this previous block corresponds to "previous block hash" of the current header // the link has been found if (correspondingBlockHeader.BlockHashToHex == blockHeader.PreviousBlockHash.DumpHex()) { // Launch header accepted event and return MessageHub.Instance.Publish(new HeaderAccepted(blockHeader)); return; } } // Launch unlinkable again with the last headers index MessageHub.Instance.Publish(new UnlinkableHeader(headers.Last())); }); MessageHub.Instance.Subscribe <DPoSStateChanged>(inState => { MessageHub.Instance.Publish(inState.IsMining ? StateEvent.MiningStart : StateEvent.MiningEnd); }); MessageHub.Instance.Subscribe <BlockMined>(inBlock => { // Update DPoS process. //MessageHub.Instance.Publish(UpdateConsensus.Update); AddMinedBlock(inBlock.Block); }); MessageHub.Instance.Subscribe <BlockMinedAndStored>(inBlock => { // Update DPoS process. MessageHub.Instance.Publish(UpdateConsensus.Update); HandleMinedAndStroedBlock(inBlock.Block); }); MessageHub.Instance.Subscribe <TerminationSignal>(signal => { if (signal.Module == TerminatedModuleEnum.BlockSynchronizer) { _terminated = true; MessageHub.Instance.Publish(new TerminatedModule(TerminatedModuleEnum.BlockSynchronizer)); } }); }