Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/state/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (it *NodeIterator) step() error {
if !it.dataIt.Next(true) {
it.dataIt = nil
}
if !bytes.Equal(account.CodeHash, emptyCodeHash) {
if !bytes.Equal(account.CodeHash, types.EmptyCodeHash.Bytes()) {
it.codeHash = common.BytesToHash(account.CodeHash)
//it.code, err = it.state.db.ContractCode(common.BytesToAddress(it.stateIt.LeafKey()), common.BytesToHash(account.CodeHash))
it.code, err = it.state.db.ContractCode(address, common.BytesToHash(account.CodeHash))
Expand Down
11 changes: 5 additions & 6 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/CortexFoundation/CortexTheseus/rlp"
)

var emptyCodeHash = crypto.Keccak256(nil)
var big0 = big.NewInt(0)

type Code []byte
Expand Down Expand Up @@ -97,7 +96,7 @@ type stateObject struct {

// empty returns whether the account is considered empty.
func (s *stateObject) empty() bool {
return s.data.Nonce == 0 && s.data.Balance.Sign() == 0 && bytes.Equal(s.data.CodeHash, emptyCodeHash) && s.data.Upload.Sign() == 0 && s.data.Num.Sign() == 0
return s.data.Nonce == 0 && s.data.Balance.Sign() == 0 && bytes.Equal(s.data.CodeHash, types.EmptyCodeHash.Bytes()) && s.data.Upload.Sign() == 0 && s.data.Num.Sign() == 0
}

// newObject creates a state object.
Expand Down Expand Up @@ -150,7 +149,7 @@ func (s *stateObject) getTrie(db Database) Trie {
if s.trie == nil {
// Try fetching from prefetcher first
// We don't prefetch empty tries
if s.data.Root != emptyRoot && s.db.prefetcher != nil {
if s.data.Root != types.EmptyRootHash && s.db.prefetcher != nil {
// When the miner is creating the pending state, there is no
// prefetcher
s.trie = s.db.prefetcher.trie(s.data.Root)
Expand Down Expand Up @@ -264,7 +263,7 @@ func (s *stateObject) finalise(prefetch bool) {
slotsToPrefetch = append(slotsToPrefetch, common.CopyBytes(key[:])) // Copy needed for closure
}
}
if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != emptyRoot {
if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != types.EmptyRootHash {
s.db.prefetcher.prefetch(s.data.Root, slotsToPrefetch)
}
if len(s.dirtyStorage) > 0 {
Expand Down Expand Up @@ -508,7 +507,7 @@ func (s *stateObject) Code(db Database) []byte {
if s.code != nil {
return s.code
}
if bytes.Equal(s.CodeHash(), emptyCodeHash) {
if bytes.Equal(s.CodeHash(), types.EmptyCodeHash.Bytes()) {
return nil
}
code, err := db.ContractCode(s.address, common.BytesToHash(s.CodeHash()))
Expand All @@ -526,7 +525,7 @@ func (s *stateObject) CodeSize(db Database) int {
if s.code != nil {
return len(s.code)
}
if bytes.Equal(s.CodeHash(), emptyCodeHash) {
if bytes.Equal(s.CodeHash(), types.EmptyCodeHash.Bytes()) {
return 0
}
size, err := db.ContractCodeSize(s.address, common.BytesToHash(s.CodeHash()))
Expand Down
15 changes: 3 additions & 12 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ type revision struct {
journalIndex int
}

var (
// emptyState is the known hash of an empty state trie entry.
//emptyState = crypto.Keccak256Hash(nil)
emptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")

// emptyCode is the known hash of the empty CVM bytecode.
emptyCode = crypto.Keccak256Hash(nil)
)

type proofList [][]byte

func (n *proofList) Put(key []byte, value []byte) error {
Expand Down Expand Up @@ -713,10 +704,10 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
Num: acc.Num,
}
if len(data.CodeHash) == 0 {
data.CodeHash = emptyCodeHash
data.CodeHash = types.EmptyCodeHash.Bytes()
}
if data.Root == (common.Hash{}) {
data.Root = emptyRoot
data.Root = types.EmptyRootHash
}
}
}
Expand Down Expand Up @@ -1172,7 +1163,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
if err := rlp.DecodeBytes(leaf, &account); err != nil {
return nil
}
if account.Root != emptyRoot {
if account.Root != types.EmptyRootHash {
s.db.TrieDB().Reference(account.Root, parent)
}
return nil
Expand Down