mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 03:30:35 +00:00
core/state: avoid statedb.dbErr due to emptyCode (#21051)
* core/state: more verbose stateb errors * core/state: fix flaw * core/state: fixed lint Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
This commit is contained in:
parent
b0b65d017f
commit
82f9ed49fa
@ -18,6 +18,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
@ -294,9 +295,12 @@ func (s *StateDB) GetCodeSize(addr common.Address) int {
|
||||
if stateObject.code != nil {
|
||||
return len(stateObject.code)
|
||||
}
|
||||
if bytes.Equal(stateObject.CodeHash(), emptyCode[:]) {
|
||||
return 0
|
||||
}
|
||||
size, err := s.db.ContractCodeSize(stateObject.addrHash, common.BytesToHash(stateObject.CodeHash()))
|
||||
if err != nil {
|
||||
s.setError(err)
|
||||
s.setError(fmt.Errorf("GetCodeSize (%x) error: %v", addr[:], err))
|
||||
}
|
||||
return size
|
||||
}
|
||||
@ -465,7 +469,9 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("can't encode object at %x: %v", addr[:], err))
|
||||
}
|
||||
s.setError(s.trie.TryUpdate(addr[:], data))
|
||||
if err = s.trie.TryUpdate(addr[:], data); err != nil {
|
||||
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
|
||||
}
|
||||
|
||||
// If state snapshotting is active, cache the data til commit. Note, this
|
||||
// update mechanism is not symmetric to the deletion, because whereas it is
|
||||
@ -484,7 +490,9 @@ func (s *StateDB) deleteStateObject(obj *stateObject) {
|
||||
}
|
||||
// Delete the account from the trie
|
||||
addr := obj.Address()
|
||||
s.setError(s.trie.TryDelete(addr[:]))
|
||||
if err := s.trie.TryDelete(addr[:]); err != nil {
|
||||
s.setError(fmt.Errorf("deleteStateObject (%x) error: %v", addr[:], err))
|
||||
}
|
||||
}
|
||||
|
||||
// getStateObject retrieves a state object given by the address, returning nil if
|
||||
@ -536,8 +544,11 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
|
||||
defer func(start time.Time) { s.AccountReads += time.Since(start) }(time.Now())
|
||||
}
|
||||
enc, err := s.trie.TryGet(addr[:])
|
||||
if err != nil {
|
||||
s.setError(fmt.Errorf("getDeleteStateObject (%x) error: %v", addr[:], err))
|
||||
return nil
|
||||
}
|
||||
if len(enc) == 0 {
|
||||
s.setError(err)
|
||||
return nil
|
||||
}
|
||||
if err := rlp.DecodeBytes(enc, &data); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user