From 495a8b919aaf93b574430e7db701cadf34fdb124 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 11 Jul 2025 10:15:16 +0800 Subject: [PATCH] core/state: simplify meter code #24304 (#1208) --- core/state/state_object.go | 5 +++-- core/state/statedb.go | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index 40714908ed..1fcda94546 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -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{} diff --git a/core/state/statedb.go b/core/state/statedb.go index ea238d69be..b710c99278 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -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