From d729550a5dd3dd7152bc78a40d6245a50112072a Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 3 Nov 2025 10:45:51 +0100 Subject: [PATCH] review feedback from Gary part 1 Co-authored-by: Gary Rong --- cmd/evm/internal/t8ntool/execution.go | 1 + cmd/evm/internal/t8ntool/transition.go | 10 ++++++---- core/state/dump.go | 21 +++++++++++---------- tests/block_test_util.go | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index fa4f63a1a1..335158720d 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -194,6 +194,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, Time: pre.Env.ParentTimestamp, ExcessBlobGas: pre.Env.ParentExcessBlobGas, BlobGasUsed: pre.Env.ParentBlobGasUsed, + BaseFee: pre.Env.ParentBaseFee, } header := &types.Header{ Time: pre.Env.Timestamp, diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index c47561e57b..e34e17d8f4 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -118,6 +118,7 @@ func Transition(ctx *cli.Context) error { } } prestate.Pre = inputData.Alloc + if btStr != stdinSelector && btStr != "" { if err := readFile(btStr, "BT", &inputData.BT); err != nil { return err @@ -125,6 +126,7 @@ func Transition(ctx *cli.Context) error { } prestate.BT = inputData.BT + // Set the block environment if envStr != stdinSelector { var env stEnv @@ -195,8 +197,10 @@ func Transition(ctx *cli.Context) error { return err } // Dump the execution result - collector := make(Alloc) - var btleaves map[common.Hash]hexutil.Bytes + var ( + collector = make(Alloc) + btleaves map[common.Hash]hexutil.Bytes + ) isBinary := chainConfig.IsVerkle(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) if !isBinary { s.DumpToCollector(collector, nil) @@ -492,7 +496,6 @@ func genBinTrieFromAlloc(alloc core.GenesisAlloc) (*bintrie.BinaryTrie, error) { return nil, fmt.Errorf("error inserting storage: %w", err) } } - account := &types.StateAccount{ Balance: uint256.MustFromBig(acc.Balance), Nonce: acc.Nonce, @@ -503,7 +506,6 @@ func genBinTrieFromAlloc(alloc core.GenesisAlloc) (*bintrie.BinaryTrie, error) { if err != nil { return nil, fmt.Errorf("error inserting account: %w", err) } - err = bt.UpdateContractCode(addr, common.BytesToHash(account.CodeHash), acc.Code) if err != nil { return nil, fmt.Errorf("error inserting code: %w", err) diff --git a/core/state/dump.go b/core/state/dump.go index 4a17d1adde..829d106ed3 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -18,6 +18,7 @@ package state import ( "encoding/json" + "errors" "fmt" "time" @@ -224,17 +225,17 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey [] // DumpBinTrieLeaves collects all binary trie leaf nodes into the provided map. func (s *StateDB) DumpBinTrieLeaves(collector map[common.Hash]hexutil.Bytes) error { - if s.trie == nil { - trie, err := s.db.OpenTrie(s.originalRoot) - if err != nil { - return err - } - s.trie = trie - } - - it, err := s.trie.(*bintrie.BinaryTrie).NodeIterator(nil) + tr, err := s.db.OpenTrie(s.originalRoot) if err != nil { - panic(err) + return err + } + btr, ok := tr.(*bintrie.BinaryTrie) + if !ok { + return errors.New("trie is not a binary trie") + } + it, err := btr.NodeIterator(nil) + if err != nil { + return err } for it.Next(true) { if it.Leaf() { diff --git a/tests/block_test_util.go b/tests/block_test_util.go index 99ce051573..2ced18787a 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -118,8 +118,8 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, tracer *t } // import pre accounts & construct test genesis block & state root // Commit genesis state - gspec := t.genesis(config) var ( + gspec = t.genesis(config) db = rawdb.NewMemoryDatabase() tconf = &triedb.Config{ Preimages: true,