core/state: simplify meter code #24304 (#1208)

This commit is contained in:
Daniel Liu 2025-07-11 10:15:16 +08:00 committed by GitHub
parent 906f07736e
commit 495a8b919a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -201,9 +201,10 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
return value
}
// Track the amount of time wasted on reading the storage trie
defer func(start time.Time) { s.db.StorageReads += time.Since(start) }(time.Now())
start := time.Now()
// Otherwise load the value from the database
enc, err := s.getTrie(db).TryGet(key[:])
enc, err := s.getTrie(db).TryGet(key.Bytes())
s.db.StorageReads += time.Since(start)
if err != nil {
s.setError(err)
return common.Hash{}

View file

@ -526,10 +526,14 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
return obj
}
// Track the amount of time wasted on loading the object from the database
defer func(start time.Time) { s.AccountReads += time.Since(start) }(time.Now())
start := time.Now()
// Load the object from the database
enc, err := s.trie.TryGet(addr[:])
enc, err := s.trie.TryGet(addr.Bytes())
s.AccountReads += time.Since(start)
if err != nil {
s.setError(fmt.Errorf("getDeleteStateObject (%x) error: %v", addr.Bytes(), err))
return nil
}
if len(enc) == 0 {
s.setError(err)
return nil