public BlockProducerEnvFactory( IDbProvider dbProvider, IBlockTree blockTree, IReadOnlyTrieStore readOnlyTrieStore, ISpecProvider specProvider, IBlockValidator blockValidator, IRewardCalculatorSource rewardCalculatorSource, IReceiptStorage receiptStorage, IBlockPreprocessorStep blockPreprocessorStep, ITxPool txPool, ITransactionComparerProvider transactionComparerProvider, IMiningConfig miningConfig, ILogManager logManager) { _dbProvider = dbProvider; _blockTree = blockTree; _readOnlyTrieStore = readOnlyTrieStore; _specProvider = specProvider; _blockValidator = blockValidator; _rewardCalculatorSource = rewardCalculatorSource; _receiptStorage = receiptStorage; _blockPreprocessorStep = blockPreprocessorStep; _txPool = txPool; _transactionComparerProvider = transactionComparerProvider; _miningConfig = miningConfig; _logManager = logManager; TransactionsExecutorFactory = new BlockProducerTransactionsExecutorFactory(specProvider, logManager); }
public IBlockchainBridge CreateBlockchainBridge() { ReadOnlyBlockTree readOnlyTree = new ReadOnlyBlockTree(BlockTree); IReadOnlyDbProvider readOnlyDbProvider = new ReadOnlyDbProvider(DbProvider, false); ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv = new ReadOnlyTxProcessingEnv( readOnlyDbProvider, readOnlyTree, SpecProvider, LogManager); IMiningConfig miningConfig = ConfigProvider.GetConfig <IMiningConfig>(); ISyncConfig syncConfig = ConfigProvider.GetConfig <ISyncConfig>(); return(new BlockchainBridge( readOnlyTxProcessingEnv, TxPool, ReceiptFinder, FilterStore, FilterManager, EthereumEcdsa, Timestamper, LogFinder, miningConfig.Enabled, syncConfig.BeamSync && syncConfig.FastSync )); }
private static ITxFilter CreateBaseAuRaTxFilter( IMiningConfig miningConfig, AuRaNethermindApi api, IReadOnlyTxProcessorSource readOnlyTxProcessorSource, IDictionaryContractDataStore <TxPriorityContract.Destination>?minGasPricesContractDataStore, ISpecProvider specProvider) { IMinGasPriceTxFilter minGasPriceTxFilter = CreateStandardMinGasPriceTxFilter(miningConfig, specProvider); ITxFilter gasPriceTxFilter = minGasPriceTxFilter; if (minGasPricesContractDataStore != null) { gasPriceTxFilter = new MinGasPriceContractTxFilter(minGasPriceTxFilter, minGasPricesContractDataStore); } Address?registrar = api.ChainSpec?.Parameters.Registrar; if (registrar != null) { RegisterContract registerContract = new(api.AbiEncoder, registrar, readOnlyTxProcessorSource); CertifierContract certifierContract = new(api.AbiEncoder, registerContract, readOnlyTxProcessorSource); return(new TxCertifierFilter(certifierContract, gasPriceTxFilter, specProvider, api.LogManager)); } return(gasPriceTxFilter); }
public AuRaValidatorFactory(IStateProvider stateProvider, IAbiEncoder abiEncoder, ITransactionProcessor transactionProcessor, IReadOnlyTxProcessorSource readOnlyTxProcessorSource, IBlockTree blockTree, IReceiptFinder receiptFinder, IValidatorStore validatorStore, IBlockFinalizationManager finalizationManager, ITxSender txSender, ITxPool txPool, IMiningConfig miningConfig, ILogManager logManager, ISigner signer, ReportingContractBasedValidator.Cache reportingValidatorCache, long posdaoTransition, bool forSealing = false) { _stateProvider = stateProvider; _abiEncoder = abiEncoder; _transactionProcessor = transactionProcessor; _readOnlyTxProcessorSource = readOnlyTxProcessorSource; _blockTree = blockTree; _receiptFinder = receiptFinder; _validatorStore = validatorStore; _finalizationManager = finalizationManager; _txSender = txSender; _txPool = txPool; _miningConfig = miningConfig; _logManager = logManager; _signer = signer; _reportingValidatorCache = reportingValidatorCache; _posdaoTransition = posdaoTransition; _forSealing = forSealing; }
public IBlockchainBridge CreateBlockchainBridge() { ReadOnlyBlockTree readOnlyTree = BlockTree.AsReadOnly(); LazyInitializer.EnsureInitialized(ref _readOnlyDbProvider, () => new ReadOnlyDbProvider(DbProvider, false)); // TODO: reuse the same trie cache here ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv = new( _readOnlyDbProvider, ReadOnlyTrieStore, readOnlyTree, SpecProvider, LogManager); IMiningConfig miningConfig = ConfigProvider.GetConfig <IMiningConfig>(); ISyncConfig syncConfig = ConfigProvider.GetConfig <ISyncConfig>(); return(new BlockchainBridge( readOnlyTxProcessingEnv, TxPool, ReceiptFinder, FilterStore, FilterManager, EthereumEcdsa, Timestamper, LogFinder, miningConfig.Enabled, syncConfig.BeamSync && syncConfig.FastSync )); }
public TxGasPriceSender(ITxSender txSender, ITxPool txPool, IMiningConfig miningConfig, uint percentDelta = TxGasPriceSenderConstants.DefaultPercentMultiplier) { _txSender = txSender ?? throw new ArgumentNullException(nameof(txSender)); _txPool = txPool ?? throw new ArgumentNullException(nameof(txPool)); _miningConfig = miningConfig ?? throw new ArgumentNullException(nameof(miningConfig)); _percentDelta = percentDelta; }
public DevBlockProducer( ITxSource txSource, IBlockchainProcessor processor, IStateProvider stateProvider, IBlockTree blockTree, IBlockProcessingQueue blockProcessingQueue, ITxPool txPool, ITimestamper timestamper, ISpecProvider specProvider, IMiningConfig miningConfig, ILogManager logManager) : base( txSource, processor, new NethDevSealEngine(), blockTree, blockProcessingQueue, stateProvider, FollowOtherMiners.Instance, timestamper, specProvider, logManager) { _txPool = txPool ?? throw new ArgumentNullException(nameof(txPool)); _miningConfig = miningConfig ?? throw new ArgumentNullException(nameof(miningConfig)); _timer = new Timer(_timeout.TotalMilliseconds); _timer.Elapsed += TimerOnElapsed; _timer.AutoReset = false; }
public async Task Execute(CancellationToken _) { IMiningConfig miningConfig = _api.Config <IMiningConfig>(); if (miningConfig.Enabled) { if (_api.BlockProducer == null) { throw new StepDependencyException(nameof(_api.BlockProducer)); } if (_api.BlockTree == null) { throw new StepDependencyException(nameof(_api.BlockTree)); } ILogger logger = _api.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn($"Starting {_api.SealEngineType} block producer & sealer"); } ProducedBlockSuggester suggester = new(_api.BlockTree, _api.BlockProducer); _api.DisposeStack.Push(suggester); _api.BlockProducer.Start(); } }
public async Task Execute(CancellationToken _) { IMiningConfig miningConfig = _api.Config <IMiningConfig>(); if (miningConfig.Enabled) { _api.BlockProducer = await BuildProducer(); } }
public static ITxFilter CreateAuRaTxFilter( IMiningConfig miningConfig, AuRaNethermindApi api, IReadOnlyTxProcessorSource readOnlyTxProcessorSource, IDictionaryContractDataStore <TxPriorityContract.Destination>?minGasPricesContractDataStore) { ITxFilter baseAuRaTxFilter = CreateBaseAuRaTxFilter(miningConfig, api, readOnlyTxProcessorSource, minGasPricesContractDataStore); ITxFilter?txPermissionFilter = CreateTxPermissionFilter(api, readOnlyTxProcessorSource); return(txPermissionFilter != null ? new CompositeTxFilter(baseAuRaTxFilter, txPermissionFilter) : baseAuRaTxFilter); }
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; }
protected BlockProducerContext GetProducerChain(IBlockTree blockTree, IDbProvider dbProvider, IReadOnlyTrieStore readOnlyTrieStore, IBlockPreprocessorStep blockPreprocessor, ITxPool txPool, IBlockValidator blockValidator, IRewardCalculatorSource rewardCalculatorSource, IReceiptStorage receiptStorage, ISpecProvider specProvider, IMiningConfig miningConfig, ILogManager logManager) { ReadOnlyDbProvider readOnlyDbProvider = dbProvider.AsReadOnly(false); ReadOnlyBlockTree readOnlyBlockTree = blockTree.AsReadOnly(); ReadOnlyTxProcessingEnv txProcessingEnv = new(readOnlyDbProvider, readOnlyTrieStore, readOnlyBlockTree, specProvider, logManager); ITransactionComparerProvider transactionComparerProvider = new TransactionComparerProvider(specProvider, blockTree); BlockProcessor blockProcessor = CreateBlockProcessor(txProcessingEnv, specProvider, blockValidator, rewardCalculatorSource, txPool, receiptStorage, logManager); IBlockchainProcessor blockchainProcessor = new BlockchainProcessor( readOnlyBlockTree, blockProcessor, blockPreprocessor, logManager, BlockchainProcessor.Options.NoReceipts); OneTimeChainProcessor chainProcessor = new( readOnlyDbProvider, blockchainProcessor); return(new BlockProducerContext { ChainProcessor = chainProcessor, ReadOnlyStateProvider = txProcessingEnv.StateProvider, TxSource = CreateTxSourceForProducer(txProcessingEnv, txPool, specProvider, logManager, miningConfig, transactionComparerProvider), ReadOnlyTxProcessingEnv = txProcessingEnv }); }
public ReportingContractBasedValidator( ContractBasedValidator contractValidator, IReportingValidatorContract reportingValidatorContract, long posdaoTransition, ITxSender txSender, ITxPool txPool, IMiningConfig miningConfig, IReadOnlyStateProvider stateProvider, Cache cache, ILogManager logManager) { _contractValidator = contractValidator ?? throw new ArgumentNullException(nameof(contractValidator)); ValidatorContract = reportingValidatorContract ?? throw new ArgumentNullException(nameof(reportingValidatorContract)); _posdaoTransition = posdaoTransition; _posdaoTxSender = txSender ?? throw new ArgumentNullException(nameof(txSender)); _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); _cache = cache ?? throw new ArgumentNullException(nameof(cache)); _nonPosdaoTxSender = new TxGasPriceSender(txSender, txPool, miningConfig); _persistentReports = cache.PersistentReports ?? throw new ArgumentNullException(nameof(cache)); _logger = logManager?.GetClassLogger <ReportingContractBasedValidator>() ?? throw new ArgumentNullException(nameof(logManager)); }
public override Eth2BlockProducer Create( IBlockTree blockTree, IDbProvider dbProvider, IReadOnlyTrieStore readOnlyTrieStore, IBlockPreprocessorStep blockPreprocessor, ITxPool txPool, IBlockValidator blockValidator, IRewardCalculatorSource rewardCalculatorSource, IReceiptStorage receiptStorage, IBlockProcessingQueue blockProcessingQueue, ISpecProvider specProvider, ISigner engineSigner, IMiningConfig miningConfig, ILogManager logManager) { BlockProducerContext producerContext = GetProducerChain( blockTree, dbProvider, readOnlyTrieStore, blockPreprocessor, txPool, blockValidator, rewardCalculatorSource, receiptStorage, specProvider, miningConfig, logManager); return(new Eth2TestBlockProducer( producerContext.TxSource, producerContext.ChainProcessor, blockTree, blockProcessingQueue, producerContext.ReadOnlyStateProvider, new TargetAdjustedGasLimitCalculator(specProvider, miningConfig), engineSigner, specProvider, logManager)); }
public Task Execute(CancellationToken _) { IMiningConfig miningConfig = _api.Config <IMiningConfig>(); if (miningConfig.Enabled) { BuildProducer(); if (_api.BlockProducer == null) { throw new StepDependencyException(nameof(_api.BlockProducer)); } ILogger logger = _api.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn($"Starting {_api.SealEngineType} block producer & sealer"); } _api.BlockProducer.Start(); } return(Task.CompletedTask); }
public Eth2BlockProducer Create( IBlockProducerEnvFactory blockProducerEnvFactory, IBlockTree blockTree, IBlockProductionTrigger blockProductionTrigger, ISpecProvider specProvider, ISigner engineSigner, ITimestamper timestamper, IMiningConfig miningConfig, ILogManager logManager) { BlockProducerEnv producerEnv = GetProducerEnv(blockProducerEnvFactory); return(new Eth2BlockProducer( producerEnv.TxSource, producerEnv.ChainProcessor, blockTree, blockProductionTrigger, producerEnv.ReadOnlyStateProvider, _gasLimitCalculator ?? new TargetAdjustedGasLimitCalculator(specProvider, miningConfig), engineSigner, timestamper, specProvider, logManager)); }
public static ITxFilter CreateStandardTxFilter(IMiningConfig miningConfig) => new MinGasPriceTxFilter(miningConfig.MinGasPrice);
private ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv processingEnv, ITxPool txPool, ISpecProvider specProvider, ILogManager logManager, IMiningConfig miningConfig, ITransactionComparerProvider transactionComparerProvider) => CreateTxPoolTxSource(processingEnv, txPool, miningConfig, specProvider, transactionComparerProvider, logManager);
private TxPoolTxSource CreateTxPoolTxSource(ReadOnlyTxProcessingEnv processingEnv, ITxPool txPool, IMiningConfig miningConfig, ISpecProvider specProvider, ITransactionComparerProvider transactionComparerProvider, ILogManager logManager) { ITxFilterPipeline txSourceFilterPipeline = CreateTxSourceFilter(logManager, specProvider); return(new TxPoolTxSource(txPool, processingEnv.StateReader, specProvider, transactionComparerProvider, logManager, txSourceFilterPipeline)); }
public TargetAdjustedGasLimitCalculator(ISpecProvider specProvider, IMiningConfig miningConfig) { _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); _miningConfig = miningConfig ?? throw new ArgumentNullException(nameof(miningConfig)); }
public Task <IBlockProducer> InitBlockProducer(IBlockProductionTrigger?blockProductionTrigger = null, ITxSource?additionalTxSource = null) { if (_mergeConfig.Enabled) { _miningConfig = _api.Config <IMiningConfig>(); if (_api.EngineSigner == null) { throw new ArgumentNullException(nameof(_api.EngineSigner)); } if (_api.ChainSpec == null) { throw new ArgumentNullException(nameof(_api.ChainSpec)); } if (_api.BlockTree == null) { throw new ArgumentNullException(nameof(_api.BlockTree)); } if (_api.BlockProcessingQueue == null) { throw new ArgumentNullException(nameof(_api.BlockProcessingQueue)); } if (_api.StateProvider == null) { throw new ArgumentNullException(nameof(_api.StateProvider)); } if (_api.SpecProvider == null) { throw new ArgumentNullException(nameof(_api.SpecProvider)); } if (_api.BlockValidator == null) { throw new ArgumentNullException(nameof(_api.BlockValidator)); } if (_api.RewardCalculatorSource == null) { throw new ArgumentNullException(nameof(_api.RewardCalculatorSource)); } if (_api.ReceiptStorage == null) { throw new ArgumentNullException(nameof(_api.ReceiptStorage)); } if (_api.TxPool == null) { throw new ArgumentNullException(nameof(_api.TxPool)); } if (_api.DbProvider == null) { throw new ArgumentNullException(nameof(_api.DbProvider)); } if (_api.ReadOnlyTrieStore == null) { throw new ArgumentNullException(nameof(_api.ReadOnlyTrieStore)); } ILogger logger = _api.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn("Starting ETH2 block producer & sealer"); } _manualTimestamper ??= new ManualTimestamper(); _api.BlockProducer = _blockProducer = new Eth2BlockProducerFactory(additionalTxSource).Create( _api.BlockProducerEnvFactory, _api.BlockTree, blockProductionTrigger ?? DefaultBlockProductionTrigger, _api.SpecProvider, _api.EngineSigner, _manualTimestamper, _miningConfig, _api.LogManager ); } return(Task.FromResult((IBlockProducer)_blockProducer)); }
private ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv processingEnv, ITxPool txPool, ILogManager logManager, IMiningConfig miningConfig) => CreateTxPoolTxSource(processingEnv, txPool, miningConfig, logManager);
public static IMinGasPriceTxFilter CreateStandardMinGasPriceTxFilter(IMiningConfig miningConfig, ISpecProvider specProvider) => new MinGasPriceTxFilter(miningConfig.MinGasPrice, specProvider);
private TxPoolTxSource CreateTxPoolTxSource(ReadOnlyTxProcessingEnv processingEnv, ITxPool txPool, IMiningConfig miningConfig, ILogManager logManager) { ITxFilter txSourceFilter = CreateTxSourceFilter(miningConfig); return(new TxPoolTxSource(txPool, processingEnv.StateReader, logManager, txSourceFilter)); }
private Task InitBlockchain() { InitBlockTraceDumper(); (IApiWithStores getApi, IApiWithBlockchain setApi) = _api.ForBlockchain; if (getApi.ChainSpec == null) { throw new StepDependencyException(nameof(getApi.ChainSpec)); } if (getApi.DbProvider == null) { throw new StepDependencyException(nameof(getApi.DbProvider)); } if (getApi.SpecProvider == null) { throw new StepDependencyException(nameof(getApi.SpecProvider)); } if (getApi.BlockTree == null) { throw new StepDependencyException(nameof(getApi.BlockTree)); } _logger = getApi.LogManager.GetClassLogger(); IInitConfig initConfig = getApi.Config <IInitConfig>(); ISyncConfig syncConfig = getApi.Config <ISyncConfig>(); IPruningConfig pruningConfig = getApi.Config <IPruningConfig>(); IMiningConfig miningConfig = getApi.Config <IMiningConfig>(); if (syncConfig.DownloadReceiptsInFastSync && !syncConfig.DownloadBodiesInFastSync) { _logger.Warn($"{nameof(syncConfig.DownloadReceiptsInFastSync)} is selected but {nameof(syncConfig.DownloadBodiesInFastSync)} - enabling bodies to support receipts download."); syncConfig.DownloadBodiesInFastSync = true; } Account.AccountStartNonce = getApi.ChainSpec.Parameters.AccountStartNonce; IWitnessCollector witnessCollector; if (syncConfig.WitnessProtocolEnabled) { WitnessCollector witnessCollectorImpl = new(getApi.DbProvider.WitnessDb, _api.LogManager); witnessCollector = setApi.WitnessCollector = witnessCollectorImpl; setApi.WitnessRepository = witnessCollectorImpl.WithPruning(getApi.BlockTree !, getApi.LogManager); } else { witnessCollector = setApi.WitnessCollector = NullWitnessCollector.Instance; setApi.WitnessRepository = NullWitnessCollector.Instance; } CachingStore cachedStateDb = getApi.DbProvider.StateDb .Cached(Trie.MemoryAllowance.TrieNodeCacheCount); setApi.MainStateDbWithCache = cachedStateDb; IKeyValueStore codeDb = getApi.DbProvider.CodeDb .WitnessedBy(witnessCollector); TrieStore trieStore; IKeyValueStoreWithBatching stateWitnessedBy = setApi.MainStateDbWithCache.WitnessedBy(witnessCollector); if (pruningConfig.Mode.IsMemory()) { IPersistenceStrategy persistenceStrategy = Persist.IfBlockOlderThan(pruningConfig.PersistenceInterval); // TODO: this should be based on time if (pruningConfig.Mode.IsFull()) { PruningTriggerPersistenceStrategy triggerPersistenceStrategy = new((IFullPruningDb)getApi.DbProvider !.StateDb, getApi.BlockTree !, getApi.LogManager); getApi.DisposeStack.Push(triggerPersistenceStrategy); persistenceStrategy = persistenceStrategy.Or(triggerPersistenceStrategy); } setApi.TrieStore = trieStore = new TrieStore( stateWitnessedBy, Prune.WhenCacheReaches(pruningConfig.CacheMb.MB()), // TODO: memory hint should define this persistenceStrategy, getApi.LogManager); if (pruningConfig.Mode.IsFull()) { IFullPruningDb fullPruningDb = (IFullPruningDb)getApi.DbProvider !.StateDb; fullPruningDb.PruningStarted += (_, args) => { cachedStateDb.PersistCache(args.Context); trieStore.PersistCache(args.Context, args.Context.CancellationTokenSource.Token); }; } } else { setApi.TrieStore = trieStore = new TrieStore( stateWitnessedBy, No.Pruning, Persist.EveryBlock, getApi.LogManager); } TrieStoreBoundaryWatcher trieStoreBoundaryWatcher = new(trieStore, _api.BlockTree !, _api.LogManager); getApi.DisposeStack.Push(trieStoreBoundaryWatcher); getApi.DisposeStack.Push(trieStore); ITrieStore readOnlyTrieStore = setApi.ReadOnlyTrieStore = trieStore.AsReadOnly(cachedStateDb); IStateProvider stateProvider = setApi.StateProvider = new StateProvider( trieStore, codeDb, getApi.LogManager); ReadOnlyDbProvider readOnly = new(getApi.DbProvider, false); IStateReader stateReader = setApi.StateReader = new StateReader(readOnlyTrieStore, readOnly.GetDb <IDb>(DbNames.Code), getApi.LogManager); setApi.TransactionComparerProvider = new TransactionComparerProvider(getApi.SpecProvider !, getApi.BlockTree.AsReadOnly()); setApi.ChainHeadStateProvider = new ChainHeadReadOnlyStateProvider(getApi.BlockTree, stateReader); Account.AccountStartNonce = getApi.ChainSpec.Parameters.AccountStartNonce; stateProvider.StateRoot = getApi.BlockTree !.Head?.StateRoot ?? Keccak.EmptyTreeHash; if (_api.Config <IInitConfig>().DiagnosticMode == DiagnosticMode.VerifyTrie) { Task.Run(() => { try { _logger !.Info("Collecting trie stats and verifying that no nodes are missing..."); TrieStats stats = stateProvider.CollectStats(getApi.DbProvider.CodeDb, _api.LogManager); _logger.Info($"Starting from {getApi.BlockTree.Head?.Number} {getApi.BlockTree.Head?.StateRoot}{Environment.NewLine}" + stats); } catch (Exception ex) { _logger !.Error(ex.ToString()); } }); } // Init state if we need system calls before actual processing starts if (getApi.BlockTree !.Head?.StateRoot != null) { stateProvider.StateRoot = getApi.BlockTree.Head.StateRoot; } TxValidator txValidator = setApi.TxValidator = new TxValidator(getApi.SpecProvider.ChainId); ITxPool txPool = _api.TxPool = CreateTxPool(); ReceiptCanonicalityMonitor receiptCanonicalityMonitor = new(getApi.BlockTree, getApi.ReceiptStorage, _api.LogManager); getApi.DisposeStack.Push(receiptCanonicalityMonitor); _api.ReceiptMonitor = receiptCanonicalityMonitor; _api.BlockPreprocessor.AddFirst( new RecoverSignatures(getApi.EthereumEcdsa, txPool, getApi.SpecProvider, getApi.LogManager)); IStorageProvider storageProvider = setApi.StorageProvider = new StorageProvider( trieStore, stateProvider, getApi.LogManager); // blockchain processing BlockhashProvider blockhashProvider = new ( getApi.BlockTree, getApi.LogManager); VirtualMachine virtualMachine = new ( blockhashProvider, getApi.SpecProvider, getApi.LogManager); WorldState worldState = new (stateProvider, storageProvider); _api.TransactionProcessor = new TransactionProcessor( getApi.SpecProvider, worldState, virtualMachine, getApi.LogManager); InitSealEngine(); if (_api.SealValidator == null) { throw new StepDependencyException(nameof(_api.SealValidator)); } setApi.HeaderValidator = CreateHeaderValidator(); IHeaderValidator?headerValidator = setApi.HeaderValidator; IUnclesValidator unclesValidator = setApi.UnclesValidator = new UnclesValidator( getApi.BlockTree, headerValidator, getApi.LogManager); setApi.BlockValidator = new BlockValidator( txValidator, headerValidator, unclesValidator, getApi.SpecProvider, getApi.LogManager); IChainHeadInfoProvider chainHeadInfoProvider = new ChainHeadInfoProvider(getApi.SpecProvider, getApi.BlockTree, stateReader); setApi.TxPoolInfoProvider = new TxPoolInfoProvider(chainHeadInfoProvider.AccountStateProvider, txPool); setApi.GasPriceOracle = new GasPriceOracle(getApi.BlockTree, getApi.SpecProvider, _api.LogManager, miningConfig.MinGasPrice); IBlockProcessor mainBlockProcessor = setApi.MainBlockProcessor = CreateBlockProcessor(); BlockchainProcessor blockchainProcessor = new( getApi.BlockTree, mainBlockProcessor, _api.BlockPreprocessor, stateReader, getApi.LogManager, new BlockchainProcessor.Options { StoreReceiptsByDefault = initConfig.StoreReceipts, DumpOptions = initConfig.AutoDump }); setApi.BlockProcessingQueue = blockchainProcessor; setApi.BlockchainProcessor = blockchainProcessor; setApi.EthSyncingInfo = new EthSyncingInfo(getApi.BlockTree); // TODO: can take the tx sender from plugin here maybe ITxSigner txSigner = new WalletTxSigner(getApi.Wallet, getApi.SpecProvider.ChainId); TxSealer standardSealer = new(txSigner, getApi.Timestamper); NonceReservingTxSealer nonceReservingTxSealer = new(txSigner, getApi.Timestamper, txPool); setApi.TxSender = new TxPoolSender(txPool, nonceReservingTxSealer, standardSealer); // TODO: possibly hide it (but need to confirm that NDM does not really need it) IFilterStore filterStore = setApi.FilterStore = new FilterStore(); setApi.FilterManager = new FilterManager(filterStore, mainBlockProcessor, txPool, getApi.LogManager); setApi.HealthHintService = CreateHealthHintService(); setApi.BlockProductionPolicy = new BlockProductionPolicy(miningConfig); InitializeFullPruning(pruningConfig, initConfig, _api, stateReader); return(Task.CompletedTask); }
public Task InitBlockProducer() { if (_mergeConfig.Enabled) { _miningConfig = _api.Config <IMiningConfig>(); if (_api.EngineSigner == null) { throw new ArgumentException(nameof(_api.EngineSigner)); } if (_api.ChainSpec == null) { throw new ArgumentException(nameof(_api.ChainSpec)); } if (_api.BlockTree == null) { throw new ArgumentException(nameof(_api.BlockTree)); } if (_api.BlockProcessingQueue == null) { throw new ArgumentException(nameof(_api.BlockProcessingQueue)); } if (_api.StateProvider == null) { throw new ArgumentException(nameof(_api.StateProvider)); } if (_api.SpecProvider == null) { throw new ArgumentException(nameof(_api.SpecProvider)); } if (_api.BlockValidator == null) { throw new ArgumentException(nameof(_api.BlockValidator)); } if (_api.RewardCalculatorSource == null) { throw new ArgumentException(nameof(_api.RewardCalculatorSource)); } if (_api.ReceiptStorage == null) { throw new ArgumentException(nameof(_api.ReceiptStorage)); } if (_api.TxPool == null) { throw new ArgumentException(nameof(_api.TxPool)); } if (_api.DbProvider == null) { throw new ArgumentException(nameof(_api.DbProvider)); } if (_api.ReadOnlyTrieStore == null) { throw new ArgumentException(nameof(_api.ReadOnlyTrieStore)); } ILogger logger = _api.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn("Starting ETH2 block producer & sealer"); } _api.BlockProducer = _blockProducer = new Eth2BlockProducerFactory().Create( _api.BlockTree, _api.DbProvider, _api.ReadOnlyTrieStore, _api.BlockPreprocessor, _api.TxPool, _api.BlockValidator, _api.RewardCalculatorSource, _api.ReceiptStorage, _api.BlockProcessingQueue, _api.SpecProvider, _api.EngineSigner, _miningConfig, _api.LogManager ); } return(Task.CompletedTask); }
private ITxFilter CreateTxSourceFilter(IMiningConfig miningConfig) => TxFilterBuilders.CreateStandardTxFilter(miningConfig);
public BlockProductionPolicy( IMiningConfig miningConfig) { _miningConfig = miningConfig; }
public async Task <IBlockProducer> InitBlockProducer(IConsensusPlugin consensusPlugin) { if (MergeEnabled) { if (_api.EngineSigner == null) { throw new ArgumentNullException(nameof(_api.EngineSigner)); } if (_api.ChainSpec == null) { throw new ArgumentNullException(nameof(_api.ChainSpec)); } if (_api.BlockTree == null) { throw new ArgumentNullException(nameof(_api.BlockTree)); } if (_api.BlockProcessingQueue == null) { throw new ArgumentNullException(nameof(_api.BlockProcessingQueue)); } if (_api.SpecProvider == null) { throw new ArgumentNullException(nameof(_api.SpecProvider)); } if (_api.BlockValidator == null) { throw new ArgumentNullException(nameof(_api.BlockValidator)); } if (_api.RewardCalculatorSource == null) { throw new ArgumentNullException(nameof(_api.RewardCalculatorSource)); } if (_api.ReceiptStorage == null) { throw new ArgumentNullException(nameof(_api.ReceiptStorage)); } if (_api.TxPool == null) { throw new ArgumentNullException(nameof(_api.TxPool)); } if (_api.DbProvider == null) { throw new ArgumentNullException(nameof(_api.DbProvider)); } if (_api.ReadOnlyTrieStore == null) { throw new ArgumentNullException(nameof(_api.ReadOnlyTrieStore)); } if (_api.BlockchainProcessor == null) { throw new ArgumentNullException(nameof(_api.BlockchainProcessor)); } if (_api.HeaderValidator == null) { throw new ArgumentNullException(nameof(_api.HeaderValidator)); } if (_mergeBlockProductionPolicy == null) { throw new ArgumentNullException(nameof(_mergeBlockProductionPolicy)); } if (_api.SealValidator == null) { throw new ArgumentNullException(nameof(_api.SealValidator)); } if (_logger.IsInfo) { _logger.Info("Starting Merge block producer & sealer"); } IBlockProducer?blockProducer = _mergeBlockProductionPolicy.ShouldInitPreMergeBlockProduction() ? await consensusPlugin.InitBlockProducer() : null; _miningConfig = _api.Config <IMiningConfig>(); _manualTimestamper ??= new ManualTimestamper(); _blockProductionTrigger = new BuildBlocksWhenRequested(); BlockProducerEnv blockProducerEnv = _api.BlockProducerEnvFactory.Create(); _api.SealEngine = new MergeSealEngine(_api.SealEngine, _poSSwitcher, _api.SealValidator, _api.LogManager); _api.Sealer = _api.SealEngine; PostMergeBlockProducerFactory blockProducerFactory = new(_api.SpecProvider, _api.SealEngine, _manualTimestamper, _miningConfig, _api.LogManager); _postMergeBlockProducer = blockProducerFactory.Create( blockProducerEnv, _blockProductionTrigger, CreateTxSource(blockProducerEnv.ReadOnlyStateProvider) ); _api.BlockProducer = new MergeBlockProducer(blockProducer, _postMergeBlockProducer, _poSSwitcher); } return(_api.BlockProducer !); }