Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add metrics to track transactions by type in txpool #11403

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy this comment as blob sub-pool exists.

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,
Comment on lines +49 to +50
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't mentioned in the original issue but I assume we wanted to track all tx types so added here.


/// 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
Loading