Skip to main content

tempo_transaction_pool/
metrics.rs

1//! Transaction pool metrics for the AA2D pool.
2
3use reth_metrics::{
4    Metrics,
5    metrics::{Counter, Gauge, Histogram},
6};
7
8/// AA2D pool metrics
9#[derive(Metrics, Clone)]
10#[metrics(scope = "transaction_pool.aa_2d")]
11pub struct AA2dPoolMetrics {
12    /// Total number of transactions in the AA2D pool
13    pub total_transactions: Gauge,
14
15    /// Number of pending (executable) transactions in the AA2D pool
16    pub pending_transactions: Gauge,
17
18    /// Number of queued (non-executable) transactions in the AA2D pool
19    pub queued_transactions: Gauge,
20
21    /// Total number of tracked (address, nonce_key) pairs
22    pub tracked_nonce_keys: Gauge,
23
24    /// Number of transactions inserted into the AA2D pool
25    pub inserted_transactions: Counter,
26
27    /// Number of transactions removed from the AA2D pool
28    pub removed_transactions: Counter,
29
30    /// Number of transactions promoted from queued to pending
31    pub promoted_transactions: Counter,
32
33    /// Number of transactions demoted from pending to queued
34    pub demoted_transactions: Counter,
35}
36
37impl AA2dPoolMetrics {
38    /// Update the transaction count metrics
39    #[inline]
40    pub fn set_transaction_counts(&self, total: usize, pending: usize, queued: usize) {
41        self.total_transactions.set(total as f64);
42        self.pending_transactions.set(pending as f64);
43        self.queued_transactions.set(queued as f64);
44    }
45
46    /// Update the nonce key tracking metrics
47    #[inline]
48    pub fn inc_nonce_key_count(&self, nonce_keys: usize) {
49        self.tracked_nonce_keys.increment(nonce_keys as f64);
50    }
51
52    /// Increment the inserted transactions counter
53    #[inline]
54    pub fn inc_inserted(&self) {
55        self.inserted_transactions.increment(1);
56    }
57
58    /// Increment the removed transactions counter
59    #[inline]
60    pub fn inc_removed(&self, count: usize) {
61        self.removed_transactions.increment(count as u64);
62    }
63
64    /// Increment the promoted transactions counter
65    #[inline]
66    pub fn inc_promoted(&self, count: usize) {
67        self.promoted_transactions.increment(count as u64);
68    }
69
70    /// Increment the demoted transactions counter
71    #[inline]
72    pub fn inc_demoted(&self, count: usize) {
73        self.demoted_transactions.increment(count as u64);
74    }
75}
76
77/// Metrics for the Tempo pool maintenance task.
78#[derive(Metrics, Clone)]
79#[metrics(scope = "transaction_pool.maintenance")]
80pub struct TempoPoolMaintenanceMetrics {
81    /// Total time spent processing a block update in seconds.
82    pub block_update_duration_seconds: Histogram,
83
84    /// Time spent evicting expired AA transactions in seconds.
85    pub expired_eviction_duration_seconds: Histogram,
86
87    /// Time spent processing fee token pause/unpause events in seconds.
88    pub pause_events_duration_seconds: Histogram,
89
90    /// Time spent evicting invalidated transactions (revoked keys, validator tokens, blacklist) in seconds.
91    pub invalidation_eviction_duration_seconds: Histogram,
92
93    /// Time spent updating the AMM liquidity cache in seconds.
94    pub amm_cache_update_duration_seconds: Histogram,
95
96    /// Time spent updating the 2D nonce pool in seconds.
97    pub nonce_pool_update_duration_seconds: Histogram,
98
99    /// Number of expired transactions evicted.
100    pub expired_transactions_evicted: Counter,
101
102    /// Number of transactions moved to the paused pool.
103    pub transactions_paused: Counter,
104
105    /// Number of transactions restored from the paused pool.
106    pub transactions_unpaused: Counter,
107
108    /// Number of transactions evicted due to invalidation events.
109    pub transactions_invalidated: Counter,
110
111    /// Number of paused transactions evicted due to the global cap.
112    pub paused_pool_cap_evicted: Counter,
113}