Skip to content

Commit

Permalink
state/stateobject: add read/write/access meters;
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbundler committed Nov 10, 2023
1 parent a45c0a9 commit c1dabea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ func (s *stateObject) updateTrie() (Trie, error) {
s.db.setError(fmt.Errorf("state object update trie getTrie err, contract: %v, err: %v", s.address, err))
return nil, err
}
storageReadMeter.Mark(int64(len(s.originStorage)))
storageWriteMeter.Mark(int64(len(s.pendingStorage)))
// Insert all the pending updates into the trie
usedStorage := make([][]byte, 0, len(s.pendingStorage))
dirtyStorage := make(map[common.Hash][]byte)
Expand All @@ -448,16 +450,28 @@ func (s *stateObject) updateTrie() (Trie, error) {
}

if s.db.EnableExpire() {
var accessCount int64
// append more access slots to update in db
for key := range s.pendingAccessedState {
if _, ok := dirtyStorage[key]; ok {
continue
}
accessCount++
// it must hit in cache
value := s.GetState(key)
dirtyStorage[key] = common.TrimLeftZeroes(value[:])
//log.Debug("updateTrie access state", "contract", s.address, "key", key, "epoch", s.db.Epoch())
}
for key := range s.pendingFutureReviveState {
if _, ok := dirtyStorage[key]; ok {
continue
}
if _, ok := s.pendingAccessedState[key]; ok {
continue
}
accessCount++
}
storageAccessMeter.Mark(accessCount)
}

var wg sync.WaitGroup
Expand Down
3 changes: 3 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ var (
getCommittedStorageExpiredLocalReviveMeter = metrics.NewRegisteredMeter("state/contract/committed/expired/localrevive", nil)
getCommittedStorageUnexpiredMeter = metrics.NewRegisteredMeter("state/contract/committed/unexpired", nil)
getCommittedStorageRemoteMeter = metrics.NewRegisteredMeter("state/contract/committed/remote", nil)
storageReadMeter = metrics.NewRegisteredMeter("state/contract/state/read", nil)
storageWriteMeter = metrics.NewRegisteredMeter("state/contract/state/write", nil)
storageAccessMeter = metrics.NewRegisteredMeter("state/contract/state/access", nil)
)

type revision struct {
Expand Down

0 comments on commit c1dabea

Please sign in to comment.