mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(op, txpool, metrics): add metric for removed conditional txs (#14541)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -8744,11 +8744,13 @@ dependencies = [
|
|||||||
"c-kzg",
|
"c-kzg",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"metrics",
|
||||||
"op-alloy-consensus",
|
"op-alloy-consensus",
|
||||||
"op-alloy-flz",
|
"op-alloy-flz",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"reth-chain-state",
|
"reth-chain-state",
|
||||||
"reth-chainspec",
|
"reth-chainspec",
|
||||||
|
"reth-metrics",
|
||||||
"reth-optimism-chainspec",
|
"reth-optimism-chainspec",
|
||||||
"reth-optimism-evm",
|
"reth-optimism-evm",
|
||||||
"reth-optimism-forks",
|
"reth-optimism-forks",
|
||||||
|
|||||||
@ -35,6 +35,10 @@ reth-optimism-evm.workspace = true
|
|||||||
reth-optimism-forks.workspace = true
|
reth-optimism-forks.workspace = true
|
||||||
reth-optimism-primitives = { workspace = true, features = ["reth-codec"] }
|
reth-optimism-primitives = { workspace = true, features = ["reth-codec"] }
|
||||||
|
|
||||||
|
# metrics
|
||||||
|
reth-metrics.workspace = true
|
||||||
|
metrics.workspace = true
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
c-kzg.workspace = true
|
c-kzg.workspace = true
|
||||||
derive_more.workspace = true
|
derive_more.workspace = true
|
||||||
|
|||||||
@ -1,12 +1,28 @@
|
|||||||
//! Support for maintaining the state of the transaction pool
|
//! Support for maintaining the state of the transaction pool
|
||||||
|
|
||||||
|
use crate::conditional::MaybeConditionalTransaction;
|
||||||
use alloy_consensus::{conditional::BlockConditionalAttributes, BlockHeader};
|
use alloy_consensus::{conditional::BlockConditionalAttributes, BlockHeader};
|
||||||
use futures_util::{future::BoxFuture, FutureExt, Stream, StreamExt};
|
use futures_util::{future::BoxFuture, FutureExt, Stream, StreamExt};
|
||||||
use reth_chain_state::CanonStateNotification;
|
use reth_chain_state::CanonStateNotification;
|
||||||
|
use reth_metrics::{metrics::Counter, Metrics};
|
||||||
use reth_primitives_traits::NodePrimitives;
|
use reth_primitives_traits::NodePrimitives;
|
||||||
use reth_transaction_pool::TransactionPool;
|
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.
|
/// Returns a spawnable future for maintaining the state of the transaction pool.
|
||||||
pub fn maintain_transaction_pool_future<N, Pool, St>(
|
pub fn maintain_transaction_pool_future<N, Pool, St>(
|
||||||
@ -35,6 +51,7 @@ where
|
|||||||
Pool::Transaction: MaybeConditionalTransaction,
|
Pool::Transaction: MaybeConditionalTransaction,
|
||||||
St: Stream<Item = CanonStateNotification<N>> + Send + Unpin + 'static,
|
St: Stream<Item = CanonStateNotification<N>> + Send + Unpin + 'static,
|
||||||
{
|
{
|
||||||
|
let metrics = MaintainPoolMetrics::default();
|
||||||
loop {
|
loop {
|
||||||
let Some(event) = events.next().await else { break };
|
let Some(event) = events.next().await else { break };
|
||||||
if let CanonStateNotification::Commit { new } = event {
|
if let CanonStateNotification::Commit { new } = event {
|
||||||
@ -51,7 +68,10 @@ where
|
|||||||
to_remove.push(*tx.hash());
|
to_remove.push(*tx.hash());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let _ = pool.remove_transactions(to_remove);
|
if !to_remove.is_empty() {
|
||||||
|
metrics.inc_removed_tx_conditional(to_remove.len());
|
||||||
|
let _ = pool.remove_transactions(to_remove);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user