Skip to content

Commit

Permalink
tracing: Show OptimismBaseFeeRecipient in prestate
Browse files Browse the repository at this point in the history
The OptimismBaseFeeRecipient should show up in prestate tracing results
(both the normal prestate and the diff mode prestate results) if
IsOptimism.
I added one prestate diff test with Optimism turned on to show that it
works correctly. This required adding Random (so that IsMerge is true)
and L1CostFunc to the test block context.
  • Loading branch information
karlb committed Oct 21, 2024
1 parent 82dd9eb commit 4966438
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 4 deletions.
2 changes: 1 addition & 1 deletion eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
// Configure a blockchain with the given prestate
var (
signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
context = test.Context.toBlockContext(test.Genesis)
state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
context = test.Context.toBlockContext(test.Genesis, state.StateDB)
)
state.Close()

Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/internal/tracetest/flat_calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func flatCallTracerTestRunner(tracerName string, filename string, dirPath string
return fmt.Errorf("failed to parse testcase input: %v", err)
}
signer := types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
context := test.Context.toBlockContext(test.Genesis)
state := tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
context := test.Context.toBlockContext(test.Genesis, state.StateDB)
defer state.Close()

// Create the tracer, the EVM environment and run it
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/internal/tracetest/prestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
// Configure a blockchain with the given prestate
var (
signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
context = test.Context.toBlockContext(test.Genesis)
state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
context = test.Context.toBlockContext(test.Genesis, state.StateDB)
)
defer state.Close()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"genesis": {
"baseFeePerGas": "1000000000",
"blobGasUsed": "0",
"difficulty": "0",
"excessBlobGas": "0",
"extraData": "0x",
"gasLimit": "11500000",
"hash": "0x4a3a3699d4d328652bfea00c9fdc2be4768519142e10e0d6cebdbec5056f101e",
"miner": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": "0",
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"stateRoot": "0x0344388281802511fb31b24f96f087a8b935683646d2a75de96465703505e065",
"timestamp": "0",
"withdrawals": [],
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"alloc": {
"0x0000000000000000000000000000000000000000": {
"balance": "0x0"
},
"0xf7b094d8c987eff69afec8f93153ac9829577125": {
"balance": "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7"
}
},
"config": {
"chainId": 1337,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"arrowGlacierBlock": 0,
"grayGlacierBlock": 0,
"bedrockBlock": 0,
"shanghaiTime": 0,
"cancunTime": 0,
"terminalTotalDifficulty": 0,
"terminalTotalDifficultyPassed": true,
"depositContractAddress": "0x0000000000000000000000000000000000000000",
"optimism": {
"eip1559Elasticity": 6,
"eip1559Denominator": 50,
"eip1559DenominatorCanyon": 250
}
}
},
"context": {
"number": "1",
"difficulty": "0",
"timestamp": "1729512767",
"gasLimit": "11511229",
"miner": "0x0000000000000000000000000000000000000000",
"baseFeePerGas": "875000000",
"random": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"random": "0x0000000000000000000000000000000000000000000000000000000000000000",
"input": "0x02f8708205398001847735940182520894f7b094d8c987eff69afec8f93153ac9829577125880de0b6b3a764000080c001a0e44882c072410fbadfd4783a71be745edfcedd9fc9ab55b66e25bb039db2f579a017c13129640ceff7ffa674bcff74bcce168404aa8450a67ece2737ca5a554a12",
"result": {
"post": {
"0x0000000000000000000000000000000000000000": {
"balance": "0x5208"
},
"0x4200000000000000000000000000000000000019": {
"balance": "0x10b643590600"
},
"0xf7b094d8c987eff69afec8f93153ac9829577125": {
"balance": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffef49bca6a7ef",
"nonce": 1
}
},
"pre": {
"0x0000000000000000000000000000000000000000": {
"balance": "0x0"
},
"0x4200000000000000000000000000000000000019": {
"balance": "0x0"
},
"0xf7b094d8c987eff69afec8f93153ac9829577125": {
"balance": "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7"
}
}
},
"tracerConfig": {
"diffMode": true
}
}
5 changes: 4 additions & 1 deletion eth/tracers/internal/tracetest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"

// Force-load native and js packages, to trigger registration
Expand All @@ -34,7 +35,7 @@ type callContext struct {
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
}

func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
func (c *callContext) toBlockContext(genesis *core.Genesis, statedb types.StateGetter) vm.BlockContext {
context := vm.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
Expand All @@ -43,6 +44,8 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
Time: uint64(c.Time),
Difficulty: (*big.Int)(c.Difficulty),
GasLimit: uint64(c.GasLimit),
Random: &genesis.Mixhash,
L1CostFunc: types.NewL1CostFunc(genesis.Config, statedb),
}
if genesis.Config.IsLondon(context.BlockNumber) {
context.BaseFee = (*big.Int)(c.BaseFee)
Expand Down
4 changes: 4 additions & 0 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/eth/tracers/internal"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

//go:generate go run github.com/fjl/gencodec -type account -field-override accountMarshaling -out gen_account_json.go
Expand Down Expand Up @@ -158,6 +159,9 @@ func (t *prestateTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction
t.lookupAccount(from)
t.lookupAccount(t.to)
t.lookupAccount(env.Coinbase)
if env.ChainConfig.Optimism != nil {
t.lookupAccount(params.OptimismBaseFeeRecipient)
}
}

func (t *prestateTracer) OnTxEnd(receipt *types.Receipt, err error) {
Expand Down

0 comments on commit 4966438

Please sign in to comment.