Skip to content

Commit 37ecff0

Browse files
authored
cmd/evm, tests: record preimages if dump is expected (#26955)
With #25287 we made it so that preimages were not recorded by default. This had the side effect that the evm command is no longer able to dump state since it does a preimage lookup to determine the address represented by a key. This change enables the recording of preimages when the dump command is given.
1 parent 7f3fc15 commit 37ecff0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cmd/evm/runner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/ethereum/go-ethereum/internal/flags"
4141
"github.com/ethereum/go-ethereum/log"
4242
"github.com/ethereum/go-ethereum/params"
43+
"github.com/ethereum/go-ethereum/trie"
4344
"github.com/urfave/cli/v2"
4445
)
4546

@@ -125,6 +126,7 @@ func runCmd(ctx *cli.Context) error {
125126
sender = common.BytesToAddress([]byte("sender"))
126127
receiver = common.BytesToAddress([]byte("receiver"))
127128
genesisConfig *core.Genesis
129+
preimages = ctx.Bool(DumpFlag.Name)
128130
)
129131
if ctx.Bool(MachineFlag.Name) {
130132
tracer = logger.NewJSONLogger(logconfig, os.Stdout)
@@ -139,10 +141,12 @@ func runCmd(ctx *cli.Context) error {
139141
genesisConfig = gen
140142
db := rawdb.NewMemoryDatabase()
141143
genesis := gen.MustCommit(db)
142-
statedb, _ = state.New(genesis.Root(), state.NewDatabase(db), nil)
144+
sdb := state.NewDatabaseWithConfig(db, &trie.Config{Preimages: preimages})
145+
statedb, _ = state.New(genesis.Root(), sdb, nil)
143146
chainConfig = gen.Config
144147
} else {
145-
statedb, _ = state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
148+
sdb := state.NewDatabaseWithConfig(rawdb.NewMemoryDatabase(), &trie.Config{Preimages: preimages})
149+
statedb, _ = state.New(common.Hash{}, sdb, nil)
146150
genesisConfig = new(core.Genesis)
147151
}
148152
if ctx.String(SenderFlag.Name) != "" {

tests/state_test_util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/ethereum/go-ethereum/ethdb"
3838
"github.com/ethereum/go-ethereum/params"
3939
"github.com/ethereum/go-ethereum/rlp"
40+
"github.com/ethereum/go-ethereum/trie"
4041
"golang.org/x/crypto/sha3"
4142
)
4243

@@ -284,7 +285,7 @@ func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
284285
}
285286

286287
func MakePreState(db ethdb.Database, accounts core.GenesisAlloc, snapshotter bool) (*snapshot.Tree, *state.StateDB) {
287-
sdb := state.NewDatabase(db)
288+
sdb := state.NewDatabaseWithConfig(db, &trie.Config{Preimages: true})
288289
statedb, _ := state.New(common.Hash{}, sdb, nil)
289290
for addr, a := range accounts {
290291
statedb.SetCode(addr, a.Code)

0 commit comments

Comments
 (0)