Skip to content

Commit 46b7e78

Browse files
authored
cmd/evm/internal/t8ntool: panic on database corruption (#32776)
These functions were previously ignoring the error returned by both `statedb.Commit()` and the subsequent `state.New()`, which could silently fail and cause panics later when the `statedb` is used. This change adds proper error checking and panics with a descriptive error message if state creation fails. While unlikely in normal operation, this can occur if there are database corruption issues or if invalid root hashes are provided, making debugging significantly easier when such issues do occur. This issue was encountered and fixed in gballet#552 where the error handling proved essential for debugging cc: @gballet as this was discussed in a call already.
1 parent 4b08020 commit 46b7e78

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
374374
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB {
375375
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true})
376376
sdb := state.NewDatabase(tdb, nil)
377-
statedb, _ := state.New(types.EmptyRootHash, sdb)
377+
statedb, err := state.New(types.EmptyRootHash, sdb)
378+
if err != nil {
379+
panic(fmt.Errorf("failed to create initial state: %v", err))
380+
}
378381
for addr, a := range accounts {
379382
statedb.SetCode(addr, a.Code, tracing.CodeChangeUnspecified)
380383
statedb.SetNonce(addr, a.Nonce, tracing.NonceChangeGenesis)
@@ -384,8 +387,14 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB
384387
}
385388
}
386389
// Commit and re-open to start with a clean state.
387-
root, _ := statedb.Commit(0, false, false)
388-
statedb, _ = state.New(root, sdb)
390+
root, err := statedb.Commit(0, false, false)
391+
if err != nil {
392+
panic(fmt.Errorf("failed to commit initial state: %v", err))
393+
}
394+
statedb, err = state.New(root, sdb)
395+
if err != nil {
396+
panic(fmt.Errorf("failed to reopen state after commit: %v", err))
397+
}
389398
return statedb
390399
}
391400

0 commit comments

Comments
 (0)