Skip to content

Commit

Permalink
eth/tracers: add optional includePrecompiles flag to callTracer - def…
Browse files Browse the repository at this point in the history
…ault true is preserved (#10986)

relates to #9784

- Adds support for an optional `"includePrecompiles"` tracer config
option for `callTracer` that users can use to control behaviour
(previous default of including precompile traces is preserved)
- Adds tests for default and for `"includePrecompiles": false` based on
https://etherscan.io/tx/0x536434786ace02697118c44abf2835f188bf79902807c61a523ca3a6200bc350
  • Loading branch information
taratorio authored Jul 3, 2024
1 parent 30cae52 commit 4193e03
Show file tree
Hide file tree
Showing 5 changed files with 971 additions and 39 deletions.
51 changes: 24 additions & 27 deletions eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/ledgerwatch/erigon-lib/common/dir"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon-lib/common/hexutility"

"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/core"
Expand Down Expand Up @@ -133,41 +132,37 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
t.Fatalf("failed to parse testcase input: %v", err)
}
// Configure a blockchain with the given prestate
var (
signer = types.MakeSigner(test.Genesis.Config, uint64(test.Context.Number), uint64(test.Context.Time))
origin, _ = signer.Sender(tx)
txContext = evmtypes.TxContext{
Origin: origin,
GasPrice: tx.GetPrice(),
}
context = evmtypes.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
Coinbase: test.Context.Miner,
BlockNumber: uint64(test.Context.Number),
Time: uint64(test.Context.Time),
Difficulty: (*big.Int)(test.Context.Difficulty),
GasLimit: uint64(test.Context.GasLimit),
}
rules = test.Genesis.Config.Rules(context.BlockNumber, context.Time)
)
signer := types.MakeSigner(test.Genesis.Config, uint64(test.Context.Number), uint64(test.Context.Time))
context := evmtypes.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
Coinbase: test.Context.Miner,
BlockNumber: uint64(test.Context.Number),
Time: uint64(test.Context.Time),
Difficulty: (*big.Int)(test.Context.Difficulty),
GasLimit: uint64(test.Context.GasLimit),
}
if test.Context.BaseFee != nil {
context.BaseFee, _ = uint256.FromBig((*big.Int)(test.Context.BaseFee))
}
rules := test.Genesis.Config.Rules(context.BlockNumber, context.Time)

m := mock.Mock(t)
dbTx, err := m.DB.BeginRw(m.Ctx)
require.NoError(t, err)
defer dbTx.Rollback()
statedb, _ := tests.MakePreState(rules, dbTx, test.Genesis.Alloc, uint64(test.Context.Number))
if test.Genesis.BaseFee != nil {
context.BaseFee, _ = uint256.FromBig(test.Genesis.BaseFee)
}
statedb, err := tests.MakePreState(rules, dbTx, test.Genesis.Alloc, uint64(test.Context.Number))
require.NoError(t, err)
tracer, err := tracers.New(tracerName, new(tracers.Context), test.TracerConfig)
if err != nil {
t.Fatalf("failed to create call tracer: %v", err)
}
evm := vm.NewEVM(context, txContext, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
msg, err := tx.AsMessage(*signer, test.Genesis.BaseFee, rules)
msg, err := tx.AsMessage(*signer, (*big.Int)(test.Context.BaseFee), rules)
if err != nil {
t.Fatalf("failed to prepare transaction for tracing: %v", err)
}
txContext := core.NewEVMTxContext(msg)
evm := vm.NewEVM(context, txContext, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.GetGas()).AddBlobGas(tx.GetBlobGas()), true /* refunds */, false /* gasBailout */)
if err != nil {
t.Fatalf("failed to execute transaction: %v", err)
Expand All @@ -183,8 +178,10 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
// This is a tweak to make it deterministic. Can be removed when
// we remove the legacy tracer.
var x callTrace
json.Unmarshal(res, &x)
res, _ = json.Marshal(x)
err = json.Unmarshal(res, &x)
require.NoError(t, err)
res, err = json.Marshal(x)
require.NoError(t, err)
}
want, err := json.Marshal(test.Result)
if err != nil {
Expand Down
Loading

0 comments on commit 4193e03

Please sign in to comment.