core/state: fix

This commit is contained in:
Gary Rong 2026-01-22 11:10:10 +08:00
parent db6f23d1e0
commit a97c08dedb
3 changed files with 6 additions and 3 deletions

View file

@ -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)

View file

@ -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()))

View file

@ -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.