core/state: avoid empty codehash allocs and needless storage trie opens

This commit is contained in:
Forostovec 2026-01-26 13:11:57 +02:00 committed by GitHub
parent 8aa18640a0
commit 685039a7dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -90,7 +90,7 @@ type stateObject struct {
// empty returns whether the account is considered empty. // empty returns whether the account is considered empty.
func (s *stateObject) empty() bool { func (s *stateObject) empty() bool {
return s.data.Nonce == 0 && s.data.Balance.IsZero() && bytes.Equal(s.data.CodeHash, types.EmptyCodeHash.Bytes()) return s.data.Nonce == 0 && s.data.Balance.IsZero() && bytes.Equal(s.data.CodeHash, types.EmptyCodeHash[:])
} }
// newObject creates a state object. // newObject creates a state object.
@ -535,7 +535,7 @@ func (s *stateObject) Code() []byte {
if len(s.code) != 0 { if len(s.code) != 0 {
return s.code return s.code
} }
if bytes.Equal(s.CodeHash(), types.EmptyCodeHash.Bytes()) { if bytes.Equal(s.CodeHash(), types.EmptyCodeHash[:]) {
return nil return nil
} }
defer func(start time.Time) { defer func(start time.Time) {
@ -562,7 +562,7 @@ func (s *stateObject) CodeSize() int {
if len(s.code) != 0 { if len(s.code) != 0 {
return len(s.code) return len(s.code)
} }
if bytes.Equal(s.CodeHash(), types.EmptyCodeHash.Bytes()) { if bytes.Equal(s.CodeHash(), types.EmptyCodeHash[:]) {
return 0 return 0
} }
defer func(start time.Time) { defer func(start time.Time) {