tempo_transaction_pool/
metrics.rs

1//! Transaction pool metrics for the AA2D pool.
2
3use reth_metrics::{
4    Metrics,
5    metrics::{Counter, Gauge},
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}