cmd/evm/t8ntool: add error handling for Commit and state reopening

Previously, both statedb.Commit() and the subsequent state.New() were
ignoring returned errors. This could lead to silent failures where:
1. The commit operation fails but execution continues
2. State reopening fails after a successful commit

Both scenarios can cause difficult-to-debug issues, especially in testing
scenarios where state consistency is critical.

This change adds proper error checking for both operations, ensuring that
any failures are caught immediately with descriptive error messages.

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:
CPerezz 2025-09-29 12:24:28 +02:00
parent 5e6f04c774
commit eb99acbb35
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -387,8 +387,14 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB
}
}
// Commit and re-open to start with a clean state.
root, _ := statedb.Commit(0, false, false)
statedb, _ = state.New(root, sdb)
root, err := statedb.Commit(0, false, false)
if err != nil {
panic(fmt.Errorf("failed to commit initial state: %v", err))
}
statedb, err = state.New(root, sdb)
if err != nil {
panic(fmt.Errorf("failed to reopen state after commit: %v", err))
}
return statedb
}