Skip to content

Commit

Permalink
Align blockchain.go trie metrics with coreth (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush authored Aug 29, 2023
1 parent 65a1f5a commit 71e9f76
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
blockStateInitTimer = metrics.NewRegisteredCounter("chain/block/inits/state", nil)
blockExecutionTimer = metrics.NewRegisteredCounter("chain/block/executions", nil)
blockTrieOpsTimer = metrics.NewRegisteredCounter("chain/block/trie", nil)
blockStateValidationTimer = metrics.NewRegisteredCounter("chain/block/validations/state", nil)
blockValidationTimer = metrics.NewRegisteredCounter("chain/block/validations/state", nil)
blockWriteTimer = metrics.NewRegisteredCounter("chain/block/writes", nil)

acceptorQueueGauge = metrics.NewRegisteredGauge("chain/acceptor/queue/size", nil)
Expand Down Expand Up @@ -1377,7 +1377,7 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
// If we have a followup block, run that against the current state to pre-cache
// transactions and probabilistically some of the account/storage trie nodes.
// Process block using the parent state as reference point
substart = time.Now()
pstart := time.Now()
receipts, logs, usedGas, err := bc.processor.Process(block, parent, statedb, bc.vmConfig)
if serr := statedb.Error(); serr != nil {
log.Error("statedb error encountered", "err", serr, "number", block.Number(), "hash", block.Hash())
Expand All @@ -1386,32 +1386,32 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
bc.reportBlock(block, receipts, err)
return err
}

// Update the metrics touched during block processing
accountReadTimer.Inc(statedb.AccountReads.Milliseconds()) // Account reads are complete, we can mark them
storageReadTimer.Inc(statedb.StorageReads.Milliseconds()) // Storage reads are complete, we can mark them
snapshotAccountReadTimer.Inc(statedb.SnapshotAccountReads.Milliseconds()) // Account reads are complete, we can mark them
snapshotStorageReadTimer.Inc(statedb.SnapshotStorageReads.Milliseconds()) // Storage reads are complete, we can mark them
trieproc := statedb.AccountHashes + statedb.StorageHashes // Save to not double count in validation
trieproc += statedb.SnapshotAccountReads + statedb.AccountReads + statedb.AccountUpdates
trieproc += statedb.SnapshotStorageReads + statedb.StorageReads + statedb.StorageUpdates
blockExecutionTimer.Inc((time.Since(substart) - trieproc).Milliseconds())
ptime := time.Since(pstart)

// Validate the state using the default validator
substart = time.Now()
vstart := time.Now()
if err := bc.validator.ValidateState(block, statedb, receipts, usedGas); err != nil {
bc.reportBlock(block, receipts, err)
return err
}

// Update the metrics touched during block validation
accountUpdateTimer.Inc(statedb.AccountUpdates.Milliseconds()) // Account updates are complete, we can mark them
storageUpdateTimer.Inc(statedb.StorageUpdates.Milliseconds()) // Storage updates are complete, we can mark them
accountHashTimer.Inc(statedb.AccountHashes.Milliseconds()) // Account hashes are complete, we can mark them
storageHashTimer.Inc(statedb.StorageHashes.Milliseconds()) // Storage hashes are complete, we can mark them
additionalTrieProc := statedb.AccountHashes + statedb.StorageHashes + statedb.AccountUpdates + statedb.StorageUpdates - trieproc
blockStateValidationTimer.Inc((time.Since(substart) - additionalTrieProc).Milliseconds())
blockTrieOpsTimer.Inc((trieproc + additionalTrieProc).Milliseconds())
vtime := time.Since(vstart)

// Update the metrics touched during block processing and validation
accountReadTimer.Inc(statedb.AccountReads.Milliseconds()) // Account reads are complete(in processing)
storageReadTimer.Inc(statedb.StorageReads.Milliseconds()) // Storage reads are complete(in processing)
snapshotAccountReadTimer.Inc(statedb.SnapshotAccountReads.Milliseconds()) // Account reads are complete(in processing)
snapshotStorageReadTimer.Inc(statedb.SnapshotStorageReads.Milliseconds()) // Storage reads are complete(in processing)
accountUpdateTimer.Inc(statedb.AccountUpdates.Milliseconds()) // Account updates are complete(in validation)
storageUpdateTimer.Inc(statedb.StorageUpdates.Milliseconds()) // Storage updates are complete(in validation)
accountHashTimer.Inc(statedb.AccountHashes.Milliseconds()) // Account hashes are complete(in validation)
storageHashTimer.Inc(statedb.StorageHashes.Milliseconds()) // Storage hashes are complete(in validation)
triehash := statedb.AccountHashes + statedb.StorageHashes // The time spent on tries hashing
trieUpdate := statedb.AccountUpdates + statedb.StorageUpdates // The time spent on tries update
trieRead := statedb.SnapshotAccountReads + statedb.AccountReads // The time spent on account read
trieRead += statedb.SnapshotStorageReads + statedb.StorageReads // The time spent on storage read
blockExecutionTimer.Inc((ptime - trieRead).Milliseconds()) // The time spent on EVM processing
blockValidationTimer.Inc((vtime - (triehash + trieUpdate)).Milliseconds()) // The time spent on block validation
blockTrieOpsTimer.Inc((triehash + trieUpdate + trieRead).Milliseconds()) // The time spent on trie operations

// If [writes] are disabled, skip [writeBlockWithState] so that we do not write the block
// or the state trie to disk.
Expand All @@ -1424,16 +1424,16 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
// writeBlockWithState (called within writeBlockAndSethead) creates a reference that
// will be cleaned up in Accept/Reject so we need to ensure an error cannot occur
// later in verification, since that would cause the referenced root to never be dereferenced.
substart = time.Now()
wstart := time.Now()
if err := bc.writeBlockAndSetHead(block, receipts, logs, statedb); err != nil {
return err
}
// Update the metrics touched during block commit
accountCommitTimer.Inc(statedb.AccountCommits.Milliseconds()) // Account commits are complete, we can mark them
storageCommitTimer.Inc(statedb.StorageCommits.Milliseconds()) // Storage commits are complete, we can mark them
snapshotCommitTimer.Inc(statedb.SnapshotCommits.Milliseconds()) // Snapshot commits are complete, we can mark them
triedbCommitTimer.Inc(statedb.TrieDBCommits.Milliseconds()) // Triedb commits are complete, we can mark them
blockWriteTimer.Inc((time.Since(substart) - statedb.AccountCommits - statedb.StorageCommits - statedb.SnapshotCommits - statedb.TrieDBCommits).Milliseconds())
triedbCommitTimer.Inc(statedb.TrieDBCommits.Milliseconds()) // Trie database commits are complete, we can mark them
blockWriteTimer.Inc((time.Since(wstart) - statedb.AccountCommits - statedb.StorageCommits - statedb.SnapshotCommits - statedb.TrieDBCommits).Milliseconds())
blockInsertTimer.Inc(time.Since(start).Milliseconds())

log.Debug("Inserted new block", "number", block.Number(), "hash", block.Hash(),
Expand Down

0 comments on commit 71e9f76

Please sign in to comment.