Skip to content

Commit

Permalink
Refactor/remove tx processing env base (#7967)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Dec 27, 2024
1 parent b81070d commit 54c0739
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@

namespace Nethermind.Consensus.Processing;

public class OverridableTxProcessingEnv : ReadOnlyTxProcessingEnvBase, IOverridableTxProcessorSource
public class OverridableTxProcessingEnv : IOverridableTxProcessorSource
{
private readonly Lazy<ITransactionProcessor> _transactionProcessorLazy;
public IStateReader StateReader { get; }
public IBlockTree BlockTree { get; }
protected ISpecProvider SpecProvider { get; }
protected ILogManager LogManager { get; }

protected new OverridableWorldState StateProvider { get; }
protected OverridableWorldStateManager WorldStateManager { get; }
private readonly Lazy<ITransactionProcessor> _transactionProcessorLazy;
protected OverridableWorldState StateProvider { get; }
protected OverridableCodeInfoRepository CodeInfoRepository { get; }
protected IVirtualMachine Machine { get; }
protected ITransactionProcessor TransactionProcessor => _transactionProcessorLazy.Value;
Expand All @@ -29,12 +32,18 @@ public OverridableTxProcessingEnv(
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager? logManager
) : base(worldStateManager.GlobalStateReader, worldStateManager.CreateResettableWorldState(), readOnlyBlockTree, specProvider, logManager)
)
{
WorldStateManager = worldStateManager;
StateProvider = (OverridableWorldState)base.StateProvider;
SpecProvider = specProvider;
StateReader = worldStateManager.GlobalStateReader;
BlockTree = readOnlyBlockTree;
IBlockhashProvider blockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager);
LogManager = logManager;

StateProvider = (OverridableWorldState)worldStateManager.CreateResettableWorldState();

CodeInfoRepository = new(new CodeInfoRepository());
Machine = new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager);
Machine = new VirtualMachine(blockhashProvider, specProvider, CodeInfoRepository, logManager);
_transactionProcessorLazy = new(CreateTransactionProcessor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace Nethermind.Consensus.Processing
{
public class ReadOnlyTxProcessingEnv : ReadOnlyTxProcessingEnvBase, IReadOnlyTxProcessorSource
public class ReadOnlyTxProcessingEnv : IReadOnlyTxProcessorSource
{
protected readonly ILogManager _logManager;
public IStateReader StateReader { get; }
protected IWorldState StateProvider { get; }
protected IBlockTree BlockTree { get; }
public IBlockhashProvider BlockhashProvider { get; }
protected ISpecProvider SpecProvider { get; }
protected ILogManager LogManager { get; }

protected ITransactionProcessor? _transactionProcessor;
protected ITransactionProcessor TransactionProcessor
Expand Down Expand Up @@ -57,18 +62,24 @@ private ReadOnlyTxProcessingEnv(
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager logManager
) : base(stateReader, stateProvider, readOnlyBlockTree, specProvider, logManager)
)
{
SpecProvider = specProvider;
StateReader = stateReader;
StateProvider = stateProvider;
BlockTree = readOnlyBlockTree;
BlockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager);

CodeInfoRepository = codeInfoRepository;
Machine = new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager);
BlockTree = readOnlyBlockTree ?? throw new ArgumentNullException(nameof(readOnlyBlockTree));
BlockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager);

_logManager = logManager;
LogManager = logManager;
}

protected virtual ITransactionProcessor CreateTransactionProcessor() =>
new TransactionProcessor(SpecProvider, StateProvider, Machine, CodeInfoRepository, _logManager);
new TransactionProcessor(SpecProvider, StateProvider, Machine, CodeInfoRepository, LogManager);

public IReadOnlyTxProcessingScope Build(Hash256 stateRoot)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,41 @@ protected override void ProcessTransaction(in BlockExecutionContext blkCtx, Tran
}
}

public class SimulateReadOnlyBlocksProcessingEnv : ReadOnlyTxProcessingEnvBase, IDisposable
public class SimulateReadOnlyBlocksProcessingEnv : IDisposable
{
private IWorldState StateProvider { get; }
public IBlockTree BlockTree { get; }
public ISpecProvider SpecProvider { get; }

private readonly IBlockValidator _blockValidator;
private readonly ILogManager? _logManager;
private readonly ITransactionProcessor _transactionProcessor;
public IWorldState WorldState => StateProvider;

public SimulateReadOnlyBlocksProcessingEnv(
IWorldStateManager worldStateManager,
IWorldState worldState,
IReadOnlyBlockTree baseBlockTree,
IReadOnlyDbProvider readOnlyDbProvider,
IBlockTree blockTree,
ISpecProvider specProvider,
ILogManager? logManager = null,
bool validate = false)
: base(worldStateManager.GlobalStateReader, worldStateManager.CreateResettableWorldState(), blockTree, specProvider, logManager)
{
ReadOnlyBlockTree = baseBlockTree;
SpecProvider = specProvider;
DbProvider = readOnlyDbProvider;
WorldStateManager = worldStateManager;
_logManager = logManager;

BlockTree = new BlockTreeOverlay(ReadOnlyBlockTree, blockTree);
BlockhashProvider = new SimulateBlockhashProvider(new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager), BlockTree);
StateProvider = WorldStateManager.GlobalWorldState;
StateReader = WorldStateManager.GlobalStateReader;
BlockTree = new BlockTreeOverlay(baseBlockTree, blockTree);
StateProvider = worldState;
SimulateBlockhashProvider blockhashProvider = new SimulateBlockhashProvider(new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager), BlockTree);
CodeInfoRepository = new OverridableCodeInfoRepository(new CodeInfoRepository());
VirtualMachine = new SimulateVirtualMachine(new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager));
_transactionProcessor = new SimulateTransactionProcessor(SpecProvider, StateProvider, VirtualMachine, CodeInfoRepository, _logManager, validate);
SimulateVirtualMachine virtualMachine = new SimulateVirtualMachine(new VirtualMachine(blockhashProvider, specProvider, CodeInfoRepository, logManager));
_transactionProcessor = new SimulateTransactionProcessor(SpecProvider, StateProvider, virtualMachine, CodeInfoRepository, _logManager, validate);
_blockValidator = CreateValidator();
BlockTransactionPicker = new BlockProductionTransactionPicker(specProvider, true);
}

public IWorldStateManager WorldStateManager { get; }
public IVirtualMachine VirtualMachine { get; }
public IReadOnlyDbProvider DbProvider { get; }
public IReadOnlyBlockTree ReadOnlyBlockTree { get; set; }
private IReadOnlyDbProvider DbProvider { get; }
public OverridableCodeInfoRepository CodeInfoRepository { get; }
public BlockProductionTransactionPicker BlockTransactionPicker { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public SimulateReadOnlyBlocksProcessingEnv Create(bool validate)
IReadOnlyDbProvider editableDbProvider = new ReadOnlyDbProvider(dbProvider, true);
OverlayTrieStore overlayTrieStore = new(editableDbProvider.StateDb, worldStateManager.TrieStore, logManager);
OverlayWorldStateManager overlayWorldStateManager = new(editableDbProvider, overlayTrieStore, logManager);
IWorldState worldState = overlayWorldStateManager.GlobalWorldState;
BlockTree tempBlockTree = CreateTempBlockTree(editableDbProvider, specProvider, logManager, editableDbProvider);

return new SimulateReadOnlyBlocksProcessingEnv(
overlayWorldStateManager,
worldState,
baseBlockTree,
editableDbProvider,
tempBlockTree,
Expand Down

0 comments on commit 54c0739

Please sign in to comment.