public BlockExecutor(IChainService chainService, IExecutingService executingService, ITransactionResultManager transactionResultManager, ClientManager clientManager, IBinaryMerkleTreeManager binaryMerkleTreeManager, ITxHub txHub, IChainManagerBasic chainManagerBasic, IStateStore stateStore) { _chainService = chainService; _executingService = executingService; _transactionResultManager = transactionResultManager; _clientManager = clientManager; _binaryMerkleTreeManager = binaryMerkleTreeManager; _txHub = txHub; _chainManagerBasic = chainManagerBasic; _stateStore = stateStore; _dpoSInfoProvider = new DPoSInfoProvider(_stateStore); _logger = LogManager.GetLogger(nameof(BlockExecutor)); MessageHub.Instance.Subscribe <DPoSStateChanged>(inState => _isMining = inState.IsMining); _executing = false; _prepareTerminated = false; _terminated = false; MessageHub.Instance.Subscribe <TerminationSignal>(signal => { if (signal.Module == TerminatedModuleEnum.BlockExecutor) { if (!_executing) { _terminated = true; MessageHub.Instance.Publish(new TerminatedModule(TerminatedModuleEnum.BlockExecutor)); } else { _prepareTerminated = true; } } }); MessageHub.Instance.Subscribe <StateEvent>(inState => { if (inState == StateEvent.RollbackFinished) { _isLimitExecutionTime = false; } if (inState == StateEvent.MiningStart) { _isLimitExecutionTime = true; } _logger?.Trace($"Current Event: {inState.ToString()} ,IsLimitExecutionTime: {_isLimitExecutionTime}"); }); }
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 DPoS(IStateStore stateStore, ITxHub txHub, IMiner miner, IChainService chainService) { _txHub = txHub; _miner = miner; _chainService = chainService; _prepareTerminated = false; _terminated = false; _logger = LogManager.GetLogger(nameof(DPoS)); Helper = new AElfDPoSHelper(Hash.LoadHex(ChainConfig.Instance.ChainId), Miners, ContractAddress, stateStore); Provider = new DPoSInfoProvider(stateStore); var count = MinersConfig.Instance.Producers.Count; GlobalConfig.BlockProducerNumber = count; GlobalConfig.BlockNumberOfEachRound = count + 1; _logger?.Info("Block Producer nodes count:" + GlobalConfig.BlockProducerNumber); _logger?.Info("Blocks of one round:" + GlobalConfig.BlockNumberOfEachRound); if (GlobalConfig.BlockProducerNumber == 1 && NodeConfig.Instance.IsMiner) { AElfDPoSObserver.RecoverMining(); } MessageHub.Instance.Subscribe <UpdateConsensus>(async option => { if (option == UpdateConsensus.Update) { _logger?.Trace("UpdateConsensus - Update"); await Update(); } if (option == UpdateConsensus.Dispose) { _logger?.Trace("UpdateConsensus - Dispose"); Stop(); } }); MessageHub.Instance.Subscribe <LockMining>(async inState => { if (inState.Lock) { IncrementLockNumber(); } else { await Start(); } }); MessageHub.Instance.Subscribe <TerminationSignal>(signal => { if (signal.Module == TerminatedModuleEnum.Mining) { _prepareTerminated = true; } }); MessageHub.Instance.Subscribe <FSMStateChanged>(inState => { CurrentState = inState.CurrentState; }); }