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
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
@ -294,9 +295,12 @@ func (s *StateDB) GetCodeSize(addr common.Address) int {
|
|||||||
if stateObject.code != nil {
|
if stateObject.code != nil {
|
||||||
return len(stateObject.code)
|
return len(stateObject.code)
|
||||||
}
|
}
|
||||||
|
if bytes.Equal(stateObject.CodeHash(), emptyCode[:]) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
size, err := s.db.ContractCodeSize(stateObject.addrHash, common.BytesToHash(stateObject.CodeHash()))
|
size, err := s.db.ContractCodeSize(stateObject.addrHash, common.BytesToHash(stateObject.CodeHash()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(err)
|
s.setError(fmt.Errorf("GetCodeSize (%x) error: %v", addr[:], err))
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
@ -465,7 +469,9 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("can't encode object at %x: %v", addr[:], err))
|
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
|
// If state snapshotting is active, cache the data til commit. Note, this
|
||||||
// update mechanism is not symmetric to the deletion, because whereas it is
|
// 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
|
// Delete the account from the trie
|
||||||
addr := obj.Address()
|
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
|
// 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())
|
defer func(start time.Time) { s.AccountReads += time.Since(start) }(time.Now())
|
||||||
}
|
}
|
||||||
enc, err := s.trie.TryGet(addr[:])
|
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 {
|
if len(enc) == 0 {
|
||||||
s.setError(err)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := rlp.DecodeBytes(enc, &data); err != nil {
|
if err := rlp.DecodeBytes(enc, &data); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user