Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Nethermind.Consensus.Producers
/// </summary>
public abstract class BlockProducerBase : IBlockProducer
{
private IBlockchainProcessor Processor { get; }
protected IBlockchainProcessor Processor { get; }
protected IBlockTree BlockTree { get; }
private ITimestamper Timestamper { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected virtual ContainerBuilder ConfigureBuilder(ContainerBuilder builder) =>
.AddScoped<IBlockProcessor.IBlockTransactionsExecutor, BlockProcessor.BlockProductionTransactionsExecutor>()
.AddDecorator<IWithdrawalProcessor, BlockProductionWithdrawalProcessor>()
.AddDecorator<IBlockchainProcessor, OneTimeChainProcessor>()
.AddScoped<IProducedBlockSuggester, ProducedBlockSuggester>()
Comment thread
damian-orzechowski marked this conversation as resolved.
Outdated

.AddScoped<IBlockProducerEnv, BlockProducerEnv>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Autofac;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Core;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.State;

namespace Nethermind.Consensus.Producers
{
/// <summary>
/// Block producer environment factory that uses the global world state and stores receipts by default.
/// It will not trigger suggesting produced blocks.
/// </summary>
/// <param name="rootLifetime"></param>
/// <param name="worldStateManager"></param>
/// <param name="txSourceFactory"></param>
public class GlobalWorldStateBlockProducerEnvFactory(
ILifetimeScope rootLifetime,
IWorldStateManager worldStateManager,
IBlockProducerTxSourceFactory txSourceFactory)
: IBlockProducerEnvFactory
{
protected virtual ContainerBuilder ConfigureBuilder(ContainerBuilder builder) => builder
.AddScoped<ITxSource>(txSourceFactory.Create())
.AddScoped(BlockchainProcessor.Options.Default)
.AddScoped<ITransactionProcessorAdapter, BuildUpTransactionProcessorAdapter>()
.AddScoped<IBlockProcessor.IBlockTransactionsExecutor, BlockProcessor.BlockProductionTransactionsExecutor>()
.AddDecorator<IWithdrawalProcessor, BlockProductionWithdrawalProcessor>()
.AddDecorator<IBlockchainProcessor, OneTimeChainProcessor>()
.AddScoped<IProducedBlockSuggester, NoOpProducedBlockSuggester>()

.AddScoped<IBlockProducerEnv, BlockProducerEnv>();

public virtual IBlockProducerEnv Create()
{
ILifetimeScope lifetimeScope = rootLifetime.BeginLifetimeScope(builder =>
ConfigureBuilder(builder)
.AddScoped(worldStateManager.GlobalWorldState));

rootLifetime.Disposer.AddInstanceForAsyncDisposal(lifetimeScope);
return lifetimeScope.Resolve<IBlockProducerEnv>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;

namespace Nethermind.Consensus.Producers;

public interface IProducedBlockSuggester : IDisposable
{
// Just a marker interface to support DI
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Nethermind.Consensus.Producers;
public class NoOpProducedBlockSuggester : IProducedBlockSuggester
{
public void Dispose() { }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Nethermind.Blockchain;
using Nethermind.Core;

namespace Nethermind.Consensus.Producers
{
public class ProducedBlockSuggester : IDisposable
public class ProducedBlockSuggester : IProducedBlockSuggester
{
private readonly IBlockTree _blockTree;
private readonly IBlockProducerRunner _blockProducerRunner;
Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Init/Steps/StartBlockProducer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Threading;
using System.Threading.Tasks;
using Autofac;
using Nethermind.Api;
using Nethermind.Api.Steps;
using Nethermind.Consensus.Producers;
using Nethermind.Logging;
using System.Threading;
using System.Threading.Tasks;

namespace Nethermind.Init.Steps
{
Expand All @@ -30,8 +31,7 @@ public Task Execute(CancellationToken _)

ILogger logger = _api.LogManager.GetClassLogger();
if (logger.IsInfo) logger.Info($"Starting {_api.SealEngineType} block producer & sealer");
ProducedBlockSuggester suggester = new(_api.BlockTree, _api.BlockProducerRunner);
_api.DisposeStack.Push(suggester);
_api.Context.ResolveOptional<IProducedBlockSuggester>();
_api.BlockProducerRunner.Start();
}

Expand Down