diff --git a/core/state/parallel_statedb.go b/core/state/parallel_statedb.go index 4aff3ce5ea..a0da320361 100644 --- a/core/state/parallel_statedb.go +++ b/core/state/parallel_statedb.go @@ -464,7 +464,7 @@ func (s *ParallelStateDB) Empty(addr common.Address) bool { return false } codeHash := s.GetCodeHash(addr) - return bytes.Equal(codeHash.Bytes(), emptyCodeHash) // code is empty, the object is empty + return bytes.Equal(codeHash.Bytes(), types.EmptyCodeHash.Bytes()) // code is empty, the object is empty } // 2.Try to get from unconfirmed & main DB // 2.1 Already read before @@ -725,7 +725,7 @@ func (s *ParallelStateDB) GetCodeHash(addr common.Address) common.Hash { // wrong 'empty' hash. if dirtyObj != nil { // found one - if dirtyObj.CodeHash() == nil || bytes.Equal(dirtyObj.CodeHash(), emptyCodeHash) { + if dirtyObj.CodeHash() == nil || bytes.Equal(dirtyObj.CodeHash(), types.EmptyCodeHash.Bytes()) { dirtyObj.data.CodeHash = codeHash.Bytes() } } diff --git a/core/state/state_object.go b/core/state/state_object.go index 0c2d326799..1b5059140d 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -35,8 +35,6 @@ import ( "github.com/holiman/uint256" ) -var emptyCodeHash = crypto.Keccak256(nil) - type Code []byte func (c Code) String() string { @@ -230,14 +228,15 @@ func (s *stateObject) empty() bool { // Slot 1 tx 1: sub balance 100, it is empty and deleted // Slot 0 tx 2: GetNonce, lightCopy based on main DB(balance = 100) , not empty - if s.dbItf.GetBalance(s.address).Sign() != 0 { // check balance first, since it is most likely not zero + if !s.dbItf.GetBalance(s.address).IsZero() { // check balance first, since it is most likely not zero + return false } if s.dbItf.GetNonce(s.address) != 0 { return false } codeHash := s.dbItf.GetCodeHash(s.address) - return bytes.Equal(codeHash.Bytes(), emptyCodeHash) // code is empty, the object is empty + return bytes.Equal(codeHash.Bytes(), types.EmptyCodeHash.Bytes()) // code is empty, the object is empty } // newObject creates a state object. diff --git a/core/state/statedb.go b/core/state/statedb.go index 3a45fde021..71491e587f 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -563,8 +563,8 @@ func (s *StateDB) GetCodeHash(addr common.Address) (ret common.Hash) { s.RecordRead(types.AccountStateKey(addr, types.AccountCodeHash), ret.Bytes()) }() stateObject := s.getStateObject(addr) - if stateObject == nil { - return common.Hash{} + if stateObject != nil { + return common.BytesToHash(stateObject.CodeHash()) } return common.Hash{} }