From 1048e2d6a36b8c3fb467d60fd33122bae0cc7ebe Mon Sep 17 00:00:00 2001 From: Martin HS Date: Fri, 8 Dec 2023 11:06:01 +0100 Subject: [PATCH] cmd/evm: fix dump after state-test exec (#28650) The dump after state-test didn't work, the problem was an error, "Already committed", which was silently ignored. This change re-initialises the state, so the dumping works again. --- cmd/evm/staterunner.go | 17 +++++++++-------- core/state/dump.go | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index 618ddf2ede..6e751b630f 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -100,18 +100,19 @@ func runStateTest(fname string, cfg vm.Config, jsonOut, dump bool) error { for _, st := range test.Subtests() { // Run the test and aggregate the result result := &StatetestResult{Name: key, Fork: st.Fork, Pass: true} - test.Run(st, cfg, false, rawdb.HashScheme, func(err error, snaps *snapshot.Tree, state *state.StateDB) { - if state != nil { - root := state.IntermediateRoot(false) + test.Run(st, cfg, false, rawdb.HashScheme, func(err error, snaps *snapshot.Tree, statedb *state.StateDB) { + var root common.Hash + if statedb != nil { + root = statedb.IntermediateRoot(false) result.Root = &root if jsonOut { fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%#x\"}\n", root) } - } - // Dump any state to aid debugging - if dump { - dump := state.RawDump(nil) - result.State = &dump + if dump { // Dump any state to aid debugging + cpy, _ := state.New(root, statedb.Database(), nil) + dump := cpy.RawDump(nil) + result.State = &dump + } } if err != nil { // Test failed, mark as so diff --git a/core/state/dump.go b/core/state/dump.go index cf46621144..55abb50f1c 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -129,6 +129,7 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey [] trieIt, err := s.trie.NodeIterator(conf.Start) if err != nil { + log.Error("Trie dumping error", "err", err) return nil } it := trie.NewIterator(trieIt)