diff --git a/core/state/reader.go b/core/state/reader.go index 4d1530805d..35b732173b 100644 --- a/core/state/reader.go +++ b/core/state/reader.go @@ -201,7 +201,6 @@ func (r *cachingCodeReader) Code(addr common.Address, codeHash common.Hash) ([]b func (r *cachingCodeReader) CodeSize(addr common.Address, codeHash common.Hash) (int, error) { if cached, ok := r.codeSizeCache.Get(codeHash); ok { r.hit.Add(1) - r.hitBytes.Add(int64(cached)) return cached, nil } code, err := r.Code(addr, codeHash) diff --git a/core/state/state_object.go b/core/state/state_object.go index 3b4238b37b..2873c3cb8a 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -568,7 +568,6 @@ func (s *stateObject) CodeSize() int { defer func(start time.Time) { s.db.CodeLoaded += 1 s.db.CodeReads += time.Since(start) - s.db.CodeLoadBytes += len(s.code) }(time.Now()) size, err := s.db.reader.CodeSize(s.address, common.BytesToHash(s.CodeHash())) diff --git a/core/state/statedb.go b/core/state/statedb.go index a2c9866875..610e7173cf 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -159,7 +159,12 @@ type StateDB struct { StorageUpdated atomic.Int64 // Number of storage slots updated during the state transition StorageDeleted atomic.Int64 // Number of storage slots deleted during the state transition CodeLoaded int // Number of contract code loaded during the state transition - CodeLoadBytes int // Total number of bytes read from contract code + + // CodeLoadBytes is the total number of bytes read from contract code. + // This value may be smaller than the actual number of bytes read, since + // some APIs (e.g. CodeSize) may load the entire code from either the + // cache or the database when the size is not available in the cache. + CodeLoadBytes int } // New creates a new state from a given trie.