Skip to content

Commit 3a9dbdc

Browse files
authored
feat(tx-pool): make metrics, listener structs, and fields public (#20087)
1 parent af1e12f commit 3a9dbdc

File tree

3 files changed

+72
-69
lines changed

3 files changed

+72
-69
lines changed

crates/transaction-pool/src/metrics.rs

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,72 @@ use reth_metrics::{
1010
#[metrics(scope = "transaction_pool")]
1111
pub struct TxPoolMetrics {
1212
/// Number of transactions inserted in the pool
13-
pub(crate) inserted_transactions: Counter,
13+
pub inserted_transactions: Counter,
1414
/// Number of invalid transactions
15-
pub(crate) invalid_transactions: Counter,
15+
pub invalid_transactions: Counter,
1616
/// Number of removed transactions from the pool
17-
pub(crate) removed_transactions: Counter,
17+
pub removed_transactions: Counter,
1818

1919
/// Number of transactions in the pending sub-pool
20-
pub(crate) pending_pool_transactions: Gauge,
20+
pub pending_pool_transactions: Gauge,
2121
/// Total amount of memory used by the transactions in the pending sub-pool in bytes
22-
pub(crate) pending_pool_size_bytes: Gauge,
22+
pub pending_pool_size_bytes: Gauge,
2323

2424
/// Number of transactions in the basefee sub-pool
25-
pub(crate) basefee_pool_transactions: Gauge,
25+
pub basefee_pool_transactions: Gauge,
2626
/// Total amount of memory used by the transactions in the basefee sub-pool in bytes
27-
pub(crate) basefee_pool_size_bytes: Gauge,
27+
pub basefee_pool_size_bytes: Gauge,
2828

2929
/// Number of transactions in the queued sub-pool
30-
pub(crate) queued_pool_transactions: Gauge,
30+
pub queued_pool_transactions: Gauge,
3131
/// Total amount of memory used by the transactions in the queued sub-pool in bytes
32-
pub(crate) queued_pool_size_bytes: Gauge,
32+
pub queued_pool_size_bytes: Gauge,
3333

3434
/// Number of transactions in the blob sub-pool
35-
pub(crate) blob_pool_transactions: Gauge,
35+
pub blob_pool_transactions: Gauge,
3636
/// Total amount of memory used by the transactions in the blob sub-pool in bytes
37-
pub(crate) blob_pool_size_bytes: Gauge,
37+
pub blob_pool_size_bytes: Gauge,
3838

3939
/// Number of all transactions of all sub-pools: pending + basefee + queued + blob
40-
pub(crate) total_transactions: Gauge,
40+
pub total_transactions: Gauge,
4141
/// Number of all legacy transactions in the pool
42-
pub(crate) total_legacy_transactions: Gauge,
42+
pub total_legacy_transactions: Gauge,
4343
/// Number of all EIP-2930 transactions in the pool
44-
pub(crate) total_eip2930_transactions: Gauge,
44+
pub total_eip2930_transactions: Gauge,
4545
/// Number of all EIP-1559 transactions in the pool
46-
pub(crate) total_eip1559_transactions: Gauge,
46+
pub total_eip1559_transactions: Gauge,
4747
/// Number of all EIP-4844 transactions in the pool
48-
pub(crate) total_eip4844_transactions: Gauge,
48+
pub total_eip4844_transactions: Gauge,
4949
/// Number of all EIP-7702 transactions in the pool
50-
pub(crate) total_eip7702_transactions: Gauge,
50+
pub total_eip7702_transactions: Gauge,
5151
/// Number of all other transactions in the pool
52-
pub(crate) total_other_transactions: Gauge,
52+
pub total_other_transactions: Gauge,
5353

5454
/// How often the pool was updated after the canonical state changed
55-
pub(crate) performed_state_updates: Counter,
55+
pub performed_state_updates: Counter,
5656

5757
/// Counter for the number of pending transactions evicted
58-
pub(crate) pending_transactions_evicted: Counter,
58+
pub pending_transactions_evicted: Counter,
5959
/// Counter for the number of basefee transactions evicted
60-
pub(crate) basefee_transactions_evicted: Counter,
60+
pub basefee_transactions_evicted: Counter,
6161
/// Counter for the number of blob transactions evicted
62-
pub(crate) blob_transactions_evicted: Counter,
62+
pub blob_transactions_evicted: Counter,
6363
/// Counter for the number of queued transactions evicted
64-
pub(crate) queued_transactions_evicted: Counter,
64+
pub queued_transactions_evicted: Counter,
6565
}
6666

6767
/// Transaction pool blobstore metrics
6868
#[derive(Metrics)]
6969
#[metrics(scope = "transaction_pool")]
7070
pub struct BlobStoreMetrics {
7171
/// Number of failed inserts into the blobstore
72-
pub(crate) blobstore_failed_inserts: Counter,
72+
pub blobstore_failed_inserts: Counter,
7373
/// Number of failed deletes into the blobstore
74-
pub(crate) blobstore_failed_deletes: Counter,
74+
pub blobstore_failed_deletes: Counter,
7575
/// The number of bytes the blobs in the blobstore take up
76-
pub(crate) blobstore_byte_size: Gauge,
76+
pub blobstore_byte_size: Gauge,
7777
/// How many blobs are currently in the blobstore
78-
pub(crate) blobstore_entries: Gauge,
78+
pub blobstore_entries: Gauge,
7979
}
8080

8181
/// Transaction pool maintenance metrics
@@ -84,35 +84,39 @@ pub struct BlobStoreMetrics {
8484
pub struct MaintainPoolMetrics {
8585
/// Gauge indicating the number of addresses with pending updates in the pool,
8686
/// requiring their account information to be fetched.
87-
pub(crate) dirty_accounts: Gauge,
87+
pub dirty_accounts: Gauge,
8888
/// Counter for the number of times the pool state diverged from the canonical blockchain
8989
/// state.
90-
pub(crate) drift_count: Counter,
90+
pub drift_count: Counter,
9191
/// Counter for the number of transactions reinserted into the pool following a blockchain
9292
/// reorganization (reorg).
93-
pub(crate) reinserted_transactions: Counter,
93+
pub reinserted_transactions: Counter,
9494
/// Counter for the number of finalized blob transactions that have been removed from tracking.
95-
pub(crate) deleted_tracked_finalized_blobs: Counter,
95+
pub deleted_tracked_finalized_blobs: Counter,
9696
}
9797

9898
impl MaintainPoolMetrics {
99+
/// Sets the number of dirty accounts in the pool.
99100
#[inline]
100-
pub(crate) fn set_dirty_accounts_len(&self, count: usize) {
101+
pub fn set_dirty_accounts_len(&self, count: usize) {
101102
self.dirty_accounts.set(count as f64);
102103
}
103104

105+
/// Increments the count of reinserted transactions.
104106
#[inline]
105-
pub(crate) fn inc_reinserted_transactions(&self, count: usize) {
107+
pub fn inc_reinserted_transactions(&self, count: usize) {
106108
self.reinserted_transactions.increment(count as u64);
107109
}
108110

111+
/// Increments the count of deleted tracked finalized blobs.
109112
#[inline]
110-
pub(crate) fn inc_deleted_tracked_blobs(&self, count: usize) {
113+
pub fn inc_deleted_tracked_blobs(&self, count: usize) {
111114
self.deleted_tracked_finalized_blobs.increment(count as u64);
112115
}
113116

117+
/// Increments the drift count by one.
114118
#[inline]
115-
pub(crate) fn inc_drift(&self) {
119+
pub fn inc_drift(&self) {
116120
self.drift_count.increment(1);
117121
}
118122
}
@@ -122,31 +126,31 @@ impl MaintainPoolMetrics {
122126
#[metrics(scope = "transaction_pool")]
123127
pub struct AllTransactionsMetrics {
124128
/// Number of all transactions by hash in the pool
125-
pub(crate) all_transactions_by_hash: Gauge,
129+
pub all_transactions_by_hash: Gauge,
126130
/// Number of all transactions by id in the pool
127-
pub(crate) all_transactions_by_id: Gauge,
131+
pub all_transactions_by_id: Gauge,
128132
/// Number of all transactions by all senders in the pool
129-
pub(crate) all_transactions_by_all_senders: Gauge,
133+
pub all_transactions_by_all_senders: Gauge,
130134
/// Number of blob transactions nonce gaps.
131-
pub(crate) blob_transactions_nonce_gaps: Counter,
135+
pub blob_transactions_nonce_gaps: Counter,
132136
/// The current blob base fee
133-
pub(crate) blob_base_fee: Gauge,
137+
pub blob_base_fee: Gauge,
134138
/// The current base fee
135-
pub(crate) base_fee: Gauge,
139+
pub base_fee: Gauge,
136140
}
137141

138142
/// Transaction pool validation metrics
139143
#[derive(Metrics)]
140144
#[metrics(scope = "transaction_pool")]
141145
pub struct TxPoolValidationMetrics {
142146
/// How long to successfully validate a blob
143-
pub(crate) blob_validation_duration: Histogram,
147+
pub blob_validation_duration: Histogram,
144148
}
145149

146150
/// Transaction pool validator task metrics
147151
#[derive(Metrics)]
148152
#[metrics(scope = "transaction_pool")]
149153
pub struct TxPoolValidatorMetrics {
150154
/// Number of in-flight validation job sends waiting for channel capacity
151-
pub(crate) inflight_validation_jobs: Gauge,
155+
pub inflight_validation_jobs: Gauge,
152156
}

crates/transaction-pool/src/pool/listener.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<T: PoolTransaction> Stream for AllTransactionsEvents<T> {
8282
/// This is essentially a multi-producer, multi-consumer channel where each event is broadcast to
8383
/// all active receivers.
8484
#[derive(Debug)]
85-
pub(crate) struct PoolEventBroadcast<T: PoolTransaction> {
85+
pub struct PoolEventBroadcast<T: PoolTransaction> {
8686
/// All listeners for all transaction events.
8787
all_events_broadcaster: AllPoolEventsBroadcaster<T>,
8888
/// All listeners for events for a certain transaction hash.
@@ -121,12 +121,12 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
121121

122122
/// Returns true if no listeners are installed
123123
#[inline]
124-
pub(crate) fn is_empty(&self) -> bool {
124+
pub fn is_empty(&self) -> bool {
125125
self.all_events_broadcaster.is_empty() && self.broadcasters_by_hash.is_empty()
126126
}
127127

128128
/// Create a new subscription for the given transaction hash.
129-
pub(crate) fn subscribe(&mut self, tx_hash: TxHash) -> TransactionEvents {
129+
pub fn subscribe(&mut self, tx_hash: TxHash) -> TransactionEvents {
130130
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
131131

132132
match self.broadcasters_by_hash.entry(tx_hash) {
@@ -141,14 +141,14 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
141141
}
142142

143143
/// Create a new subscription for all transactions.
144-
pub(crate) fn subscribe_all(&mut self) -> AllTransactionsEvents<T> {
144+
pub fn subscribe_all(&mut self) -> AllTransactionsEvents<T> {
145145
let (tx, rx) = tokio::sync::mpsc::channel(TX_POOL_EVENT_CHANNEL_SIZE);
146146
self.all_events_broadcaster.senders.push(tx);
147147
AllTransactionsEvents::new(rx)
148148
}
149149

150150
/// Notify listeners about a transaction that was added to the pending queue.
151-
pub(crate) fn pending(&mut self, tx: &TxHash, replaced: Option<Arc<ValidPoolTransaction<T>>>) {
151+
pub fn pending(&mut self, tx: &TxHash, replaced: Option<Arc<ValidPoolTransaction<T>>>) {
152152
self.broadcast_event(tx, TransactionEvent::Pending, FullTransactionEvent::Pending(*tx));
153153

154154
if let Some(replaced) = replaced {
@@ -158,7 +158,7 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
158158
}
159159

160160
/// Notify listeners about a transaction that was replaced.
161-
pub(crate) fn replaced(&mut self, tx: Arc<ValidPoolTransaction<T>>, replaced_by: TxHash) {
161+
pub fn replaced(&mut self, tx: Arc<ValidPoolTransaction<T>>, replaced_by: TxHash) {
162162
let transaction = Arc::clone(&tx);
163163
self.broadcast_event(
164164
tx.hash(),
@@ -168,7 +168,7 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
168168
}
169169

170170
/// Notify listeners about a transaction that was added to the queued pool.
171-
pub(crate) fn queued(&mut self, tx: &TxHash, reason: Option<QueuedReason>) {
171+
pub fn queued(&mut self, tx: &TxHash, reason: Option<QueuedReason>) {
172172
self.broadcast_event(
173173
tx,
174174
TransactionEvent::Queued,
@@ -177,7 +177,7 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
177177
}
178178

179179
/// Notify listeners about a transaction that was propagated.
180-
pub(crate) fn propagated(&mut self, tx: &TxHash, peers: Vec<PropagateKind>) {
180+
pub fn propagated(&mut self, tx: &TxHash, peers: Vec<PropagateKind>) {
181181
let peers = Arc::new(peers);
182182
self.broadcast_event(
183183
tx,
@@ -188,7 +188,7 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
188188

189189
/// Notify listeners about all discarded transactions.
190190
#[inline]
191-
pub(crate) fn discarded_many(&mut self, discarded: &[Arc<ValidPoolTransaction<T>>]) {
191+
pub fn discarded_many(&mut self, discarded: &[Arc<ValidPoolTransaction<T>>]) {
192192
if self.is_empty() {
193193
return
194194
}
@@ -198,17 +198,17 @@ impl<T: PoolTransaction> PoolEventBroadcast<T> {
198198
}
199199

200200
/// Notify listeners about a transaction that was discarded.
201-
pub(crate) fn discarded(&mut self, tx: &TxHash) {
201+
pub fn discarded(&mut self, tx: &TxHash) {
202202
self.broadcast_event(tx, TransactionEvent::Discarded, FullTransactionEvent::Discarded(*tx));
203203
}
204204

205205
/// Notify listeners about a transaction that was invalid.
206-
pub(crate) fn invalid(&mut self, tx: &TxHash) {
206+
pub fn invalid(&mut self, tx: &TxHash) {
207207
self.broadcast_event(tx, TransactionEvent::Invalid, FullTransactionEvent::Invalid(*tx));
208208
}
209209

210210
/// Notify listeners that the transaction was mined
211-
pub(crate) fn mined(&mut self, tx: &TxHash, block_hash: B256) {
211+
pub fn mined(&mut self, tx: &TxHash, block_hash: B256) {
212212
self.broadcast_event(
213213
tx,
214214
TransactionEvent::Mined(block_hash),
@@ -271,17 +271,18 @@ impl PoolEventBroadcaster {
271271

272272
/// An active listener for new pending transactions.
273273
#[derive(Debug)]
274-
pub(crate) struct PendingTransactionHashListener {
275-
pub(crate) sender: mpsc::Sender<TxHash>,
274+
pub struct PendingTransactionHashListener {
275+
/// The sender of the channel to send transaction hashes to.
276+
pub sender: mpsc::Sender<TxHash>,
276277
/// Whether to include transactions that should not be propagated over the network.
277-
pub(crate) kind: TransactionListenerKind,
278+
pub kind: TransactionListenerKind,
278279
}
279280

280281
impl PendingTransactionHashListener {
281282
/// Attempts to send all hashes to the listener.
282283
///
283284
/// Returns false if the channel is closed (receiver dropped)
284-
pub(crate) fn send_all(&self, hashes: impl IntoIterator<Item = TxHash>) -> bool {
285+
pub fn send_all(&self, hashes: impl IntoIterator<Item = TxHash>) -> bool {
285286
for tx_hash in hashes {
286287
match self.sender.try_send(tx_hash) {
287288
Ok(()) => {}
@@ -305,27 +306,25 @@ impl PendingTransactionHashListener {
305306

306307
/// An active listener for new pending transactions.
307308
#[derive(Debug)]
308-
pub(crate) struct TransactionListener<T: PoolTransaction> {
309-
pub(crate) sender: mpsc::Sender<NewTransactionEvent<T>>,
309+
pub struct TransactionListener<T: PoolTransaction> {
310+
/// The sender of the channel to send new transaction events to.
311+
pub sender: mpsc::Sender<NewTransactionEvent<T>>,
310312
/// Whether to include transactions that should not be propagated over the network.
311-
pub(crate) kind: TransactionListenerKind,
313+
pub kind: TransactionListenerKind,
312314
}
313315

314316
impl<T: PoolTransaction> TransactionListener<T> {
315317
/// Attempts to send the event to the listener.
316318
///
317319
/// Returns false if the channel is closed (receiver dropped)
318-
pub(crate) fn send(&self, event: NewTransactionEvent<T>) -> bool {
320+
pub fn send(&self, event: NewTransactionEvent<T>) -> bool {
319321
self.send_all(std::iter::once(event))
320322
}
321323

322324
/// Attempts to send all events to the listener.
323325
///
324326
/// Returns false if the channel is closed (receiver dropped)
325-
pub(crate) fn send_all(
326-
&self,
327-
events: impl IntoIterator<Item = NewTransactionEvent<T>>,
328-
) -> bool {
327+
pub fn send_all(&self, events: impl IntoIterator<Item = NewTransactionEvent<T>>) -> bool {
329328
for event in events {
330329
match self.sender.try_send(event) {
331330
Ok(()) => {}

crates/transaction-pool/src/pool/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ mod best;
112112
pub use best::BestTransactions;
113113

114114
mod blob;
115-
mod listener;
115+
pub mod listener;
116116
mod parked;
117117
pub mod pending;
118-
pub(crate) mod size;
118+
pub mod size;
119119
pub(crate) mod state;
120120
pub mod txpool;
121121
mod update;

0 commit comments

Comments
 (0)