Skip to content

Commit

Permalink
Merge pull request bnb-chain#8 from flywukong/IO-metrics
Browse files Browse the repository at this point in the history
fix GetCommittedState L1 storage metrics
  • Loading branch information
forcodedancing committed Mar 2, 2022
2 parents f14d2ed + 6bf825a commit 2a9f865
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 2a9f865

Please sign in to comment.