diff --git a/core/state/state_object.go b/core/state/state_object.go index 13b6f54c9e..a2db2f156e 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -223,13 +223,32 @@ func (s *StateObject) GetState(db Database, key common.Hash) common.Hash { hitInCache = true return value } - // Otherwise return the entry's original value - return s.GetCommittedState(db, key, &hitInCache) + return s.GetCommittedState(db, key, &hitInCache, true) } // GetCommittedState retrieves a value from the committed account storage trie. -func (s *StateObject) GetCommittedState(db Database, key common.Hash, hit *bool) common.Hash { +func (s *StateObject) GetCommittedState(db Database, key common.Hash, hit *bool, calledByGetState bool) common.Hash { + start := time.Now() + + defer func() { + if !calledByGetState { + routeid := cachemetrics.Goid() + isSyncMainProcess := cachemetrics.IsSyncMainRoutineID(routeid) + isMinerMainProcess := cachemetrics.IsMinerMainRoutineID(routeid) + if isSyncMainProcess && *hit { + cachemetrics.RecordCacheDepth("CACHE_L1_STORAGE") + cachemetrics.RecordCacheMetrics("CACHE_L1_STORAGE", start) + cachemetrics.RecordTotalCosts("CACHE_L1_STORAGE", start) + } + + if isMinerMainProcess && *hit { + cachemetrics.RecordMinerCacheDepth("MINER_L1_STORAGE") + cachemetrics.RecordMinerCacheMetrics("MINER_L1_STORAGE", start) + cachemetrics.RecordMinerTotalCosts("MINER_L1_STORAGE", start) + } + } + }() // If the fake storage is set, only lookup the state here(in the debugging mode) if s.fakeStorage != nil { return s.fakeStorage[key] diff --git a/core/state/statedb.go b/core/state/statedb.go index ee6b648379..59bcc94f2c 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -517,9 +517,10 @@ func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) commo defer s.markMetrics(start, needStorage) stateObject := s.getStateObject(addr) hit := false + if stateObject != nil { needStorage = true - return stateObject.GetCommittedState(s.db, hash, &hit) + return stateObject.GetCommittedState(s.db, hash, &hit, false) } return common.Hash{} }