Skip to content

Commit

Permalink
Refactor/move prewarm out of tx env base (#7963)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Dec 23, 2024
1 parent 9e75b29 commit 76dacba
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ public OverridableTxProcessingEnv(
OverridableWorldStateManager worldStateManager,
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager? logManager,
IWorldState? worldStateToWarmUp = null
) : base(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp)
ILogManager? logManager
) : base(worldStateManager.GlobalStateReader, worldStateManager.CreateResettableWorldState(), readOnlyBlockTree, specProvider, logManager)
{
WorldStateManager = worldStateManager;
StateProvider = (OverridableWorldState)base.StateProvider;
CodeInfoRepository = new(new CodeInfoRepository((worldStateToWarmUp as IPreBlockCaches)?.Caches.PrecompileCache));
CodeInfoRepository = new(new CodeInfoRepository());
Machine = new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager);
_transactionProcessorLazy = new(CreateTransactionProcessor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,36 @@ protected ITransactionProcessor TransactionProcessor
public IVirtualMachine Machine { get; }

public ICodeInfoRepository CodeInfoRepository { get; }

public ReadOnlyTxProcessingEnv(
IWorldStateManager worldStateManager,
IBlockTree blockTree,
ISpecProvider? specProvider,
ILogManager? logManager,
IWorldState? worldStateToWarmUp = null)
: this(worldStateManager, blockTree.AsReadOnly(), specProvider, logManager, worldStateToWarmUp)
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager logManager,
IWorldState worldStateToWarmUp
) : this(worldStateManager.GlobalStateReader, worldStateManager.CreateResettableWorldState(worldStateToWarmUp), new CodeInfoRepository((worldStateToWarmUp as IPreBlockCaches)?.Caches.PrecompileCache), readOnlyBlockTree, specProvider, logManager)
{
}

public ReadOnlyTxProcessingEnv(
IWorldStateManager worldStateManager,
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider? specProvider,
ILogManager? logManager,
IWorldState? worldStateToWarmUp = null
) : base(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp)
ISpecProvider specProvider,
ILogManager logManager
) : this(worldStateManager.GlobalStateReader, worldStateManager.CreateResettableWorldState(), new CodeInfoRepository(), readOnlyBlockTree, specProvider, logManager)
{
}

private ReadOnlyTxProcessingEnv(
IStateReader stateReader,
IWorldState stateProvider,
ICodeInfoRepository codeInfoRepository,
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager logManager
) : base(stateReader, stateProvider, readOnlyBlockTree, specProvider, logManager)
{
CodeInfoRepository = new CodeInfoRepository((worldStateToWarmUp as IPreBlockCaches)?.Caches.PrecompileCache);
CodeInfoRepository = codeInfoRepository;
Machine = new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager);
BlockTree = readOnlyBlockTree ?? throw new ArgumentNullException(nameof(readOnlyBlockTree));
BlockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ public class ReadOnlyTxProcessingEnvBase
public IBlockhashProvider BlockhashProvider { get; protected set; }

public ISpecProvider SpecProvider { get; }
public ILogManager? LogManager { get; set; }
protected ILogManager LogManager { get; }

protected ReadOnlyTxProcessingEnvBase(
IWorldStateManager worldStateManager,
IStateReader stateReader,
IWorldState stateProvider,
IBlockTree readOnlyBlockTree,
ISpecProvider? specProvider,
ILogManager? logManager,
IWorldState? worldStateToWarmUp = null
ISpecProvider specProvider,
ILogManager logManager
)
{
ArgumentNullException.ThrowIfNull(specProvider);
ArgumentNullException.ThrowIfNull(worldStateManager);
SpecProvider = specProvider;
StateReader = worldStateManager.GlobalStateReader;
StateProvider = worldStateManager.CreateResettableWorldState(worldStateToWarmUp);
BlockTree = readOnlyBlockTree ?? throw new ArgumentNullException(nameof(readOnlyBlockTree));
StateReader = stateReader;
StateProvider = stateProvider;
BlockTree = readOnlyBlockTree;
BlockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager);
LogManager = logManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Nethermind.Blockchain;
using Nethermind.Core.Specs;
using Nethermind.Evm;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Logging;
using Nethermind.State;
Expand All @@ -12,19 +13,38 @@ namespace Nethermind.Consensus.Processing;
public class ReadOnlyTxProcessingEnvFactory(
IWorldStateManager worldStateManager,
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider? specProvider,
ILogManager? logManager,
ISpecProvider specProvider,
ILogManager logManager,
IWorldState? worldStateToWarmUp = null) : IReadOnlyTxProcessingEnvFactory
{
public ReadOnlyTxProcessingEnvFactory(
IWorldStateManager worldStateManager,
IBlockTree blockTree,
ISpecProvider? specProvider,
ILogManager? logManager,
ISpecProvider specProvider,
ILogManager logManager,
IWorldState? worldStateToWarmUp = null)
: this(worldStateManager, blockTree.AsReadOnly(), specProvider, logManager, worldStateToWarmUp)
{
}

public IReadOnlyTxProcessorSource Create() => new ReadOnlyTxProcessingEnv(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp);
public IReadOnlyTxProcessorSource Create()
{
if (worldStateToWarmUp is null)
{
return new ReadOnlyTxProcessingEnv(
worldStateManager,
readOnlyBlockTree,
specProvider,
logManager);
}
else
{
return new ReadOnlyTxProcessingEnv(
worldStateManager,
readOnlyBlockTree,
specProvider,
logManager,
worldStateToWarmUp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public SimulateReadOnlyBlocksProcessingEnv(
ISpecProvider specProvider,
ILogManager? logManager = null,
bool validate = false)
: base(worldStateManager, blockTree, specProvider, logManager)
: base(worldStateManager.GlobalStateReader, worldStateManager.CreateResettableWorldState(), blockTree, specProvider, logManager)
{
ReadOnlyBlockTree = baseBlockTree;
DbProvider = readOnlyDbProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public class OptimismOverridableTxProcessingEnv(
ISpecProvider specProvider,
ILogManager logManager,
IL1CostHelper l1CostHelper,
IOptimismSpecHelper opSpecHelper,
IWorldState? worldStateToWarmUp = null)
: OverridableTxProcessingEnv(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp)
IOptimismSpecHelper opSpecHelper)
: OverridableTxProcessingEnv(worldStateManager, readOnlyBlockTree, specProvider, logManager)
{
protected override ITransactionProcessor CreateTransactionProcessor()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ public class OptimismReadOnlyTxProcessingEnv(
ISpecProvider specProvider,
ILogManager logManager,
IL1CostHelper l1CostHelper,
IOptimismSpecHelper opSpecHelper,
IWorldState? worldStateToWarmUp = null) : ReadOnlyTxProcessingEnv(
IOptimismSpecHelper opSpecHelper) : ReadOnlyTxProcessingEnv(
worldStateManager,
readOnlyBlockTree,
specProvider,
logManager,
worldStateToWarmUp
logManager
)
{
protected override ITransactionProcessor CreateTransactionProcessor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ public class TaikoReadOnlyTxProcessingEnv(
OverridableWorldStateManager worldStateManager,
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager logManager,
IWorldState? worldStateToWarmUp = null) : OverridableTxProcessingEnv(
ILogManager logManager) : OverridableTxProcessingEnv(
worldStateManager,
readOnlyBlockTree,
specProvider,
logManager,
worldStateToWarmUp
)
logManager
)
{
protected override ITransactionProcessor CreateTransactionProcessor() =>
new TaikoTransactionProcessor(SpecProvider, StateProvider, Machine, CodeInfoRepository, LogManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class TaikoReadOnlyTxProcessingEnvFactory(
OverridableWorldStateManager worldStateManager,
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager logManager,
IWorldState? worldStateToWarmUp = null)
ILogManager logManager)
{
public TaikoReadOnlyTxProcessingEnv Create() => new(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp);
public TaikoReadOnlyTxProcessingEnv Create() => new(worldStateManager, readOnlyBlockTree, specProvider, logManager);
}

0 comments on commit 76dacba

Please sign in to comment.