mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-30 09:38:24 -05:00
feat: add canonicalization latency metric (#3865)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use reth_metrics::{
|
||||
metrics::{self, Counter, Gauge},
|
||||
metrics::{self, Counter, Gauge, Histogram},
|
||||
Metrics,
|
||||
};
|
||||
|
||||
@@ -15,6 +15,14 @@ pub(crate) struct EngineMetrics {
|
||||
pub(crate) new_payload_messages: Counter,
|
||||
/// The number of times the pruner was run.
|
||||
pub(crate) pruner_runs: Counter,
|
||||
/// Latency for making canonical already canonical block
|
||||
pub(crate) make_canonical_already_canonical_latency: Histogram,
|
||||
/// Latency for making canonical committed block
|
||||
pub(crate) make_canonical_committed_latency: Histogram,
|
||||
/// Latency for making canonical returns error
|
||||
pub(crate) make_canonical_error_latency: Histogram,
|
||||
/// Latency for all making canonical results
|
||||
pub(crate) make_canonical_latency: Histogram,
|
||||
}
|
||||
|
||||
/// Metrics for the `EngineSyncController`.
|
||||
|
||||
@@ -12,7 +12,7 @@ use reth_db::database::Database;
|
||||
use reth_interfaces::{
|
||||
blockchain_tree::{
|
||||
error::{InsertBlockError, InsertBlockErrorKind},
|
||||
BlockStatus, BlockchainTreeEngine, InsertPayloadOk,
|
||||
BlockStatus, BlockchainTreeEngine, CanonicalOutcome, InsertPayloadOk,
|
||||
},
|
||||
consensus::ForkchoiceState,
|
||||
executor::{BlockExecutionError, BlockValidationError},
|
||||
@@ -39,6 +39,7 @@ use std::{
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
time::Instant,
|
||||
};
|
||||
use tokio::sync::{
|
||||
mpsc,
|
||||
@@ -628,7 +629,10 @@ where
|
||||
return Ok(OnForkChoiceUpdated::syncing())
|
||||
}
|
||||
|
||||
let status = match self.blockchain.make_canonical(&state.head_block_hash) {
|
||||
let start = Instant::now();
|
||||
let make_canonical_result = self.blockchain.make_canonical(&state.head_block_hash);
|
||||
self.record_make_canonical_latency(start, &make_canonical_result);
|
||||
let status = match make_canonical_result {
|
||||
Ok(outcome) => {
|
||||
if !outcome.is_already_canonical() {
|
||||
debug!(target: "consensus::engine", hash=?state.head_block_hash, number=outcome.header().number, "canonicalized new head");
|
||||
@@ -684,6 +688,28 @@ where
|
||||
Ok(OnForkChoiceUpdated::valid(status))
|
||||
}
|
||||
|
||||
/// Record latency metrics for one call to make a block canonical
|
||||
/// Takes start time of the call and result of the make canonical call
|
||||
///
|
||||
/// Handles cases for error, already canonical and commmitted blocks
|
||||
fn record_make_canonical_latency(
|
||||
&self,
|
||||
start: Instant,
|
||||
outcome: &Result<CanonicalOutcome, Error>,
|
||||
) {
|
||||
let elapsed = start.elapsed();
|
||||
self.metrics.make_canonical_latency.record(elapsed);
|
||||
match outcome {
|
||||
Ok(CanonicalOutcome::AlreadyCanonical { .. }) => {
|
||||
self.metrics.make_canonical_already_canonical_latency.record(elapsed)
|
||||
}
|
||||
Ok(CanonicalOutcome::Committed { .. }) => {
|
||||
self.metrics.make_canonical_committed_latency.record(elapsed)
|
||||
}
|
||||
Err(_) => self.metrics.make_canonical_error_latency.record(elapsed),
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensures that the given forkchoice state is consistent, assuming the head block has been
|
||||
/// made canonical. This takes a status as input, and will only perform consistency checks if
|
||||
/// the input status is VALID.
|
||||
|
||||
Reference in New Issue
Block a user