From 4bba61322ec058c502818f9db1218853fa4f1d5e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 13 Oct 2024 17:40:51 +0100 Subject: [PATCH] Skip committing state during warmup (#7595) --- .../Processing/BlockCachePreWarmer.cs | 2 +- .../TransactionProcessing/ITransactionProcessor.cs | 6 ++++++ .../SystemTransactionProcessor.cs | 2 +- .../TransactionProcessing/TransactionProcessor.cs | 10 +++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs index 9cd7e79e497..2f85445b6bc 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs @@ -147,7 +147,7 @@ private void WarmupTransactions(ParallelOptions parallelOptions, IReleaseSpec sp { scope.WorldState.WarmUp(tx.AccessList); // eip-2930 } - TransactionResult result = scope.TransactionProcessor.Trace(systemTransaction, new BlockExecutionContext(block.Header.Clone()), NullTxTracer.Instance); + TransactionResult result = scope.TransactionProcessor.Warmup(systemTransaction, new BlockExecutionContext(block.Header.Clone()), NullTxTracer.Instance); if (_logger.IsTrace) _logger.Trace($"Finished pre-warming cache for tx[{i}] {tx.Hash} with {result}"); } catch (Exception ex) when (ex is EvmException or OverflowException) diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/ITransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/ITransactionProcessor.cs index 96ac8e27948..e347490cb11 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/ITransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/ITransactionProcessor.cs @@ -28,4 +28,10 @@ public interface ITransactionProcessor /// Will NOT charge gas from sender account, so stateDiff will miss gas fee /// TransactionResult Trace(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer); + + /// + /// Call transaction, no validations, don't commit state + /// Will NOT charge gas from sender account + /// + TransactionResult Warmup(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer); } diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs index e84a21f60c3..9eaab2cd442 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs @@ -38,7 +38,7 @@ protected override TransactionResult Execute(Transaction tx, in BlockExecutionCo WorldState.CreateAccountIfNotExists(Address.SystemUser, UInt256.Zero, UInt256.Zero); } - return base.Execute(tx, in blCtx, tracer, !opts.HasFlag(ExecutionOptions.NoValidation) + return base.Execute(tx, in blCtx, tracer, (opts != ExecutionOptions.Warmup && !opts.HasFlag(ExecutionOptions.NoValidation)) ? opts | (ExecutionOptions)OriginalValidate | ExecutionOptions.NoValidation : opts); } diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs index 3ebf373ab25..209697860c2 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs @@ -64,7 +64,12 @@ protected enum ExecutionOptions /// /// Skip potential fail checks /// - NoValidation = Commit | 4, + Warmup = 4, + + /// + /// Skip potential fail checks and commit state after execution + /// + NoValidation = Commit | Warmup, /// /// Commit and later restore state also skip validation, use for CallAndRestore @@ -112,6 +117,9 @@ public TransactionResult Execute(Transaction transaction, in BlockExecutionConte public TransactionResult Trace(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.NoValidation); + public TransactionResult Warmup(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => + ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.Warmup); + private TransactionResult ExecuteCore(Transaction tx, in BlockExecutionContext blCtx, ITxTracer tracer, ExecutionOptions opts) { if (tx.IsSystem())