mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add payload build metrics (#2367)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4641,6 +4641,8 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"metrics",
|
||||
"reth-metrics-derive",
|
||||
"reth-payload-builder",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
|
||||
@ -20,6 +20,10 @@ reth-tasks = { path = "../../tasks" }
|
||||
## ethereum
|
||||
revm = { version = "3" }
|
||||
|
||||
# metrics
|
||||
metrics = "0.20.1"
|
||||
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
|
||||
|
||||
## async
|
||||
tokio = { version = "1", features = ["sync", "time"] }
|
||||
futures-core = "0.3"
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
//! reth basic payload job generator
|
||||
|
||||
use crate::metrics::PayloadBuilderMetrics;
|
||||
use futures_core::{ready, Stream};
|
||||
use futures_util::FutureExt;
|
||||
use reth_payload_builder::{
|
||||
@ -47,6 +48,8 @@ use tokio::{
|
||||
};
|
||||
use tracing::trace;
|
||||
|
||||
mod metrics;
|
||||
|
||||
/// The [PayloadJobGenerator] that creates [BasicPayloadJob]s.
|
||||
pub struct BasicPayloadJobGenerator<Client, Pool, Tasks> {
|
||||
/// The client that can interact with the chain.
|
||||
@ -143,6 +146,7 @@ where
|
||||
best_payload: None,
|
||||
pending_block: None,
|
||||
payload_task_guard: self.payload_task_guard.clone(),
|
||||
metrics: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -252,6 +256,8 @@ pub struct BasicPayloadJob<Client, Pool, Tasks> {
|
||||
pending_block: Option<PendingPayload>,
|
||||
/// Restricts how many generator tasks can be executed at once.
|
||||
payload_task_guard: PayloadTaskGuard,
|
||||
/// metrics for this type
|
||||
metrics: PayloadBuilderMetrics,
|
||||
}
|
||||
|
||||
impl<Client, Pool, Tasks> Stream for BasicPayloadJob<Client, Pool, Tasks>
|
||||
@ -283,6 +289,7 @@ where
|
||||
let guard = this.payload_task_guard.clone();
|
||||
let payload_config = this.config.clone();
|
||||
let best_payload = this.best_payload.clone();
|
||||
this.metrics.inc_initiated_payload_builds();
|
||||
this.executor.spawn_blocking(Box::pin(async move {
|
||||
// acquire the permit for executing the task
|
||||
let _permit = guard.0.acquire().await;
|
||||
@ -311,6 +318,7 @@ where
|
||||
}
|
||||
}
|
||||
Poll::Ready(Err(err)) => {
|
||||
this.metrics.inc_failed_payload_builds();
|
||||
this.interval.reset();
|
||||
return Poll::Ready(Some(Err(err)))
|
||||
}
|
||||
@ -345,6 +353,7 @@ where
|
||||
// Note: it is assumed that this is unlikely to happen, as the payload job is started right
|
||||
// away and the first full block should have been built by the time CL is requesting the
|
||||
// payload.
|
||||
self.metrics.inc_requested_empty_payload();
|
||||
build_empty_payload(&self.client, self.config.clone()).map(Arc::new)
|
||||
}
|
||||
}
|
||||
|
||||
30
crates/payload/basic/src/metrics.rs
Normal file
30
crates/payload/basic/src/metrics.rs
Normal file
@ -0,0 +1,30 @@
|
||||
//! Metrics for the payload builder impl
|
||||
|
||||
use metrics::Counter;
|
||||
use reth_metrics_derive::Metrics;
|
||||
|
||||
/// Transaction pool metrics
|
||||
#[derive(Metrics)]
|
||||
#[metrics(scope = "payloads")]
|
||||
pub(crate) struct PayloadBuilderMetrics {
|
||||
/// Number of active jobs
|
||||
pub(crate) requested_empty_payload: Counter,
|
||||
/// Total number of initiated payload build attempts
|
||||
pub(crate) initiated_payload_builds: Counter,
|
||||
/// Total number of failed payload build attempts
|
||||
pub(crate) failed_payload_builds: Counter,
|
||||
}
|
||||
|
||||
impl PayloadBuilderMetrics {
|
||||
pub(crate) fn inc_requested_empty_payload(&self) {
|
||||
self.requested_empty_payload.increment(1);
|
||||
}
|
||||
|
||||
pub(crate) fn inc_initiated_payload_builds(&self) {
|
||||
self.initiated_payload_builds.increment(1);
|
||||
}
|
||||
|
||||
pub(crate) fn inc_failed_payload_builds(&self) {
|
||||
self.failed_payload_builds.increment(1);
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
//! Payloadbuild service metrics.
|
||||
//! Payload builder service metrics.
|
||||
|
||||
use metrics::{Counter, Gauge};
|
||||
use reth_metrics_derive::Metrics;
|
||||
|
||||
/// Transaction pool metrics
|
||||
/// Payload builder service metrics
|
||||
#[derive(Metrics)]
|
||||
#[metrics(scope = "payloads")]
|
||||
pub(crate) struct PayloadBuilderServiceMetrics {
|
||||
|
||||
Reference in New Issue
Block a user