From 9a7094d2ebf67ac8b282d52471ccee947d13aae8 Mon Sep 17 00:00:00 2001 From: Alex Bespalov Date: Mon, 26 Aug 2024 08:40:55 +0300 Subject: [PATCH] Allow state overrides for `debug_traceCall` --- .../Nethermind.Consensus/Tracing/GethStyleTracer.cs | 11 +++++++---- .../Nethermind.Consensus/Tracing/IGethStyleTracer.cs | 3 ++- .../Modules/DebugModule/DebugBridge.cs | 6 ++++-- .../Modules/DebugModule/DebugRpcModule.cs | 6 ++++-- .../Modules/DebugModule/IDebugBridge.cs | 3 ++- .../Modules/DebugModule/IDebugRpcModule.cs | 4 +++- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs b/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs index 3e240bef779..8f3e3378131 100644 --- a/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs +++ b/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs @@ -16,6 +16,7 @@ using Nethermind.Core.Extensions; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.Evm; using Nethermind.Evm.Tracing; using Nethermind.Evm.Tracing.GethStyle; using Nethermind.Evm.Tracing.GethStyle.Custom.JavaScript; @@ -71,7 +72,8 @@ public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions op return TraceBlock(GetBlockToTrace(block), options with { TxHash = txHash }, cancellationToken).FirstOrDefault(); } - public GethLikeTxTrace? Trace(BlockParameter blockParameter, Transaction tx, GethTraceOptions options, CancellationToken cancellationToken) + public GethLikeTxTrace? Trace(BlockParameter blockParameter, Transaction tx, GethTraceOptions options, + Dictionary stateOverride, CancellationToken cancellationToken) { Block block = _blockTree.FindBlock(blockParameter); if (block is null) throw new InvalidOperationException($"Cannot find block {blockParameter}"); @@ -82,7 +84,7 @@ public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions op try { - return Trace(block, tx.Hash, cancellationToken, options); + return Trace(block, tx.Hash, cancellationToken, options, stateOverride); } finally { @@ -189,7 +191,8 @@ public IEnumerable TraceBadBlockToFile(Hash256 blockHash, GethTraceOptio return tracer.FileNames; } - private GethLikeTxTrace? Trace(Block block, Hash256? txHash, CancellationToken cancellationToken, GethTraceOptions options) + private GethLikeTxTrace? Trace(Block block, Hash256? txHash, CancellationToken cancellationToken, GethTraceOptions options, + Dictionary? stateOverride = null) { ArgumentNullException.ThrowIfNull(txHash); @@ -197,7 +200,7 @@ public IEnumerable TraceBadBlockToFile(Hash256 blockHash, GethTraceOptio try { - _processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken)); + _processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken), stateOverride); return tracer.BuildResult().SingleOrDefault(); } catch diff --git a/src/Nethermind/Nethermind.Consensus/Tracing/IGethStyleTracer.cs b/src/Nethermind/Nethermind.Consensus/Tracing/IGethStyleTracer.cs index 4651add653e..a274351e6d5 100644 --- a/src/Nethermind/Nethermind.Consensus/Tracing/IGethStyleTracer.cs +++ b/src/Nethermind/Nethermind.Consensus/Tracing/IGethStyleTracer.cs @@ -6,6 +6,7 @@ using Nethermind.Blockchain.Find; using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Evm; using Nethermind.Evm.Tracing.GethStyle; using Nethermind.Serialization.Rlp; @@ -18,7 +19,7 @@ public interface IGethStyleTracer GethLikeTxTrace Trace(long blockNumber, int txIndex, GethTraceOptions options, CancellationToken cancellationToken); GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions options, CancellationToken cancellationToken); GethLikeTxTrace Trace(Rlp blockRlp, Hash256 txHash, GethTraceOptions options, CancellationToken cancellationToken); - GethLikeTxTrace? Trace(BlockParameter blockParameter, Transaction tx, GethTraceOptions options, CancellationToken cancellationToken); + GethLikeTxTrace? Trace(BlockParameter blockParameter, Transaction tx, GethTraceOptions options, Dictionary? stateOverride, CancellationToken cancellationToken); IReadOnlyCollection TraceBlock(BlockParameter blockParameter, GethTraceOptions options, CancellationToken cancellationToken); IReadOnlyCollection TraceBlock(Rlp blockRlp, GethTraceOptions options, CancellationToken cancellationToken); IEnumerable TraceBlockToFile(Hash256 blockHash, GethTraceOptions options, CancellationToken cancellationToken); diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugBridge.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugBridge.cs index dd7d34ebc82..8936004d1d5 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugBridge.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugBridge.cs @@ -16,6 +16,7 @@ using Nethermind.Core.Crypto; using Nethermind.Core.Specs; using Nethermind.Db; +using Nethermind.Evm; using Nethermind.Evm.Tracing.GethStyle; using Nethermind.Serialization.Rlp; using Nethermind.State.Proofs; @@ -151,8 +152,9 @@ public GethLikeTxTrace GetTransactionTrace(Hash256 blockHash, int index, Cancell public GethLikeTxTrace GetTransactionTrace(Rlp blockRlp, Hash256 transactionHash, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null) => _tracer.Trace(blockRlp, transactionHash, gethTraceOptions ?? GethTraceOptions.Default, cancellationToken); - public GethLikeTxTrace? GetTransactionTrace(Transaction transaction, BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null) => - _tracer.Trace(blockParameter, transaction, gethTraceOptions ?? GethTraceOptions.Default, cancellationToken); + public GethLikeTxTrace? GetTransactionTrace(Transaction transaction, BlockParameter blockParameter, CancellationToken cancellationToken, + GethTraceOptions? gethTraceOptions = null, Dictionary? stateOverride = null) => + _tracer.Trace(blockParameter, transaction, gethTraceOptions ?? GethTraceOptions.Default, stateOverride, cancellationToken); public IReadOnlyCollection GetBlockTrace(BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null) => _tracer.TraceBlock(blockParameter, gethTraceOptions ?? GethTraceOptions.Default, cancellationToken); diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugRpcModule.cs index 9c0b2919d32..b195e2e3acb 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugRpcModule.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using Nethermind.JsonRpc.Modules.Eth; using Nethermind.Core.Specs; +using Nethermind.Evm; using Nethermind.Facade.Eth; namespace Nethermind.JsonRpc.Modules.DebugModule; @@ -68,7 +69,8 @@ public ResultWrapper debug_traceTransaction(Hash256 transaction return ResultWrapper.Success(transactionTrace); } - public ResultWrapper debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = null) + public ResultWrapper debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, + GethTraceOptions? options = null, Dictionary? stateOverride = null) { blockParameter ??= BlockParameter.Latest; call.EnsureDefaults(_jsonRpcConfig.GasCap); @@ -76,7 +78,7 @@ public ResultWrapper debug_traceCall(TransactionForRpc call, Bl using CancellationTokenSource cancellationTokenSource = new(_traceTimeout); CancellationToken cancellationToken = cancellationTokenSource.Token; - GethLikeTxTrace transactionTrace = _debugBridge.GetTransactionTrace(tx, blockParameter, cancellationToken, options); + GethLikeTxTrace transactionTrace = _debugBridge.GetTransactionTrace(tx, blockParameter, cancellationToken, options, stateOverride); if (transactionTrace is null) { return ResultWrapper.Fail($"Cannot find transactionTrace for hash: {tx.Hash}", ErrorCodes.ResourceNotFound); diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugBridge.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugBridge.cs index 9b8db38d2cf..84f09ecd68e 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugBridge.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugBridge.cs @@ -7,6 +7,7 @@ using Nethermind.Blockchain.Find; using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Evm; using Nethermind.Evm.Tracing.GethStyle; using Nethermind.Serialization.Rlp; using Nethermind.Synchronization.Reporting; @@ -19,7 +20,7 @@ public interface IDebugBridge GethLikeTxTrace GetTransactionTrace(long blockNumber, int index, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null); GethLikeTxTrace GetTransactionTrace(Hash256 blockHash, int index, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null); GethLikeTxTrace GetTransactionTrace(Rlp blockRlp, Hash256 transactionHash, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null); - GethLikeTxTrace? GetTransactionTrace(Transaction transaction, BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null); + GethLikeTxTrace? GetTransactionTrace(Transaction transaction, BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null, Dictionary? stateOverride = null); IReadOnlyCollection GetBlockTrace(BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions gethTraceOptions = null); IReadOnlyCollection GetBlockTrace(Rlp blockRlp, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null); byte[] GetBlockRlp(BlockParameter param); diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugRpcModule.cs index dc0a8bd9014..83c48a63936 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/IDebugRpcModule.cs @@ -4,7 +4,9 @@ using System.Collections.Generic; using System.Threading.Tasks; using Nethermind.Blockchain.Find; +using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Evm; using Nethermind.Evm.Tracing.GethStyle; using Nethermind.Facade.Eth; using Nethermind.JsonRpc.Data; @@ -31,7 +33,7 @@ public interface IDebugRpcModule : IRpcModule ResultWrapper debug_traceTransaction(Hash256 transactionHash, GethTraceOptions options = null); [JsonRpcMethod(Description = "This method lets you run an eth_call within the context of the given block execution using the final state of parent block as the base. The block can be specified either by hash or by number. It takes the same input object as a eth_call. It returns the same output as debug_traceTransaction.", IsImplemented = true, IsSharable = true)] - ResultWrapper debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = null); + ResultWrapper debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = null, Dictionary? stateOverride = null); [JsonRpcMethod(Description = "", IsSharable = true)] ResultWrapper debug_traceTransactionByBlockAndIndex(BlockParameter blockParameter, int txIndex, GethTraceOptions options = null);