Skip to content

Commit

Permalink
Update supported methods to match Reth version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexb5dh committed Sep 1, 2024
1 parent 9a7094d commit 94c2618
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 24 deletions.
10 changes: 4 additions & 6 deletions src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ 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,
Dictionary<Address, AccountOverride> stateOverride, CancellationToken cancellationToken)
public GethLikeTxTrace? Trace(BlockParameter blockParameter, Transaction tx, GethTraceOptions options, CancellationToken cancellationToken)
{
Block block = _blockTree.FindBlock(blockParameter);
if (block is null) throw new InvalidOperationException($"Cannot find block {blockParameter}");
Expand All @@ -84,7 +83,7 @@ public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions op

try
{
return Trace(block, tx.Hash, cancellationToken, options, stateOverride);
return Trace(block, tx.Hash, cancellationToken, options);
}
finally
{
Expand Down Expand Up @@ -191,16 +190,15 @@ public IEnumerable<string> TraceBadBlockToFile(Hash256 blockHash, GethTraceOptio
return tracer.FileNames;
}

private GethLikeTxTrace? Trace(Block block, Hash256? txHash, CancellationToken cancellationToken, GethTraceOptions options,
Dictionary<Address, AccountOverride>? stateOverride = null)
private GethLikeTxTrace? Trace(Block block, Hash256? txHash, CancellationToken cancellationToken, GethTraceOptions options)
{
ArgumentNullException.ThrowIfNull(txHash);

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

try
{
_processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken), stateOverride);
_processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken), options.StateOverrides);
return tracer.BuildResult().SingleOrDefault();
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,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, Dictionary<Address, AccountOverride>? stateOverride, CancellationToken cancellationToken);
GethLikeTxTrace? Trace(BlockParameter blockParameter, Transaction tx, GethTraceOptions options, 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 @@ -2,9 +2,10 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

using Nethermind.Core;
using Nethermind.Core.Crypto;

namespace Nethermind.Evm.Tracing.GethStyle;
Expand Down Expand Up @@ -36,5 +37,8 @@ public record GethTraceOptions
[JsonPropertyName("tracerConfig")]
public JsonElement? TracerConfig { get; init; }

[JsonPropertyName("stateOverrides")]
public Dictionary<Address, AccountOverride>? StateOverrides { get; init; }

public static GethTraceOptions Default { get; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ public ResultWrapper<ParityTxTraceFromReplay> trace_call(TransactionForRpc call,
Dictionary<Address, AccountOverride>? stateOverride = null) =>
_traceModule.trace_call(call, traceTypes, blockParameter, stateOverride);

public ResultWrapper<IEnumerable<ParityTxTraceFromReplay>> trace_callMany(TransactionForRpcWithTraceTypes[] calls, BlockParameter? blockParameter = null,
Dictionary<Address, AccountOverride>? stateOverride = null) =>
_traceModule.trace_callMany(calls, blockParameter, stateOverride);
public ResultWrapper<IEnumerable<ParityTxTraceFromReplay>> trace_callMany(TransactionForRpcWithTraceTypes[] calls, BlockParameter? blockParameter = null) =>
_traceModule.trace_callMany(calls, blockParameter);

public ResultWrapper<ParityTxTraceFromReplay> trace_rawTransaction(byte[] data, string[] traceTypes) =>
_traceModule.trace_rawTransaction(data, traceTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ 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, Dictionary<Address, AccountOverride>? stateOverride = null) =>
_tracer.Trace(blockParameter, transaction, gethTraceOptions ?? GethTraceOptions.Default, stateOverride, cancellationToken);
public GethLikeTxTrace? GetTransactionTrace(Transaction transaction, BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null) =>
_tracer.Trace(blockParameter, transaction, gethTraceOptions ?? GethTraceOptions.Default, 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,7 +18,6 @@
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 @@ -69,16 +68,15 @@ 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, Dictionary<Address, AccountOverride>? stateOverride = null)
public ResultWrapper<GethLikeTxTrace> debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = 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, stateOverride);
GethLikeTxTrace transactionTrace = _debugBridge.GetTransactionTrace(tx, blockParameter, cancellationToken, options);
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 @@ -20,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, Dictionary<Address, AccountOverride>? stateOverride = null);
GethLikeTxTrace? GetTransactionTrace(Transaction transaction, BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = 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 @@ -33,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, Dictionary<Address, AccountOverride>? stateOverride = null);
ResultWrapper<GethLikeTxTrace> debug_traceCall(TransactionForRpc call, BlockParameter? blockParameter = null, GethTraceOptions? options = null);

[JsonRpcMethod(Description = "", IsSharable = true)]
ResultWrapper<GethLikeTxTrace> debug_traceTransactionByBlockAndIndex(BlockParameter blockParameter, int txIndex, GethTraceOptions options = null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ ResultWrapper<ParityTxTraceFromReplay> trace_call(TransactionForRpc call,
BlockParameter? blockParameter = null, Dictionary<Address, AccountOverride>? stateOverride = null);

[JsonRpcMethod(Description = "", IsImplemented = false, IsSharable = false)]
ResultWrapper<IEnumerable<ParityTxTraceFromReplay>> trace_callMany(TransactionForRpcWithTraceTypes[] calls,
BlockParameter? blockParameter = null, Dictionary<Address, AccountOverride>? stateOverride = null);
ResultWrapper<IEnumerable<ParityTxTraceFromReplay>> trace_callMany(TransactionForRpcWithTraceTypes[] calls, BlockParameter? blockParameter = null);

[JsonRpcMethod(Description = "Traces a call to eth_sendRawTransaction without making the call, returning the traces",
IsImplemented = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ResultWrapper<ParityTxTraceFromReplay> trace_call(TransactionForRpc call,
/// <summary>
/// Traces list of transactions. Doesn't charge fees.
/// </summary>
public ResultWrapper<IEnumerable<ParityTxTraceFromReplay>> trace_callMany(TransactionForRpcWithTraceTypes[] calls, BlockParameter? blockParameter = null, Dictionary<Address, AccountOverride>? stateOverride = null)
public ResultWrapper<IEnumerable<ParityTxTraceFromReplay>> trace_callMany(TransactionForRpcWithTraceTypes[] calls, BlockParameter? blockParameter = null)
{
blockParameter ??= BlockParameter.Latest;

Expand Down Expand Up @@ -97,7 +97,7 @@ public ResultWrapper<IEnumerable<ParityTxTraceFromReplay>> trace_callMany(Transa
}

Block block = new(headerSearch.Object!, txs, Enumerable.Empty<BlockHeader>());
IReadOnlyCollection<ParityLikeTxTrace>? traces = TraceBlock(block, new(traceTypeByTransaction), stateOverride);
IReadOnlyCollection<ParityLikeTxTrace>? traces = TraceBlock(block, new(traceTypeByTransaction));
return ResultWrapper<IEnumerable<ParityTxTraceFromReplay>>.Success(traces.Select(t => new ParityTxTraceFromReplay(t)));
}

Expand Down

0 comments on commit 94c2618

Please sign in to comment.