Skip to content

Commit

Permalink
Allow state overrides for debug_traceCall
Browse files Browse the repository at this point in the history
  • Loading branch information
alexb5dh committed Aug 26, 2024
1 parent 37eb5e3 commit 9a7094d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Address, AccountOverride> stateOverride, CancellationToken cancellationToken)
{
Block block = _blockTree.FindBlock(blockParameter);
if (block is null) throw new InvalidOperationException($"Cannot find block {blockParameter}");
Expand All @@ -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
{
Expand Down Expand Up @@ -189,15 +191,16 @@ public IEnumerable<string> 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<Address, AccountOverride>? stateOverride = null)
{
ArgumentNullException.ThrowIfNull(txHash);

IBlockTracer<GethLikeTxTrace> tracer = CreateOptionsTracer(block.Header, options with { TxHash = txHash });

try
{
_processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken));
_processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken), stateOverride);
return tracer.BuildResult().SingleOrDefault();
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Address, AccountOverride>? stateOverride, CancellationToken cancellationToken);
IReadOnlyCollection<GethLikeTxTrace> TraceBlock(BlockParameter blockParameter, GethTraceOptions options, CancellationToken cancellationToken);
IReadOnlyCollection<GethLikeTxTrace> TraceBlock(Rlp blockRlp, GethTraceOptions options, CancellationToken cancellationToken);
IEnumerable<string> TraceBlockToFile(Hash256 blockHash, GethTraceOptions options, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Address, AccountOverride>? stateOverride = null) =>
_tracer.Trace(blockParameter, transaction, gethTraceOptions ?? GethTraceOptions.Default, stateOverride, cancellationToken);

public IReadOnlyCollection<GethLikeTxTrace> GetBlockTrace(BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null) =>
_tracer.TraceBlock(blockParameter, gethTraceOptions ?? GethTraceOptions.Default, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,15 +69,16 @@ public ResultWrapper<GethLikeTxTrace> debug_traceTransaction(Hash256 transaction
return ResultWrapper<GethLikeTxTrace>.Success(transactionTrace);
}

public ResultWrapper<GethLikeTxTrace> debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = null)
public ResultWrapper<GethLikeTxTrace> debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null,
GethTraceOptions? options = null, Dictionary<Address, AccountOverride>? stateOverride = null)
{
blockParameter ??= BlockParameter.Latest;
call.EnsureDefaults(_jsonRpcConfig.GasCap);
Transaction tx = call.ToTransaction();
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<GethLikeTxTrace>.Fail($"Cannot find transactionTrace for hash: {tx.Hash}", ErrorCodes.ResourceNotFound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Address, AccountOverride>? stateOverride = null);
IReadOnlyCollection<GethLikeTxTrace> GetBlockTrace(BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions gethTraceOptions = null);
IReadOnlyCollection<GethLikeTxTrace> GetBlockTrace(Rlp blockRlp, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null);
byte[] GetBlockRlp(BlockParameter param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +33,7 @@ public interface IDebugRpcModule : IRpcModule
ResultWrapper<GethLikeTxTrace> 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<GethLikeTxTrace> debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = null);
ResultWrapper<GethLikeTxTrace> debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = null, Dictionary<Address, AccountOverride>? stateOverride = null);

[JsonRpcMethod(Description = "", IsSharable = true)]
ResultWrapper<GethLikeTxTrace> debug_traceTransactionByBlockAndIndex(BlockParameter blockParameter, int txIndex, GethTraceOptions options = null);
Expand Down

0 comments on commit 9a7094d

Please sign in to comment.