Skip to content

Commit

Permalink
Skip committing state during warmup (#7595)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Oct 13, 2024
1 parent 43b9af9 commit 4bba613
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public interface ITransactionProcessor
/// Will NOT charge gas from sender account, so stateDiff will miss gas fee
/// </summary>
TransactionResult Trace(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer);

/// <summary>
/// Call transaction, no validations, don't commit state
/// Will NOT charge gas from sender account
/// </summary>
TransactionResult Warmup(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ protected enum ExecutionOptions
/// <summary>
/// Skip potential fail checks
/// </summary>
NoValidation = Commit | 4,
Warmup = 4,

/// <summary>
/// Skip potential fail checks and commit state after execution
/// </summary>
NoValidation = Commit | Warmup,

/// <summary>
/// Commit and later restore state also skip validation, use for CallAndRestore
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 4bba613

Please sign in to comment.