public HeaderValidator(IBlockTree blockTree, ISealEngine sealEngine, ISpecProvider specProvider, ILogManager logManager) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); _sealEngine = sealEngine ?? throw new ArgumentNullException(nameof(sealEngine)); _daoBlockNumber = specProvider?.DaoBlockNumber; }
public PostMergeBlockProducer( ITxSource txSource, IBlockchainProcessor processor, IBlockTree blockTree, IBlockProductionTrigger blockProductionTrigger, IStateProvider stateProvider, IGasLimitCalculator gasLimitCalculator, ISealEngine sealEngine, ITimestamper timestamper, ISpecProvider specProvider, ILogManager logManager) : base( txSource, processor, sealEngine, blockTree, blockProductionTrigger, stateProvider, gasLimitCalculator, timestamper, specProvider, logManager, ConstantDifficulty.Zero) { }
public MergeSealEngine( ISealEngine preMergeSealEngine, IPoSSwitcher?poSSwitcher, ISealValidator mergeSealValidator, ILogManager?logManager) { _preMergeSealValidator = preMergeSealEngine ?? throw new ArgumentNullException(nameof(preMergeSealEngine)); _poSSwitcher = poSSwitcher ?? throw new ArgumentNullException(nameof(poSSwitcher)); _mergeSealValidator = mergeSealValidator; }
public PostMergeBlockProducerFactory( ISpecProvider specProvider, ISealEngine sealEngine, ITimestamper timestamper, IMiningConfig miningConfig, ILogManager logManager, IGasLimitCalculator?gasLimitCalculator = null) { _specProvider = specProvider; _sealEngine = sealEngine; _timestamper = timestamper; _miningConfig = miningConfig; _logManager = logManager; _gasLimitCalculator = gasLimitCalculator; }
public MinedBlockProducer( IDifficultyCalculator difficultyCalculator, ITransactionPool transactionPool, IBlockchainProcessor processor, ISealEngine sealEngine, IBlockTree blockTree, ITimestamp timestamp, ILogManager logManager) { _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator)); _transactionPool = transactionPool ?? throw new ArgumentNullException(nameof(transactionPool)); _processor = processor ?? throw new ArgumentNullException(nameof(processor)); _sealEngine = sealEngine ?? throw new ArgumentNullException(nameof(sealEngine)); _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); _timestamp = timestamp; _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); }
public void Setup() { _ethash = new EthashSealEngine(new Ethash(NullLogManager.Instance), NullLogManager.Instance); _testLogger = new TestLogger(); BlockTree blockStore = new BlockTree(new MemDb(), new MemDb(), new MemDb(), FrontierSpecProvider.Instance, NullLogManager.Instance); DifficultyCalculator calculator = new DifficultyCalculator(new SingleReleaseSpecProvider(Frontier.Instance, ChainId.MainNet)); _validator = new HeaderValidator(calculator, blockStore, _ethash, new SingleReleaseSpecProvider(Byzantium.Instance, 3), new OneLoggerLogManager(_testLogger)); _parentBlock = Build.A.Block.WithDifficulty(1).TestObject; _block = Build.A.Block.WithParent(_parentBlock) .WithDifficulty(131072) .WithMixHash(new Keccak("0xd7db5fdd332d3a65d6ac9c4c530929369905734d3ef7a91e373e81d0f010b8e8")) .WithNonce(0).TestObject; blockStore.SuggestBlock(_parentBlock); blockStore.SuggestBlock(_block); }
public BlockchainProcessor( IBlockTree blockTree, ISealEngine sealEngine, ITransactionStore transactionStore, IDifficultyCalculator difficultyCalculator, IBlockProcessor blockProcessor, IEthereumSigner signer, ILogManager logManager) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); _blockTree.NewBestSuggestedBlock += OnNewBestBlock; _transactionStore = transactionStore ?? throw new ArgumentNullException(nameof(transactionStore)); _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator)); _sealEngine = sealEngine ?? throw new ArgumentNullException(nameof(sealEngine)); _blockProcessor = blockProcessor ?? throw new ArgumentNullException(nameof(blockProcessor)); _signer = signer ?? throw new ArgumentNullException(nameof(signer)); }
static BlockchainTestBase() { DifficultyCalculator = new DifficultuCalculatorWrapper(); SealEngine = new EthashSealEngine(new Ethash(_logManager), DifficultyCalculator, _logManager); // temporarily keep reusing the same one as otherwise it would recreate cache for each test }
private async Task InitBlockchain() { /* spec */ if (_chainSpec.ChainId == RopstenSpecProvider.Instance.ChainId) { _specProvider = RopstenSpecProvider.Instance; } else if (_chainSpec.ChainId == MainNetSpecProvider.Instance.ChainId) { _specProvider = MainNetSpecProvider.Instance; } else if (_chainSpec.ChainId == RinkebySpecProvider.Instance.ChainId) { _specProvider = RinkebySpecProvider.Instance; } else if (_chainSpec.ChainId == GoerliSpecProvider.Instance.ChainId) { _specProvider = GoerliSpecProvider.Instance; } else if (_chainSpec.ChainId == SturebySpecProvider.Instance.ChainId) { _specProvider = SturebySpecProvider.Instance; } else { _specProvider = new SingleReleaseSpecProvider(LatestRelease.Instance, _chainSpec.ChainId); } /* sync */ IDbConfig dbConfig = _configProvider.GetConfig<IDbConfig>(); foreach (PropertyInfo propertyInfo in typeof(IDbConfig).GetProperties()) { _logger.Info($"DB {propertyInfo.Name}: {propertyInfo.GetValue(dbConfig)}"); } _dbProvider = HiveEnabled ? (IDbProvider) new MemDbProvider() : new RocksDbProvider(_initConfig.BaseDbPath, dbConfig, _logManager, _initConfig.StoreTraces, _initConfig.StoreReceipts); _ethereumSigner = new EthereumSigner(_specProvider, _logManager); _transactionPool = new TransactionPool( new PersistentTransactionStorage(_dbProvider.PendingTxsDb, _specProvider), new PendingTransactionThresholdValidator(_initConfig.ObsoletePendingTransactionInterval, _initConfig.RemovePendingTransactionInterval), new Timestamp(), _ethereumSigner, _specProvider, _logManager, _initConfig.RemovePendingTransactionInterval, _initConfig.PeerNotificationThreshold); _receiptStorage = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider); // IDbProvider debugRecorder = new RocksDbProvider(Path.Combine(_dbBasePath, "debug"), dbConfig); // _dbProvider = new RpcDbProvider(_jsonSerializer, new BasicJsonRpcClient(KnownRpcUris.NethVm1, _jsonSerializer, _logManager), _logManager, debugRecorder); // IDbProvider debugReader = new ReadOnlyDbProvider(new RocksDbProvider(Path.Combine(_dbBasePath, "debug"), dbConfig)); // _dbProvider = debugReader; _blockTree = new BlockTree( _dbProvider.BlocksDb, _dbProvider.BlockInfosDb, _specProvider, _transactionPool, _logManager); CliqueConfig cliqueConfig = null; CliqueSealEngine clique = null; switch (_chainSpec.SealEngineType) { case SealEngineType.None: _sealEngine = NullSealEngine.Instance; _rewardCalculator = new NoBlockRewards(); break; case SealEngineType.Clique: _rewardCalculator = new NoBlockRewards(); cliqueConfig = new CliqueConfig(); cliqueConfig.BlockPeriod = _chainSpec.CliquePeriod; cliqueConfig.Epoch = _chainSpec.CliqueEpoch; _sealEngine = clique = new CliqueSealEngine(cliqueConfig, _ethereumSigner, _nodeKey, _dbProvider.BlocksDb, _blockTree, _logManager); _sealEngine.CanSeal = _initConfig.IsMining; break; case SealEngineType.NethDev: _rewardCalculator = new NoBlockRewards(); _sealEngine = NullSealEngine.Instance; break; case SealEngineType.Ethash: _rewardCalculator = new RewardCalculator(_specProvider); var difficultyCalculator = new DifficultyCalculator(_specProvider); _sealEngine = new EthashSealEngine(new Ethash(_logManager), difficultyCalculator, _logManager); break; default: throw new NotSupportedException($"Seal engine type {_chainSpec.SealEngineType} is not supported in Nethermind"); } _rewardCalculator = (_sealEngine is CliqueSealEngine) ? (IRewardCalculator) new NoBlockRewards() : new RewardCalculator(_specProvider); /* validation */ var headerValidator = new HeaderValidator( _blockTree, _sealEngine, _specProvider, _logManager); var ommersValidator = new OmmersValidator( _blockTree, headerValidator, _logManager); var txValidator = new TransactionValidator( new SignatureValidator(_specProvider.ChainId)); _blockValidator = new BlockValidator( txValidator, headerValidator, ommersValidator, _specProvider, _logManager); var stateTree = new StateTree(_dbProvider.StateDb); var stateProvider = new StateProvider( stateTree, _dbProvider.CodeDb, _logManager); _stateProvider = stateProvider; var storageProvider = new StorageProvider( _dbProvider.StateDb, stateProvider, _logManager); _transactionPoolInfoProvider = new TransactionPoolInfoProvider(stateProvider); /* blockchain processing */ var blockhashProvider = new BlockhashProvider( _blockTree); var virtualMachine = new VirtualMachine( stateProvider, storageProvider, blockhashProvider, _logManager); var transactionProcessor = new TransactionProcessor( _specProvider, stateProvider, storageProvider, virtualMachine, _logManager); var txRecoveryStep = new TxSignaturesRecoveryStep(_ethereumSigner, _transactionPool); _recoveryStep = _sealEngine is CliqueSealEngine ? new CompositeDataRecoveryStep(txRecoveryStep, new AuthorRecoveryStep(clique)) : (IBlockDataRecoveryStep) txRecoveryStep; _blockProcessor = new BlockProcessor( _specProvider, _blockValidator, _rewardCalculator, transactionProcessor, _dbProvider.StateDb, _dbProvider.CodeDb, _dbProvider.TraceDb, stateProvider, storageProvider, _transactionPool, _receiptStorage, _logManager); _blockchainProcessor = new BlockchainProcessor( _blockTree, _blockProcessor, _recoveryStep, _logManager, _initConfig.StoreReceipts, _initConfig.StoreTraces); // create shared objects between discovery and peer manager _nodeFactory = new NodeFactory(_logManager); IStatsConfig statsConfig = _configProvider.GetConfig<IStatsConfig>(); _nodeStatsProvider = new NodeStatsProvider(statsConfig, _nodeFactory, _logManager, !statsConfig.CaptureNodeStatsEventHistory); var encrypter = new AesEncrypter( _configProvider.GetConfig<IKeyStoreConfig>(), _logManager); _keyStore = new FileKeyStore( _configProvider.GetConfig<IKeyStoreConfig>(), _ethereumJsonSerializer, encrypter, _cryptoRandom, _logManager); if (_initConfig.IsMining) { IReadOnlyDbProvider minerDbProvider = new ReadOnlyDbProvider(_dbProvider, false); AlternativeChain producerChain = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, minerDbProvider, _recoveryStep, _logManager, _transactionPool, _receiptStorage); switch (_chainSpec.SealEngineType) { case SealEngineType.Clique: { // TODO: need to introduce snapshot provider for clique and pass it here instead of CliqueSealEngine if (_logger.IsWarn) _logger.Warn("Starting Clique block producer & sealer"); _blockProducer = new CliqueBlockProducer(_transactionPool, producerChain.Processor, _blockTree, producerChain.StateProvider, _timestamp, _cryptoRandom, (CliqueSealEngine)_sealEngine, cliqueConfig, _nodeKey.Address, _logManager); break; } case SealEngineType.NethDev: { if (_logger.IsWarn) _logger.Warn("Starting Dev block producer & sealer"); _blockProducer = new DevBlockProducer(_transactionPool, producerChain.Processor, _blockTree, _timestamp, _logManager); break; } default: throw new NotSupportedException($"Mining in {_chainSpec.SealEngineType} mode is not supported"); } _blockProducer.Start(); } if (!HiveEnabled) { _blockchainProcessor.Start(); LoadGenesisBlock(_chainSpec,string.IsNullOrWhiteSpace(_initConfig.GenesisHash) ? null : new Keccak(_initConfig.GenesisHash), _blockTree, stateProvider, _specProvider); if (_initConfig.ProcessingEnabled) { #pragma warning disable 4014 LoadBlocksFromDb(); #pragma warning restore 4014 } else { if (_logger.IsWarn) _logger.Warn( $"Shutting down processor due to {nameof(InitConfig)}.{nameof(InitConfig.ProcessingEnabled)} set to false"); await _blockchainProcessor.StopAsync(); } } await InitializeNetwork( _receiptStorage, headerValidator, txValidator); }