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:
Martin Holst Swende 2020-05-08 20:52:20 +02:00 committed by GitHub
parent b0b65d017f
commit 82f9ed49fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -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 {