Skip to content

Commit

Permalink
feat: Add metrics to track transactions by type in txpool (paradigmxy…
Browse files Browse the repository at this point in the history
…z#11403)

Co-authored-by: garwah <garwah@garwah>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
3 people authored and ebo committed Oct 14, 2024
1 parent 944bb94 commit 5259b71
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
12 changes: 11 additions & 1 deletion crates/transaction-pool/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ pub struct TxPoolMetrics {
/// Total amount of memory used by the transactions in the blob sub-pool in bytes
pub(crate) blob_pool_size_bytes: Gauge,

/// Number of all transactions of all sub-pools: pending + basefee + queued
/// Number of all transactions of all sub-pools: pending + basefee + queued + blob
pub(crate) total_transactions: Gauge,
/// Number of all legacy transactions in the pool
pub(crate) total_legacy_transactions: Gauge,
/// Number of all EIP-2930 transactions in the pool
pub(crate) total_eip2930_transactions: Gauge,
/// Number of all EIP-1559 transactions in the pool
pub(crate) total_eip1559_transactions: Gauge,
/// Number of all EIP-4844 transactions in the pool
pub(crate) total_eip4844_transactions: Gauge,
/// Number of all EIP-7702 transactions in the pool
pub(crate) total_eip7702_transactions: Gauge,

/// How often the pool was updated after the canonical state changed
pub(crate) performed_state_updates: Counter,
Expand Down
35 changes: 33 additions & 2 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ use crate::{
ValidPoolTransaction, U256,
};
use alloy_primitives::{Address, TxHash, B256};
use reth_primitives::constants::{
eip4844::BLOB_TX_MIN_BLOB_GASPRICE, ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE,
use reth_primitives::{
constants::{
eip4844::BLOB_TX_MIN_BLOB_GASPRICE, ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE,
},
EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID,
LEGACY_TX_TYPE_ID,
};
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
Expand Down Expand Up @@ -429,6 +433,7 @@ impl<T: TransactionOrdering> TxPool<T> {

let UpdateOutcome { promoted, discarded } = self.update_accounts(changed_senders);

self.update_transaction_type_metrics();
self.metrics.performed_state_updates.increment(1);

OnNewCanonicalStateOutcome { block_hash, mined: mined_transactions, promoted, discarded }
Expand All @@ -448,6 +453,32 @@ impl<T: TransactionOrdering> TxPool<T> {
self.metrics.total_transactions.set(stats.total as f64);
}

/// Updates transaction type metrics for the entire pool.
pub(crate) fn update_transaction_type_metrics(&self) {
let mut legacy_count = 0;
let mut eip2930_count = 0;
let mut eip1559_count = 0;
let mut eip4844_count = 0;
let mut eip7702_count = 0;

for tx in self.all_transactions.transactions_iter() {
match tx.transaction.tx_type() {
LEGACY_TX_TYPE_ID => legacy_count += 1,
EIP2930_TX_TYPE_ID => eip2930_count += 1,
EIP1559_TX_TYPE_ID => eip1559_count += 1,
EIP4844_TX_TYPE_ID => eip4844_count += 1,
EIP7702_TX_TYPE_ID => eip7702_count += 1,
_ => {} // Ignore other types
}
}

self.metrics.total_legacy_transactions.set(legacy_count as f64);
self.metrics.total_eip2930_transactions.set(eip2930_count as f64);
self.metrics.total_eip1559_transactions.set(eip1559_count as f64);
self.metrics.total_eip4844_transactions.set(eip4844_count as f64);
self.metrics.total_eip7702_transactions.set(eip7702_count as f64);
}

/// Adds the transaction into the pool.
///
/// This pool consists of four sub-pools: `Queued`, `Pending`, `BaseFee`, and `Blob`.
Expand Down

0 comments on commit 5259b71

Please sign in to comment.