Skip to content

Commit

Permalink
fix code hash issue after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Sep 26, 2024
1 parent f8f5dc4 commit 8c429ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/state/parallel_statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down
7 changes: 3 additions & 4 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import (
"github.com/holiman/uint256"
)

var emptyCodeHash = crypto.Keccak256(nil)

type Code []byte

func (c Code) String() string {
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down

0 comments on commit 8c429ad

Please sign in to comment.