mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
cmd/evm/t8ntool: add error handling for state.New() in MakePreState
The function was previously ignoring the error returned by 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 https://github.com/gballet/go-ethereum/pull/552 where the error handling proved essential for debugging.
This commit is contained in:
parent
265db06242
commit
5e6f04c774
1 changed files with 4 additions and 1 deletions
|
|
@ -374,7 +374,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
|||
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB {
|
||||
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true})
|
||||
sdb := state.NewDatabase(tdb, nil)
|
||||
statedb, _ := state.New(types.EmptyRootHash, sdb)
|
||||
statedb, err := state.New(types.EmptyRootHash, sdb)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to create initial state: %v", err))
|
||||
}
|
||||
for addr, a := range accounts {
|
||||
statedb.SetCode(addr, a.Code, tracing.CodeChangeUnspecified)
|
||||
statedb.SetNonce(addr, a.Nonce, tracing.NonceChangeGenesis)
|
||||
|
|
|
|||
Loading…
Reference in a new issue