Skip to content

Commit

Permalink
fix GetCommittedState L1 storage metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Mar 2, 2022
1 parent 5381bc9 commit 6bf825a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
25 changes: 22 additions & 3 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down

0 comments on commit 6bf825a

Please sign in to comment.