feat(op, txpool, metrics): add metric for removed conditional txs (#14541)

This commit is contained in:
Federico Gimenez
2025-02-17 18:57:58 +01:00
committed by GitHub
parent ea0a96a926
commit f69ca72dc5
3 changed files with 28 additions and 2 deletions

2
Cargo.lock generated
View File

@ -8744,11 +8744,13 @@ dependencies = [
"c-kzg",
"derive_more",
"futures-util",
"metrics",
"op-alloy-consensus",
"op-alloy-flz",
"parking_lot",
"reth-chain-state",
"reth-chainspec",
"reth-metrics",
"reth-optimism-chainspec",
"reth-optimism-evm",
"reth-optimism-forks",

View File

@ -35,6 +35,10 @@ reth-optimism-evm.workspace = true
reth-optimism-forks.workspace = true
reth-optimism-primitives = { workspace = true, features = ["reth-codec"] }
# metrics
reth-metrics.workspace = true
metrics.workspace = true
# misc
c-kzg.workspace = true
derive_more.workspace = true

View File

@ -1,12 +1,28 @@
//! Support for maintaining the state of the transaction pool
use crate::conditional::MaybeConditionalTransaction;
use alloy_consensus::{conditional::BlockConditionalAttributes, BlockHeader};
use futures_util::{future::BoxFuture, FutureExt, Stream, StreamExt};
use reth_chain_state::CanonStateNotification;
use reth_metrics::{metrics::Counter, Metrics};
use reth_primitives_traits::NodePrimitives;
use reth_transaction_pool::TransactionPool;
use crate::conditional::MaybeConditionalTransaction;
/// Transaction pool maintenance metrics
#[derive(Metrics)]
#[metrics(scope = "transaction_pool")]
struct MaintainPoolMetrics {
/// Counter indicating the number of conditional transactions removed from
/// the pool because of exceeded block attributes.
removed_tx_conditional: Counter,
}
impl MaintainPoolMetrics {
#[inline]
fn inc_removed_tx_conditional(&self, count: usize) {
self.removed_tx_conditional.increment(count as u64);
}
}
/// Returns a spawnable future for maintaining the state of the transaction pool.
pub fn maintain_transaction_pool_future<N, Pool, St>(
@ -35,6 +51,7 @@ where
Pool::Transaction: MaybeConditionalTransaction,
St: Stream<Item = CanonStateNotification<N>> + Send + Unpin + 'static,
{
let metrics = MaintainPoolMetrics::default();
loop {
let Some(event) = events.next().await else { break };
if let CanonStateNotification::Commit { new } = event {
@ -51,7 +68,10 @@ where
to_remove.push(*tx.hash());
}
}
if !to_remove.is_empty() {
metrics.inc_removed_tx_conditional(to_remove.len());
let _ = pool.remove_transactions(to_remove);
}
}
}
}