protected virtual TxPoolTxSource CreateTxPoolTxSource() { ITxFilterPipeline txFilterPipeline = TxFilterPipelineBuilder.CreateStandardFilteringPipeline(LimboLogs.Instance, SpecProvider); return(new TxPoolTxSource(TxPool, StateReader, SpecProvider, TransactionComparerProvider, LogManager, txFilterPipeline)); }
private TxPoolTxSource CreateTxPoolTxSource(ReadOnlyTxProcessingEnv processingEnv, IReadOnlyTxProcessorSource readOnlyTxProcessorSource) { // We need special one for TxPriority as its following Head separately with events and we want rules from Head, not produced block IReadOnlyTxProcessorSource readOnlyTxProcessorSourceForTxPriority = new ReadOnlyTxProcessingEnv(_api.DbProvider, _api.ReadOnlyTrieStore, _api.BlockTree, _api.SpecProvider, _api.LogManager); (_txPriorityContract, _localDataSource) = TxAuRaFilterBuilders.CreateTxPrioritySources(_auraConfig, _api, readOnlyTxProcessorSourceForTxPriority); if (_txPriorityContract != null || _localDataSource != null) { _minGasPricesContractDataStore = TxAuRaFilterBuilders.CreateMinGasPricesDataStore(_api, _txPriorityContract, _localDataSource) !; _api.DisposeStack.Push(_minGasPricesContractDataStore); ContractDataStore <Address> whitelistContractDataStore = new ContractDataStoreWithLocalData <Address>( new HashSetContractDataStoreCollection <Address>(), _txPriorityContract?.SendersWhitelist, _api.BlockTree, _api.ReceiptFinder, _api.LogManager, _localDataSource?.GetWhitelistLocalDataSource() ?? new EmptyLocalDataSource <IEnumerable <Address> >()); DictionaryContractDataStore <TxPriorityContract.Destination> prioritiesContractDataStore = new DictionaryContractDataStore <TxPriorityContract.Destination>( new TxPriorityContract.DestinationSortedListContractDataStoreCollection(), _txPriorityContract?.Priorities, _api.BlockTree, _api.ReceiptFinder, _api.LogManager, _localDataSource?.GetPrioritiesLocalDataSource()); _api.DisposeStack.Push(whitelistContractDataStore); _api.DisposeStack.Push(prioritiesContractDataStore); ITxFilter auraTxFilter = CreateAuraTxFilterForProducer(readOnlyTxProcessorSource, _api.SpecProvider); ITxFilterPipeline txFilterPipeline = new TxFilterPipelineBuilder(_api.LogManager) .WithCustomTxFilter(auraTxFilter) .WithBaseFeeFilter(_api.SpecProvider) .WithNullTxFilter() .Build; return(new TxPriorityTxSource( _api.TxPool, processingEnv.StateReader, _api.LogManager, txFilterPipeline, whitelistContractDataStore, prioritiesContractDataStore, _api.SpecProvider, _api.TransactionComparerProvider)); } else { return(CreateStandardTxPoolTxSource(processingEnv, readOnlyTxProcessorSource)); } }
private TxPoolTxSource CreateStandardTxPoolTxSource(ReadOnlyTxProcessingEnv processingEnv, IReadOnlyTxProcessorSource readOnlyTxProcessorSource) { ITxFilter txSourceFilter = CreateAuraTxFilterForProducer(readOnlyTxProcessorSource, _api.SpecProvider); ITxFilterPipeline txFilterPipeline = new TxFilterPipelineBuilder(_api.LogManager) .WithCustomTxFilter(txSourceFilter) .WithBaseFeeFilter(_api.SpecProvider) .Build; return(new TxPoolTxSource(_api.TxPool, _api.SpecProvider, _api.TransactionComparerProvider, _api.LogManager, txFilterPipeline)); }
public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = false) { if (_logger.IsInfo) { _logger.Info($"CREATING NODE {privateKey.Address}"); } _logManagers[privateKey] = LimboLogs.Instance; // _logManagers[privateKey] = new OneLoggerLogManager(new ConsoleAsyncLogger(LogLevel.Debug, $"{privateKey.Address} ")); var nodeLogManager = _logManagers[privateKey]; AutoResetEvent newHeadBlockEvent = new AutoResetEvent(false); _blockEvents.Add(privateKey, newHeadBlockEvent); MemDb blocksDb = new MemDb(); MemDb headersDb = new MemDb(); MemDb blockInfoDb = new MemDb(); MemDb stateDb = new MemDb(); MemDb codeDb = new MemDb(); ISpecProvider specProvider = RinkebySpecProvider.Instance; var trieStore = new TrieStore(stateDb, nodeLogManager); StateReader stateReader = new StateReader(trieStore, codeDb, nodeLogManager); StateProvider stateProvider = new StateProvider(trieStore, codeDb, nodeLogManager); stateProvider.CreateAccount(TestItem.PrivateKeyD.Address, 100.Ether()); GoerliSpecProvider goerliSpecProvider = GoerliSpecProvider.Instance; stateProvider.Commit(goerliSpecProvider.GenesisSpec); stateProvider.CommitTree(0); BlockTree blockTree = new BlockTree(blocksDb, headersDb, blockInfoDb, new ChainLevelInfoRepository(blockInfoDb), goerliSpecProvider, NullBloomStorage.Instance, nodeLogManager); blockTree.NewHeadBlock += (sender, args) => { _blockEvents[privateKey].Set(); }; ITransactionComparerProvider transactionComparerProvider = new TransactionComparerProvider(specProvider, blockTree); TxPool.TxPool txPool = new TxPool.TxPool(new InMemoryTxStorage(), _ethereumEcdsa, new ChainHeadInfoProvider(new FixedBlockChainHeadSpecProvider(GoerliSpecProvider.Instance), blockTree, stateProvider), new TxPoolConfig(), new TxValidator(goerliSpecProvider.ChainId), _logManager, transactionComparerProvider.GetDefaultComparer()); _pools[privateKey] = txPool; BlockhashProvider blockhashProvider = new BlockhashProvider(blockTree, LimboLogs.Instance); _blockTrees.Add(privateKey, blockTree); SnapshotManager snapshotManager = new SnapshotManager(_cliqueConfig, blocksDb, blockTree, _ethereumEcdsa, nodeLogManager); _snapshotManager[privateKey] = snapshotManager; CliqueSealer cliqueSealer = new CliqueSealer(new Signer(ChainId.Goerli, privateKey, LimboLogs.Instance), _cliqueConfig, snapshotManager, nodeLogManager); _genesis.Header.StateRoot = _genesis3Validators.Header.StateRoot = stateProvider.StateRoot; _genesis.Header.Hash = _genesis.Header.CalculateHash(); _genesis3Validators.Header.Hash = _genesis3Validators.Header.CalculateHash(); StorageProvider storageProvider = new StorageProvider(trieStore, stateProvider, nodeLogManager); TransactionProcessor transactionProcessor = new TransactionProcessor(goerliSpecProvider, stateProvider, storageProvider, new VirtualMachine(stateProvider, storageProvider, blockhashProvider, specProvider, nodeLogManager), nodeLogManager); BlockProcessor blockProcessor = new BlockProcessor( goerliSpecProvider, Always.Valid, NoBlockRewards.Instance, transactionProcessor, stateProvider, storageProvider, txPool, NullReceiptStorage.Instance, NullWitnessCollector.Instance, nodeLogManager); BlockchainProcessor processor = new BlockchainProcessor(blockTree, blockProcessor, new AuthorRecoveryStep(snapshotManager), nodeLogManager, BlockchainProcessor.Options.NoReceipts); processor.Start(); var minerTrieStore = trieStore.AsReadOnly(); StateProvider minerStateProvider = new StateProvider(minerTrieStore, codeDb, nodeLogManager); StorageProvider minerStorageProvider = new StorageProvider(minerTrieStore, minerStateProvider, nodeLogManager); VirtualMachine minerVirtualMachine = new VirtualMachine(minerStateProvider, minerStorageProvider, blockhashProvider, specProvider, nodeLogManager); TransactionProcessor minerTransactionProcessor = new TransactionProcessor(goerliSpecProvider, minerStateProvider, minerStorageProvider, minerVirtualMachine, nodeLogManager); BlockProcessor minerBlockProcessor = new BlockProcessor( goerliSpecProvider, Always.Valid, NoBlockRewards.Instance, minerTransactionProcessor, minerStateProvider, minerStorageProvider, txPool, NullReceiptStorage.Instance, NullWitnessCollector.Instance, nodeLogManager); BlockchainProcessor minerProcessor = new BlockchainProcessor(blockTree, minerBlockProcessor, new AuthorRecoveryStep(snapshotManager), nodeLogManager, BlockchainProcessor.Options.NoReceipts); if (withGenesisAlreadyProcessed) { ProcessGenesis(privateKey); } ITxFilterPipeline txFilterPipeline = TxFilterPipelineBuilder.CreateStandardFilteringPipeline(nodeLogManager, specProvider); TxPoolTxSource txPoolTxSource = new TxPoolTxSource(txPool, stateReader, specProvider, transactionComparerProvider, nodeLogManager, txFilterPipeline); CliqueBlockProducer blockProducer = new CliqueBlockProducer( txPoolTxSource, minerProcessor, minerStateProvider, blockTree, _timestamper, new CryptoRandom(), snapshotManager, cliqueSealer, new TargetAdjustedGasLimitCalculator(goerliSpecProvider, new MiningConfig()), MainnetSpecProvider.Instance, _cliqueConfig, nodeLogManager); blockProducer.Start(); _producers.Add(privateKey, blockProducer); return(this); }
public Task <IBlockProducer> InitBlockProducer(IBlockProductionTrigger?blockProductionTrigger = null, ITxSource?additionalTxSource = null) { if (_nethermindApi !.SealEngineType != Nethermind.Core.SealEngineType.NethDev) { return(Task.FromResult((IBlockProducer)null)); } var(getFromApi, setInApi) = _nethermindApi !.ForProducer; ReadOnlyDbProvider readOnlyDbProvider = getFromApi.DbProvider.AsReadOnly(false); ReadOnlyBlockTree readOnlyBlockTree = getFromApi.BlockTree.AsReadOnly(); ITxFilterPipeline txFilterPipeline = new TxFilterPipelineBuilder(_nethermindApi.LogManager) .WithBaseFeeFilter(getFromApi.SpecProvider) .WithNullTxFilter() .WithMinGasPriceFilter(_nethermindApi.Config <IMiningConfig>().MinGasPrice, getFromApi.SpecProvider) .Build; TxPoolTxSource txPoolTxSource = new( getFromApi.TxPool, getFromApi.SpecProvider, getFromApi.TransactionComparerProvider !, getFromApi.LogManager, txFilterPipeline); ILogger logger = getFromApi.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn("Starting Neth Dev block producer & sealer"); } ReadOnlyTxProcessingEnv producerEnv = new( readOnlyDbProvider, getFromApi.ReadOnlyTrieStore, readOnlyBlockTree, getFromApi.SpecProvider, getFromApi.LogManager); BlockProcessor producerProcessor = new( getFromApi !.SpecProvider, getFromApi !.BlockValidator, NoBlockRewards.Instance, new BlockProcessor.BlockProductionTransactionsExecutor(producerEnv, getFromApi !.SpecProvider, getFromApi.LogManager), producerEnv.StateProvider, producerEnv.StorageProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, getFromApi.LogManager); IBlockchainProcessor producerChainProcessor = new BlockchainProcessor( readOnlyBlockTree, producerProcessor, getFromApi.BlockPreprocessor, getFromApi.LogManager, BlockchainProcessor.Options.NoReceipts); DefaultBlockProductionTrigger = new BuildBlocksRegularly(TimeSpan.FromMilliseconds(200)) .IfPoolIsNotEmpty(getFromApi.TxPool) .Or(getFromApi.ManualBlockProductionTrigger); IBlockProducer blockProducer = new DevBlockProducer( additionalTxSource.Then(txPoolTxSource).ServeTxsOneByOne(), producerChainProcessor, producerEnv.StateProvider, getFromApi.BlockTree, blockProductionTrigger ?? DefaultBlockProductionTrigger, getFromApi.Timestamper, getFromApi.SpecProvider, getFromApi.Config <IMiningConfig>(), getFromApi.LogManager); return(Task.FromResult(blockProducer)); }
private SyncTestContext CreateSyncManager(int index) { NoErrorLimboLogs logManager = NoErrorLimboLogs.Instance; ConsoleAsyncLogger logger = new(LogLevel.Debug, "PEER " + index + " "); // var logManager = new OneLoggerLogManager(logger); SingleReleaseSpecProvider specProvider = new(ConstantinopleFix.Instance, MainnetSpecProvider.Instance.ChainId); IDbProvider dbProvider = TestMemDbProvider.Init(); IDb blockDb = dbProvider.BlocksDb; IDb headerDb = dbProvider.HeadersDb; IDb blockInfoDb = dbProvider.BlockInfosDb; IDb codeDb = dbProvider.CodeDb; IDb stateDb = dbProvider.StateDb; TrieStore trieStore = new(stateDb, LimboLogs.Instance); StateReader stateReader = new(trieStore, codeDb, logManager); StateProvider stateProvider = new(trieStore, codeDb, logManager); stateProvider.CreateAccount(TestItem.AddressA, 10000.Ether()); stateProvider.Commit(specProvider.GenesisSpec); stateProvider.CommitTree(0); stateProvider.RecalculateStateRoot(); StorageProvider storageProvider = new(trieStore, stateProvider, logManager); InMemoryReceiptStorage receiptStorage = new(); EthereumEcdsa ecdsa = new(specProvider.ChainId, logManager); BlockTree tree = new(blockDb, headerDb, blockInfoDb, new ChainLevelInfoRepository(blockInfoDb), specProvider, NullBloomStorage.Instance, logManager); ITransactionComparerProvider transactionComparerProvider = new TransactionComparerProvider(specProvider, tree); TxPool.TxPool txPool = new(new InMemoryTxStorage(), ecdsa, new ChainHeadInfoProvider(specProvider, tree, stateReader), new TxPoolConfig(), new TxValidator(specProvider.ChainId), logManager, transactionComparerProvider.GetDefaultComparer()); BlockhashProvider blockhashProvider = new(tree, LimboLogs.Instance); VirtualMachine virtualMachine = new(stateProvider, storageProvider, blockhashProvider, specProvider, logManager); Always sealValidator = Always.Valid; HeaderValidator headerValidator = new(tree, sealValidator, specProvider, logManager); Always txValidator = Always.Valid; OmmersValidator ommersValidator = new(tree, headerValidator, logManager); BlockValidator blockValidator = new(txValidator, headerValidator, ommersValidator, specProvider, logManager); ISyncConfig syncConfig = _synchronizerType == SynchronizerType.Fast ? SyncConfig.WithFastSync : SyncConfig.WithFullSyncOnly; RewardCalculator rewardCalculator = new(specProvider); TransactionProcessor txProcessor = new(specProvider, stateProvider, storageProvider, virtualMachine, logManager); BlockProcessor blockProcessor = new( specProvider, blockValidator, rewardCalculator, txProcessor, stateProvider, storageProvider, txPool, receiptStorage, NullWitnessCollector.Instance, logManager); RecoverSignatures step = new(ecdsa, txPool, specProvider, logManager); BlockchainProcessor processor = new(tree, blockProcessor, step, logManager, BlockchainProcessor.Options.Default); ITimerFactory timerFactory = Substitute.For <ITimerFactory>(); NodeStatsManager nodeStatsManager = new(timerFactory, logManager); SyncPeerPool syncPeerPool = new(tree, nodeStatsManager, 25, logManager); StateProvider devState = new(trieStore, codeDb, logManager); StorageProvider devStorage = new(trieStore, devState, logManager); VirtualMachine devEvm = new(devState, devStorage, blockhashProvider, specProvider, logManager); TransactionProcessor devTxProcessor = new(specProvider, devState, devStorage, devEvm, logManager); BlockProcessor devBlockProcessor = new( specProvider, blockValidator, rewardCalculator, devTxProcessor, devState, devStorage, txPool, receiptStorage, NullWitnessCollector.Instance, logManager); BlockchainProcessor devChainProcessor = new(tree, devBlockProcessor, step, logManager, BlockchainProcessor.Options.NoReceipts); ITxFilterPipeline txFilterPipeline = TxFilterPipelineBuilder.CreateStandardFilteringPipeline(LimboLogs.Instance, specProvider); TxPoolTxSource transactionSelector = new(txPool, stateReader, specProvider, transactionComparerProvider, logManager, txFilterPipeline); DevBlockProducer producer = new( transactionSelector, devChainProcessor, stateProvider, tree, processor, new BuildBlocksRegularly(TimeSpan.FromMilliseconds(50)).IfPoolIsNotEmpty(txPool), Timestamper.Default, specProvider, new MiningConfig(), logManager); SyncProgressResolver resolver = new( tree, receiptStorage, stateDb, new MemDb(), NullTrieNodeResolver.Instance, syncConfig, logManager); MultiSyncModeSelector selector = new(resolver, syncPeerPool, syncConfig, logManager); Synchronizer synchronizer = new( dbProvider, MainnetSpecProvider.Instance, tree, NullReceiptStorage.Instance, blockValidator, sealValidator, syncPeerPool, nodeStatsManager, StaticSelector.Full, syncConfig, logManager); SyncServer syncServer = new( stateDb, codeDb, tree, receiptStorage, Always.Valid, Always.Valid, syncPeerPool, selector, syncConfig, NullWitnessCollector.Instance, logManager); ManualResetEventSlim waitEvent = new(); tree.NewHeadBlock += (_, _) => waitEvent.Set(); if (index == 0) { _genesis = Build.A.Block.Genesis.WithStateRoot(stateProvider.StateRoot).TestObject; producer.Start(); } syncPeerPool.Start(); synchronizer.Start(); processor.Start(); tree.SuggestBlock(_genesis); if (!waitEvent.Wait(1000)) { throw new Exception("No genesis"); } SyncTestContext context = new(); context.Ecdsa = ecdsa; context.BlockchainProcessor = processor; context.PeerPool = syncPeerPool; context.StateProvider = stateProvider; context.Synchronizer = synchronizer; context.SyncServer = syncServer; context.Tree = tree; context.BlockProducer = producer; context.TxPool = txPool; context.Logger = logger; return(context); }
public Task <IBlockProducer> InitBlockProducer(IBlockProductionTrigger?blockProductionTrigger = null, ITxSource?additionalTxSource = null) { if (_nethermindApi !.SealEngineType != Nethermind.Core.SealEngineType.Clique) { return(Task.FromResult((IBlockProducer)null)); } (IApiWithBlockchain getFromApi, IApiWithBlockchain setInApi) = _nethermindApi !.ForProducer; _miningConfig = getFromApi.Config <IMiningConfig>(); if (!_miningConfig.Enabled) { throw new InvalidOperationException("Request to start block producer while mining disabled."); } setInApi.Sealer = new CliqueSealer( getFromApi.EngineSigner !, _cliqueConfig !, _snapshotManager !, getFromApi.LogManager); ReadOnlyDbProvider readOnlyDbProvider = getFromApi.DbProvider !.AsReadOnly(false); ReadOnlyBlockTree readOnlyBlockTree = getFromApi.BlockTree !.AsReadOnly(); ITransactionComparerProvider transactionComparerProvider = getFromApi.TransactionComparerProvider; ReadOnlyTxProcessingEnv producerEnv = new ( readOnlyDbProvider, getFromApi.ReadOnlyTrieStore, readOnlyBlockTree, getFromApi.SpecProvider, getFromApi.LogManager); BlockProcessor producerProcessor = new ( getFromApi !.SpecProvider, getFromApi !.BlockValidator, NoBlockRewards.Instance, getFromApi.BlockProducerEnvFactory.TransactionsExecutorFactory.Create(producerEnv), producerEnv.StateProvider, producerEnv.StorageProvider, // do not remove transactions from the pool when preprocessing NullReceiptStorage.Instance, NullWitnessCollector.Instance, getFromApi.LogManager); IBlockchainProcessor producerChainProcessor = new BlockchainProcessor( readOnlyBlockTree, producerProcessor, getFromApi.BlockPreprocessor, getFromApi.StateReader, getFromApi.LogManager, BlockchainProcessor.Options.NoReceipts); OneTimeChainProcessor chainProcessor = new ( readOnlyDbProvider, producerChainProcessor); ITxFilterPipeline txFilterPipeline = TxFilterPipelineBuilder.CreateStandardFilteringPipeline( _nethermindApi.LogManager, getFromApi.SpecProvider, _miningConfig); TxPoolTxSource txPoolTxSource = new( getFromApi.TxPool, getFromApi.SpecProvider, transactionComparerProvider, getFromApi.LogManager, txFilterPipeline); IGasLimitCalculator gasLimitCalculator = setInApi.GasLimitCalculator = new TargetAdjustedGasLimitCalculator(getFromApi.SpecProvider, _miningConfig); IBlockProducer blockProducer = new CliqueBlockProducer( additionalTxSource.Then(txPoolTxSource), chainProcessor, producerEnv.StateProvider, getFromApi.BlockTree !, getFromApi.Timestamper, getFromApi.CryptoRandom, _snapshotManager !, getFromApi.Sealer !, gasLimitCalculator, getFromApi.SpecProvider, _cliqueConfig !, getFromApi.LogManager); return(Task.FromResult(blockProducer)); }
private ITxFilterPipeline CreateTxSourceFilter(ILogManager logManager, ISpecProvider specProvider) => TxFilterPipelineBuilder.CreateStandardFilteringPipeline(logManager, specProvider);