mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 09:50:45 +00:00
When a database failure occurs, bubble it up a into statedb, and report it in suitable places, such as during a 'bad block' report. Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
This commit is contained in:
parent
cb888541c5
commit
1d9fd6bdd2
3 changed files with 6 additions and 7 deletions
|
|
@ -103,7 +103,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
|
||||||
// Validate the state root against the received state root and throw
|
// Validate the state root against the received state root and throw
|
||||||
// an error if they don't match.
|
// an error if they don't match.
|
||||||
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
|
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
|
||||||
return fmt.Errorf("invalid merkle root (remote: %x local: %x)", header.Root, root)
|
return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,10 @@ type StateDB struct {
|
||||||
// DB error.
|
// DB error.
|
||||||
// State objects are used by the consensus core and VM which are
|
// State objects are used by the consensus core and VM which are
|
||||||
// unable to deal with database-level errors. Any error that occurs
|
// unable to deal with database-level errors. Any error that occurs
|
||||||
// during a database read is memoized here and will eventually be returned
|
// during a database read is memoized here and will eventually be
|
||||||
// by StateDB.Commit.
|
// returned by StateDB.Commit. Notably, this error is also shared
|
||||||
|
// by all cached state objects in case the database failure occurs
|
||||||
|
// when accessing state of accounts.
|
||||||
dbErr error
|
dbErr error
|
||||||
|
|
||||||
// The refund counter, also used by state transitioning.
|
// The refund counter, also used by state transitioning.
|
||||||
|
|
@ -134,6 +136,7 @@ func (s *StateDB) setError(err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error returns the memorized database failure occurred earlier.
|
||||||
func (s *StateDB) Error() error {
|
func (s *StateDB) Error() error {
|
||||||
return s.dbErr
|
return s.dbErr
|
||||||
}
|
}
|
||||||
|
|
@ -459,13 +462,11 @@ func (s *StateDB) SetTransientState(addr common.Address, key, value common.Hash)
|
||||||
if prev == value {
|
if prev == value {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.journal.append(transientStorageChange{
|
s.journal.append(transientStorageChange{
|
||||||
account: &addr,
|
account: &addr,
|
||||||
key: key,
|
key: key,
|
||||||
prevalue: prev,
|
prevalue: prev,
|
||||||
})
|
})
|
||||||
|
|
||||||
s.setTransientState(addr, key, value)
|
s.setTransientState(addr, key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,6 @@ type StateDB interface {
|
||||||
|
|
||||||
AddLog(*types.Log)
|
AddLog(*types.Log)
|
||||||
AddPreimage(common.Hash, []byte)
|
AddPreimage(common.Hash, []byte)
|
||||||
|
|
||||||
ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallContext provides a basic interface for the EVM calling conventions. The EVM
|
// CallContext provides a basic interface for the EVM calling conventions. The EVM
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue