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 AuRaBlockProducer(ITxSource txSource, IBlockchainProcessor processor, IBlockProductionTrigger blockProductionTrigger, IStateProvider stateProvider, ISealer sealer, IBlockTree blockTree, ITimestamper timestamper, IAuRaStepCalculator auRaStepCalculator, IReportingValidator reportingValidator, IAuraConfig config, IGasLimitCalculator gasLimitCalculator, ISpecProvider specProvider, ILogManager logManager) : base( txSource, processor, sealer, blockTree, blockProductionTrigger, stateProvider, gasLimitCalculator, timestamper, specProvider, logManager, new AuraDifficultyCalculator(auRaStepCalculator)) { _auRaStepCalculator = auRaStepCalculator ?? throw new ArgumentNullException(nameof(auRaStepCalculator)); _reportingValidator = reportingValidator ?? throw new ArgumentNullException(nameof(reportingValidator)); _config = config ?? throw new ArgumentNullException(nameof(config)); }
public MevBlockProducer( IBlockProductionTrigger blockProductionTrigger, ILogManager logManager, params MevBlockProducerInfo[] blockProducers) : base(blockProductionTrigger, new MevBestBlockPicker(), logManager, blockProducers) { }
private async Task <MevBlockProducer.MevBlockProducerInfo> CreateProducer( IConsensusPlugin consensusPlugin, int bundleLimit = 0, ITxSource?additionalTxSource = null) { bool BundleLimitTriggerCondition(BlockProductionEventArgs e) { // TODO: why we are checking parent and not the currently produced block...? BlockHeader?parent = _nethermindApi.BlockTree !.GetProducedBlockParent(e.ParentHeader); if (parent is not null) { IEnumerable <MevBundle> bundles = BundlePool.GetBundles(parent, _nethermindApi.Timestamper); return(bundles.Count() >= bundleLimit); } return(false); } IManualBlockProductionTrigger manualTrigger = new BuildBlocksWhenRequested(); IBlockProductionTrigger trigger = manualTrigger; if (bundleLimit != 0) { trigger = new TriggerWithCondition(manualTrigger, BundleLimitTriggerCondition); } IBlockProducer producer = await consensusPlugin.InitBlockProducer(trigger, additionalTxSource); return(new MevBlockProducer.MevBlockProducerInfo(producer, manualTrigger, new BeneficiaryTracer())); }
public void Does_not_trigger_when_empty(int txCount, bool shouldTrigger) { var pool = Substitute.For <ITxPool>(); pool.GetPendingTransactions().Returns(new Transaction[txCount]); bool triggered = false; BuildBlocksWhenRequested trigger = new BuildBlocksWhenRequested(); IBlockProductionTrigger withCondition = trigger.IfPoolIsNotEmpty(pool); withCondition.TriggerBlockProduction += (s, e) => triggered = true; trigger.BuildBlock(); triggered.Should().Be(shouldTrigger); }
public void On_pending_trigger_works() { int triggered = 0; BuildBlocksWhenRequested trigger1 = new(); BuildBlocksWhenRequested trigger2 = new(); IBlockProductionTrigger composite = trigger1.Or(trigger2); composite.TriggerBlockProduction += (s, e) => triggered++; trigger1.BuildBlock(); trigger2.BuildBlock(); trigger1.BuildBlock(); trigger2.BuildBlock(); triggered.Should().Be(4); }
protected MultipleBlockProducer( IBlockProductionTrigger blockProductionTrigger, IBestBlockPicker bestBlockPicker, ILogManager logManager, params T[] blockProducers) { if (blockProducers.Length == 0) { throw new ArgumentException("Collection cannot be empty.", nameof(blockProducers)); } _blockProductionTrigger = blockProductionTrigger; _bestBlockPicker = bestBlockPicker; _blockProducers = blockProducers; _logger = logManager.GetClassLogger(); }
public PostMergeBlockProducer Create( BlockProducerEnv producerEnv, IBlockProductionTrigger blockProductionTrigger, ITxSource?txSource = null) { return(new PostMergeBlockProducer( txSource ?? producerEnv.TxSource, producerEnv.ChainProcessor, producerEnv.BlockTree, blockProductionTrigger, producerEnv.ReadOnlyStateProvider, _gasLimitCalculator ?? new TargetAdjustedGasLimitCalculator(_specProvider, _miningConfig), _sealEngine, _timestamper, _specProvider, _logManager)); }
public BuildBlocksOnlyWhenNotProcessing( IBlockProductionTrigger blockProductionTrigger, IBlockProcessingQueue blockProcessingQueue, IBlockTree blockTree, ILogManager logManager, bool waitForInitialSync = true) { _blockProductionTrigger = blockProductionTrigger; _blockProcessingQueue = blockProcessingQueue; _blockTree = blockTree; _canProduce = waitForInitialSync ? 0 : 1; _logger = logManager.GetClassLogger(); _blockTree.NewBestSuggestedBlock += BlockTreeOnNewBestSuggestedBlock; _blockProcessingQueue.ProcessingQueueEmpty += OnBlockProcessorQueueEmpty; _blockProductionTrigger.TriggerBlockProduction += OnTriggerBlockProduction; }
public Task <IBlockProducer> BuildProducer(IBlockProductionTrigger blockProductionTrigger, ITxSource?additionalTxSource = null) { if (_api.EngineSigner == null) { throw new StepDependencyException(nameof(_api.EngineSigner)); } if (_api.ChainSpec == null) { throw new StepDependencyException(nameof(_api.ChainSpec)); } ILogger logger = _api.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn("Starting AuRa block producer & sealer"); } BlockProducerEnv producerEnv = GetProducerChain(additionalTxSource); IGasLimitCalculator gasLimitCalculator = _api.GasLimitCalculator = CreateGasLimitCalculator(producerEnv.ReadOnlyTxProcessingEnv); IBlockProducer blockProducer = new AuRaBlockProducer( producerEnv.TxSource, producerEnv.ChainProcessor, blockProductionTrigger, producerEnv.ReadOnlyStateProvider, _api.Sealer, _api.BlockTree, _api.Timestamper, StepCalculator, _api.ReportingValidator, _auraConfig, gasLimitCalculator, _api.SpecProvider, _api.LogManager); return(Task.FromResult(blockProducer)); }
public Eth2BlockProducer(ITxSource txSource, IBlockchainProcessor processor, IBlockTree blockTree, IBlockProductionTrigger blockProductionTrigger, IStateProvider stateProvider, IGasLimitCalculator gasLimitCalculator, ISigner signer, ITimestamper timestamper, ISpecProvider specProvider, ILogManager logManager) : base( txSource, processor, new Eth2SealEngine(signer), blockTree, blockProductionTrigger, stateProvider, gasLimitCalculator, timestamper, specProvider, logManager, ConstantDifficultyCalculator.One) { }
public MinedBlockProducer(ITxSource txSource, IBlockchainProcessor processor, ISealer sealer, IBlockTree blockTree, IBlockProductionTrigger blockProductionTrigger, IStateProvider stateProvider, IGasLimitCalculator gasLimitCalculator, ITimestamper timestamper, ISpecProvider specProvider, ILogManager logManager) : base( txSource, processor, sealer, blockTree, blockProductionTrigger, stateProvider, gasLimitCalculator, timestamper, specProvider, logManager, new EthashDifficultyCalculator(specProvider)) { }
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 TestBlockProducer( ITxSource txSource, IBlockchainProcessor processor, IStateProvider stateProvider, ISealer sealer, IBlockTree blockTree, IBlockProductionTrigger blockProductionTrigger, ITimestamper timestamper, ISpecProvider specProvider, ILogManager logManager) : base( txSource, processor, sealer, blockTree, blockProductionTrigger, stateProvider, new FollowOtherMiners(specProvider), timestamper, specProvider, logManager, ConstantDifficulty.One) { }
public TriggerWithCondition(IBlockProductionTrigger trigger, Func <BlockProductionEventArgs, bool> checkCondition) { _checkCondition = checkCondition; trigger.TriggerBlockProduction += TriggerOnTriggerBlockProduction; }
public TriggerWithCondition(IBlockProductionTrigger trigger, Func <bool> checkCondition) : this(trigger, _ => checkCondition()) { }
protected override IBlockProducer CreateTestBlockProducer(TxPoolTxSource txPoolTxSource, ISealer sealer, ITransactionComparerProvider transactionComparerProvider) { MiningConfig miningConfig = new() { MinGasPrice = UInt256.One }; BlockProducerEnvFactory blockProducerEnvFactory = new( DbProvider, BlockTree, ReadOnlyTrieStore, SpecProvider, BlockValidator, NoBlockRewards.Instance, ReceiptStorage, BlockPreprocessorStep, TxPool, transactionComparerProvider, miningConfig, LogManager) { TransactionsExecutorFactory = new MevBlockProducerTransactionsExecutorFactory(SpecProvider, LogManager) }; Eth2BlockProducer CreateEth2BlockProducer(IBlockProductionTrigger blockProductionTrigger, ITxSource?txSource = null) => new Eth2TestBlockProducerFactory(GasLimitCalculator, txSource).Create( blockProducerEnvFactory, BlockTree, blockProductionTrigger, SpecProvider, Signer, Timestamper, miningConfig, LogManager); MevBlockProducer.MevBlockProducerInfo CreateProducer(int bundleLimit = 0, ITxSource?additionalTxSource = null) { bool BundleLimitTriggerCondition(BlockProductionEventArgs e) { BlockHeader?parent = BlockTree.GetProducedBlockParent(e.ParentHeader); if (parent is not null) { IEnumerable <MevBundle> bundles = BundlePool.GetBundles(parent, Timestamper); return(bundles.Count() >= bundleLimit); } return(false); } IManualBlockProductionTrigger manualTrigger = new BuildBlocksWhenRequested(); IBlockProductionTrigger trigger = manualTrigger; if (bundleLimit != 0) { trigger = new TriggerWithCondition(manualTrigger, BundleLimitTriggerCondition); } IBlockProducer producer = CreateEth2BlockProducer(trigger, additionalTxSource); return(new MevBlockProducer.MevBlockProducerInfo(producer, manualTrigger, new BeneficiaryTracer())); } int megabundleProducerCount = _relayAddresses.Any() ? 1 : 0; List <MevBlockProducer.MevBlockProducerInfo> blockProducers = new(_maxMergedBundles + megabundleProducerCount + 1); // Add non-mev block MevBlockProducer.MevBlockProducerInfo standardProducer = CreateProducer(); blockProducers.Add(standardProducer); // Try blocks with all bundle numbers <= maxMergedBundles for (int bundleLimit = 1; bundleLimit <= _maxMergedBundles; bundleLimit++) { BundleSelector bundleSelector = new(BundlePool, bundleLimit); BundleTxSource bundleTxSource = new(bundleSelector, Timestamper); MevBlockProducer.MevBlockProducerInfo bundleProducer = CreateProducer(bundleLimit, bundleTxSource); blockProducers.Add(bundleProducer); } if (megabundleProducerCount > 0) { MegabundleSelector megabundleSelector = new(BundlePool); BundleTxSource megabundleTxSource = new(megabundleSelector, Timestamper); MevBlockProducer.MevBlockProducerInfo bundleProducer = CreateProducer(0, megabundleTxSource); blockProducers.Add(bundleProducer); } return(new MevBlockProducer(BlockProductionTrigger, LogManager, blockProducers.ToArray())); }
internal void Add(IBlockProductionTrigger trigger) { _triggers.Add(trigger); HookTrigger(trigger); }
private void HookTrigger(IBlockProductionTrigger trigger) => trigger.TriggerBlockProduction += OnInnerTriggerBlockProduction;
public ProducerUnderTest(ITxSource txSource, IBlockchainProcessor processor, ISealer sealer, IBlockTree blockTree, IBlockProductionTrigger blockProductionTrigger, IStateProvider stateProvider, IGasLimitCalculator gasLimitCalculator, ITimestamper timestamper, ILogManager logManager) : base(txSource, processor, sealer, blockTree, blockProductionTrigger, stateProvider, gasLimitCalculator, timestamper, MainnetSpecProvider.Instance, logManager, new TimestampDifficultyCalculator()) { }
protected override IBlockProducer CreateTestBlockProducer(TxPoolTxSource txPoolTxSource, ISealer sealer, ITransactionComparerProvider transactionComparerProvider) { MiningConfig miningConfig = new() { MinGasPrice = UInt256.One }; SpecProvider.UpdateMergeTransitionInfo(1, 0); BlockProducerEnvFactory blockProducerEnvFactory = new( DbProvider, BlockTree, ReadOnlyTrieStore, SpecProvider, BlockValidator, NoBlockRewards.Instance, ReceiptStorage, BlockPreprocessorStep, TxPool, transactionComparerProvider, miningConfig, LogManager) { TransactionsExecutorFactory = new MevBlockProducerTransactionsExecutorFactory(SpecProvider, LogManager) }; PostMergeBlockProducer CreatePostMergeBlockProducer(IBlockProductionTrigger blockProductionTrigger, ITxSource?txSource = null) { BlockProducerEnv blockProducerEnv = blockProducerEnvFactory.Create(txSource); return(new PostMergeBlockProducerFactory(SpecProvider, SealEngine, Timestamper, miningConfig, LogManager).Create( blockProducerEnv, blockProductionTrigger, txSource)); } MevBlockProducer.MevBlockProducerInfo CreateProducer(int bundleLimit = 0, ITxSource?additionalTxSource = null) { // TODO: this could be simplified a lot of the parent was not retrieved, not sure why do we need the parent here bool BundleLimitTriggerCondition(BlockProductionEventArgs e) { // TODO: why do we need this parent? later we use only the current block number BlockHeader?parent = BlockTree.GetProducedBlockParent(e.ParentHeader); if (parent is not null) { // ToDo resolved conflict parent.Timestamp? IEnumerable <MevBundle> bundles = BundlePool.GetBundles(parent.Number + 1, parent.Timestamp); return(bundles.Count() >= bundleLimit); } return(false); } IManualBlockProductionTrigger manualTrigger = new BuildBlocksWhenRequested(); IBlockProductionTrigger trigger = manualTrigger; if (bundleLimit != 0) { trigger = new TriggerWithCondition(manualTrigger, BundleLimitTriggerCondition); } IBlockProducer producer = CreatePostMergeBlockProducer(trigger, additionalTxSource); return(new MevBlockProducer.MevBlockProducerInfo(producer, manualTrigger, new BeneficiaryTracer())); } int megabundleProducerCount = _relayAddresses.Any() ? 1 : 0; List <MevBlockProducer.MevBlockProducerInfo> blockProducers = new(_maxMergedBundles + megabundleProducerCount + 1); // Add non-mev block MevBlockProducer.MevBlockProducerInfo standardProducer = CreateProducer(); blockProducers.Add(standardProducer); // Try blocks with all bundle numbers <= maxMergedBundles for (int bundleLimit = 1; bundleLimit <= _maxMergedBundles; bundleLimit++) { BundleSelector bundleSelector = new(BundlePool, bundleLimit); BundleTxSource bundleTxSource = new(bundleSelector, Timestamper); MevBlockProducer.MevBlockProducerInfo bundleProducer = CreateProducer(bundleLimit, bundleTxSource); blockProducers.Add(bundleProducer); } if (megabundleProducerCount > 0) { MegabundleSelector megabundleSelector = new(BundlePool); BundleTxSource megabundleTxSource = new(megabundleSelector, Timestamper); MevBlockProducer.MevBlockProducerInfo bundleProducer = CreateProducer(0, megabundleTxSource); blockProducers.Add(bundleProducer); } MevBlockProducer blockProducer = new MevBlockProducer(BlockProductionTrigger, LogManager, blockProducers.ToArray()); blockProducer.BlockProduced += OnBlockProduced; return(blockProducer); }