Skip to content

Commit 4253030

Browse files
authored
core/state: move metrics out of state objects (#29665)
1 parent 8d42e11 commit 4253030

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

core/blockchain.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ var (
6868
accountCommitTimer = metrics.NewRegisteredResettingTimer("chain/account/commits", nil)
6969

7070
storageReadTimer = metrics.NewRegisteredResettingTimer("chain/storage/reads", nil)
71-
storageHashTimer = metrics.NewRegisteredResettingTimer("chain/storage/hashes", nil)
7271
storageUpdateTimer = metrics.NewRegisteredResettingTimer("chain/storage/updates", nil)
7372
storageCommitTimer = metrics.NewRegisteredResettingTimer("chain/storage/commits", nil)
7473

@@ -1937,8 +1936,7 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
19371936
accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete(in validation)
19381937
storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete(in validation)
19391938
accountHashTimer.Update(statedb.AccountHashes) // Account hashes are complete(in validation)
1940-
storageHashTimer.Update(statedb.StorageHashes) // Storage hashes are complete(in validation)
1941-
triehash := statedb.AccountHashes + statedb.StorageHashes // The time spent on tries hashing
1939+
triehash := statedb.AccountHashes // The time spent on tries hashing
19421940
trieUpdate := statedb.AccountUpdates + statedb.StorageUpdates // The time spent on tries update
19431941
trieRead := statedb.SnapshotAccountReads + statedb.AccountReads // The time spent on account read
19441942
trieRead += statedb.SnapshotStorageReads + statedb.StorageReads // The time spent on storage read

core/state/state_object.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ func (s *stateObject) updateTrie() (Trie, error) {
294294
if len(s.pendingStorage) == 0 {
295295
return s.trie, nil
296296
}
297-
// Track the amount of time wasted on updating the storage trie
298-
defer func(start time.Time) { s.db.StorageUpdates += time.Since(start) }(time.Now())
299-
300297
// The snapshot storage map for the object
301298
var (
302299
storage map[common.Hash][]byte
@@ -400,9 +397,6 @@ func (s *stateObject) updateRoot() {
400397
if err != nil || tr == nil {
401398
return
402399
}
403-
// Track the amount of time wasted on hashing the storage trie
404-
defer func(start time.Time) { s.db.StorageHashes += time.Since(start) }(time.Now())
405-
406400
s.data.Root = tr.Hash()
407401
}
408402

@@ -415,9 +409,6 @@ func (s *stateObject) commit() (*trienode.NodeSet, error) {
415409
s.origin = s.data.Copy()
416410
return nil, nil
417411
}
418-
// Track the amount of time wasted on committing the storage trie
419-
defer func(start time.Time) { s.db.StorageCommits += time.Since(start) }(time.Now())
420-
421412
// The trie is currently in an open state and could potentially contain
422413
// cached mutations. Call commit to acquire a set of nodes that have been
423414
// modified, the set can be nil if nothing to commit.

core/state/statedb.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ type StateDB struct {
151151
AccountUpdates time.Duration
152152
AccountCommits time.Duration
153153
StorageReads time.Duration
154-
StorageHashes time.Duration
155154
StorageUpdates time.Duration
156155
StorageCommits time.Duration
157156
SnapshotAccountReads time.Duration
@@ -856,6 +855,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
856855
// the account prefetcher. Instead, let's process all the storage updates
857856
// first, giving the account prefetches just a few more milliseconds of time
858857
// to pull useful data from disk.
858+
start := time.Now()
859859
for addr, op := range s.mutations {
860860
if op.applied {
861861
continue
@@ -865,6 +865,8 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
865865
}
866866
s.stateObjects[addr].updateRoot()
867867
}
868+
s.StorageUpdates += time.Since(start)
869+
868870
// Now we're about to start to write changes to the trie. The trie is so far
869871
// _untouched_. We can check with the prefetcher, if it can give us a trie
870872
// which has the same root, but also has some content loaded into it.
@@ -1151,6 +1153,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
11511153
return common.Hash{}, err
11521154
}
11531155
// Handle all state updates afterwards
1156+
start := time.Now()
11541157
for addr, op := range s.mutations {
11551158
if op.isDelete() {
11561159
continue
@@ -1179,13 +1182,15 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
11791182
storageTrieNodesDeleted += deleted
11801183
}
11811184
}
1185+
s.StorageCommits += time.Since(start)
1186+
11821187
if codeWriter.ValueSize() > 0 {
11831188
if err := codeWriter.Write(); err != nil {
11841189
log.Crit("Failed to commit dirty codes", "error", err)
11851190
}
11861191
}
11871192
// Write the account trie changes, measuring the amount of wasted time
1188-
start := time.Now()
1193+
start = time.Now()
11891194

11901195
root, set, err := s.trie.Commit(true)
11911196
if err != nil {

0 commit comments

Comments
 (0)