@@ -28,7 +28,6 @@ import (
2828 "github.com/ethereum/go-ethereum/core/types"
2929 "github.com/ethereum/go-ethereum/crypto"
3030 "github.com/ethereum/go-ethereum/log"
31- "github.com/ethereum/go-ethereum/metrics"
3231 "github.com/ethereum/go-ethereum/params"
3332 "github.com/ethereum/go-ethereum/trie"
3433 "github.com/ethereum/go-ethereum/trie/trienode"
@@ -495,9 +494,8 @@ func (s *StateDB) GetTransientState(addr common.Address, key common.Hash) common
495494// updateStateObject writes the given object to the trie.
496495func (s * StateDB ) updateStateObject (obj * stateObject ) {
497496 // Track the amount of time wasted on updating the account from the trie
498- if metrics .EnabledExpensive {
499- defer func (start time.Time ) { s .AccountUpdates += time .Since (start ) }(time .Now ())
500- }
497+ defer func (start time.Time ) { s .AccountUpdates += time .Since (start ) }(time .Now ())
498+
501499 // Encode the account and update the account trie
502500 addr := obj .Address ()
503501 if err := s .trie .UpdateAccount (addr , & obj .data ); err != nil {
@@ -527,9 +525,8 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
527525// deleteStateObject removes the given object from the state trie.
528526func (s * StateDB ) deleteStateObject (obj * stateObject ) {
529527 // Track the amount of time wasted on deleting the account from the trie
530- if metrics .EnabledExpensive {
531- defer func (start time.Time ) { s .AccountUpdates += time .Since (start ) }(time .Now ())
532- }
528+ defer func (start time.Time ) { s .AccountUpdates += time .Since (start ) }(time .Now ())
529+
533530 // Delete the account from the trie
534531 addr := obj .Address ()
535532 if err := s .trie .DeleteAccount (addr ); err != nil {
@@ -561,9 +558,8 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
561558 if s .snap != nil {
562559 start := time .Now ()
563560 acc , err := s .snap .Account (crypto .HashData (s .hasher , addr .Bytes ()))
564- if metrics .EnabledExpensive {
565- s .SnapshotAccountReads += time .Since (start )
566- }
561+ s .SnapshotAccountReads += time .Since (start )
562+
567563 if err == nil {
568564 if acc == nil {
569565 return nil
@@ -587,9 +583,8 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
587583 start := time .Now ()
588584 var err error
589585 data , err = s .trie .GetAccount (addr )
590- if metrics .EnabledExpensive {
591- s .AccountReads += time .Since (start )
592- }
586+ s .AccountReads += time .Since (start )
587+
593588 if err != nil {
594589 s .setError (fmt .Errorf ("getDeleteStateObject (%x) error: %w" , addr .Bytes (), err ))
595590 return nil
@@ -917,9 +912,8 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
917912 s .stateObjectsPending = make (map [common.Address ]struct {})
918913 }
919914 // Track the amount of time wasted on hashing the account trie
920- if metrics .EnabledExpensive {
921- defer func (start time.Time ) { s .AccountHashes += time .Since (start ) }(time .Now ())
922- }
915+ defer func (start time.Time ) { s .AccountHashes += time .Since (start ) }(time .Now ())
916+
923917 return s .trie .Hash ()
924918}
925919
@@ -1042,16 +1036,16 @@ func (s *StateDB) deleteStorage(addr common.Address, addrHash common.Hash, root
10421036 if err != nil {
10431037 return nil , nil , err
10441038 }
1045- if metrics . EnabledExpensive {
1046- n := int64 (len (slots ))
1039+ // Report the metrics
1040+ n := int64 (len (slots ))
10471041
1048- slotDeletionMaxCount .UpdateIfGt (int64 (len (slots )))
1049- slotDeletionMaxSize .UpdateIfGt (int64 (size ))
1042+ slotDeletionMaxCount .UpdateIfGt (int64 (len (slots )))
1043+ slotDeletionMaxSize .UpdateIfGt (int64 (size ))
1044+
1045+ slotDeletionTimer .UpdateSince (start )
1046+ slotDeletionCount .Mark (n )
1047+ slotDeletionSize .Mark (int64 (size ))
10501048
1051- slotDeletionTimer .UpdateSince (start )
1052- slotDeletionCount .Mark (n )
1053- slotDeletionSize .Mark (int64 (size ))
1054- }
10551049 return slots , nodes , nil
10561050}
10571051
@@ -1190,10 +1184,8 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
11901184 }
11911185 }
11921186 // Write the account trie changes, measuring the amount of wasted time
1193- var start time.Time
1194- if metrics .EnabledExpensive {
1195- start = time .Now ()
1196- }
1187+ start := time .Now ()
1188+
11971189 root , set , err := s .trie .Commit (true )
11981190 if err != nil {
11991191 return common.Hash {}, err
@@ -1205,23 +1197,23 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
12051197 }
12061198 accountTrieNodesUpdated , accountTrieNodesDeleted = set .Size ()
12071199 }
1208- if metrics .EnabledExpensive {
1209- s .AccountCommits += time .Since (start )
1200+ // Report the commit metrics
1201+ s .AccountCommits += time .Since (start )
1202+
1203+ accountUpdatedMeter .Mark (int64 (s .AccountUpdated ))
1204+ storageUpdatedMeter .Mark (int64 (s .StorageUpdated ))
1205+ accountDeletedMeter .Mark (int64 (s .AccountDeleted ))
1206+ storageDeletedMeter .Mark (int64 (s .StorageDeleted ))
1207+ accountTrieUpdatedMeter .Mark (int64 (accountTrieNodesUpdated ))
1208+ accountTrieDeletedMeter .Mark (int64 (accountTrieNodesDeleted ))
1209+ storageTriesUpdatedMeter .Mark (int64 (storageTrieNodesUpdated ))
1210+ storageTriesDeletedMeter .Mark (int64 (storageTrieNodesDeleted ))
1211+ s .AccountUpdated , s .AccountDeleted = 0 , 0
1212+ s .StorageUpdated , s .StorageDeleted = 0 , 0
12101213
1211- accountUpdatedMeter .Mark (int64 (s .AccountUpdated ))
1212- storageUpdatedMeter .Mark (int64 (s .StorageUpdated ))
1213- accountDeletedMeter .Mark (int64 (s .AccountDeleted ))
1214- storageDeletedMeter .Mark (int64 (s .StorageDeleted ))
1215- accountTrieUpdatedMeter .Mark (int64 (accountTrieNodesUpdated ))
1216- accountTrieDeletedMeter .Mark (int64 (accountTrieNodesDeleted ))
1217- storageTriesUpdatedMeter .Mark (int64 (storageTrieNodesUpdated ))
1218- storageTriesDeletedMeter .Mark (int64 (storageTrieNodesDeleted ))
1219- s .AccountUpdated , s .AccountDeleted = 0 , 0
1220- s .StorageUpdated , s .StorageDeleted = 0 , 0
1221- }
12221214 // If snapshotting is enabled, update the snapshot tree with this new version
12231215 if s .snap != nil {
1224- start : = time .Now ()
1216+ start = time .Now ()
12251217 // Only update if there's a state transition (skip empty Clique blocks)
12261218 if parent := s .snap .Root (); parent != root {
12271219 if err := s .snaps .Update (root , parent , s .convertAccountSet (s .stateObjectsDestruct ), s .accounts , s .storages ); err != nil {
@@ -1235,9 +1227,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
12351227 log .Warn ("Failed to cap snapshot tree" , "root" , root , "layers" , 128 , "err" , err )
12361228 }
12371229 }
1238- if metrics .EnabledExpensive {
1239- s .SnapshotCommits += time .Since (start )
1240- }
1230+ s .SnapshotCommits += time .Since (start )
12411231 s .snap = nil
12421232 }
12431233 if root == (common.Hash {}) {
@@ -1248,15 +1238,14 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
12481238 origin = types .EmptyRootHash
12491239 }
12501240 if root != origin {
1251- start : = time .Now ()
1241+ start = time .Now ()
12521242 set := triestate .New (s .accountsOrigin , s .storagesOrigin )
12531243 if err := s .db .TrieDB ().Update (root , origin , block , nodes , set ); err != nil {
12541244 return common.Hash {}, err
12551245 }
12561246 s .originalRoot = root
1257- if metrics .EnabledExpensive {
1258- s .TrieDBCommits += time .Since (start )
1259- }
1247+ s .TrieDBCommits += time .Since (start )
1248+
12601249 if s .onCommit != nil {
12611250 s .onCommit (set )
12621251 }
0 commit comments