Skip to main content

reth_transaction_pool/
metrics.rs

1//! Transaction pool metrics.
2
3use reth_metrics::{
4    metrics::{Counter, Gauge, Histogram},
5    Metrics,
6};
7
8/// Transaction pool metrics
9#[derive(Metrics)]
10#[metrics(scope = "transaction_pool")]
11pub struct TxPoolMetrics {
12    /// Number of transactions inserted in the pool
13    pub inserted_transactions: Counter,
14    /// Number of invalid transactions
15    pub invalid_transactions: Counter,
16    /// Number of removed transactions from the pool
17    pub removed_transactions: Counter,
18
19    /// Number of transactions in the pending sub-pool
20    pub pending_pool_transactions: Gauge,
21    /// Total amount of memory used by the transactions in the pending sub-pool in bytes
22    pub pending_pool_size_bytes: Gauge,
23
24    /// Number of transactions in the basefee sub-pool
25    pub basefee_pool_transactions: Gauge,
26    /// Total amount of memory used by the transactions in the basefee sub-pool in bytes
27    pub basefee_pool_size_bytes: Gauge,
28
29    /// Number of transactions in the queued sub-pool
30    pub queued_pool_transactions: Gauge,
31    /// Total amount of memory used by the transactions in the queued sub-pool in bytes
32    pub queued_pool_size_bytes: Gauge,
33
34    /// Number of transactions in the blob sub-pool
35    pub blob_pool_transactions: Gauge,
36    /// Total amount of memory used by the transactions in the blob sub-pool in bytes
37    pub blob_pool_size_bytes: Gauge,
38
39    /// Number of all transactions of all sub-pools: pending + basefee + queued + blob
40    pub total_transactions: Gauge,
41    /// Number of all legacy transactions in the pool
42    pub total_legacy_transactions: Gauge,
43    /// Number of all EIP-2930 transactions in the pool
44    pub total_eip2930_transactions: Gauge,
45    /// Number of all EIP-1559 transactions in the pool
46    pub total_eip1559_transactions: Gauge,
47    /// Number of all EIP-4844 transactions in the pool
48    pub total_eip4844_transactions: Gauge,
49    /// Number of all EIP-7702 transactions in the pool
50    pub total_eip7702_transactions: Gauge,
51    /// Number of all other transactions in the pool
52    pub total_other_transactions: Gauge,
53
54    /// How often the pool was updated after the canonical state changed
55    pub performed_state_updates: Counter,
56
57    /// Counter for the number of pending transactions evicted
58    pub pending_transactions_evicted: Counter,
59    /// Counter for the number of basefee transactions evicted
60    pub basefee_transactions_evicted: Counter,
61    /// Counter for the number of blob transactions evicted
62    pub blob_transactions_evicted: Counter,
63    /// Counter for the number of queued transactions evicted
64    pub queued_transactions_evicted: Counter,
65}
66
67/// Transaction pool blobstore metrics
68#[derive(Metrics)]
69#[metrics(scope = "transaction_pool")]
70pub struct BlobStoreMetrics {
71    /// Number of failed inserts into the blobstore
72    pub blobstore_failed_inserts: Counter,
73    /// Number of failed deletes into the blobstore
74    pub blobstore_failed_deletes: Counter,
75    /// The number of bytes the blobs in the blobstore take up
76    pub blobstore_byte_size: Gauge,
77    /// How many blobs are currently in the blobstore
78    pub blobstore_entries: Gauge,
79}
80
81/// Transaction pool maintenance metrics
82#[derive(Metrics)]
83#[metrics(scope = "transaction_pool")]
84pub struct MaintainPoolMetrics {
85    /// Gauge indicating the number of addresses with pending updates in the pool,
86    /// requiring their account information to be fetched.
87    pub dirty_accounts: Gauge,
88    /// Counter for the number of times the pool state diverged from the canonical blockchain
89    /// state.
90    pub drift_count: Counter,
91    /// Counter for the number of transactions reinserted into the pool following a blockchain
92    /// reorganization (reorg).
93    pub reinserted_transactions: Counter,
94    /// Counter for the number of finalized blob transactions that have been removed from tracking.
95    pub deleted_tracked_finalized_blobs: Counter,
96}
97
98impl MaintainPoolMetrics {
99    /// Sets the number of dirty accounts in the pool.
100    #[inline]
101    pub fn set_dirty_accounts_len(&self, count: usize) {
102        self.dirty_accounts.set(count as f64);
103    }
104
105    /// Increments the count of reinserted transactions.
106    #[inline]
107    pub fn inc_reinserted_transactions(&self, count: usize) {
108        self.reinserted_transactions.increment(count as u64);
109    }
110
111    /// Increments the count of deleted tracked finalized blobs.
112    #[inline]
113    pub fn inc_deleted_tracked_blobs(&self, count: usize) {
114        self.deleted_tracked_finalized_blobs.increment(count as u64);
115    }
116
117    /// Increments the drift count by one.
118    #[inline]
119    pub fn inc_drift(&self) {
120        self.drift_count.increment(1);
121    }
122}
123
124/// All Transactions metrics
125#[derive(Metrics)]
126#[metrics(scope = "transaction_pool")]
127pub struct AllTransactionsMetrics {
128    /// Number of all transactions by hash in the pool
129    pub all_transactions_by_hash: Gauge,
130    /// Number of all transactions by id in the pool
131    pub all_transactions_by_id: Gauge,
132    /// Number of all transactions by all senders in the pool
133    pub all_transactions_by_all_senders: Gauge,
134    /// Number of blob transactions nonce gaps.
135    pub blob_transactions_nonce_gaps: Counter,
136    /// The current blob base fee
137    pub blob_base_fee: Gauge,
138    /// The current base fee
139    pub base_fee: Gauge,
140}
141
142/// Transaction pool validation metrics.
143///
144/// Rejection counters cover selected validation checks and count repeated attempts for the same
145/// transaction separately.
146#[derive(Metrics)]
147#[metrics(scope = "transaction_pool")]
148pub struct TxPoolValidationMetrics {
149    /// How long to successfully validate a blob
150    pub blob_validation_duration: Histogram,
151    /// Number of stateless validation attempts rejected due to transaction data exceeding the size
152    /// limit.
153    pub rejected_oversized_data: Counter,
154    /// Number of stateless validation attempts rejected due to a priority fee exceeding the max
155    /// fee per gas.
156    pub rejected_tip_above_fee_cap: Counter,
157    /// Number of stateless validation attempts rejected due to a local transaction fee exceeding
158    /// the configured fee cap.
159    pub rejected_exceeds_fee_cap: Counter,
160    /// Number of stateless validation attempts rejected due to a priority fee below the configured
161    /// minimum.
162    pub rejected_priority_fee_below_minimum: Counter,
163    /// Number of stateless validation attempts rejected due to a gas limit below the intrinsic or
164    /// floor gas cost.
165    pub rejected_intrinsic_gas_too_low: Counter,
166    /// Number of stateless validation attempts rejected due to intrinsic regular gas or floor gas
167    /// above the EIP-8037 regular gas cap.
168    pub rejected_intrinsic_gas_too_high: Counter,
169    /// Number of validation attempts rejected by blob count or blob sidecar checks.
170    pub invalid_4844: Counter,
171}
172
173/// Transaction pool validator task metrics
174#[derive(Metrics)]
175#[metrics(scope = "transaction_pool")]
176pub struct TxPoolValidatorMetrics {
177    /// Number of in-flight validation job sends waiting for channel capacity
178    pub inflight_validation_jobs: Gauge,
179}