Skip to content

Commit ed0df4e

Browse files
authored
perf(anvil): avoid snapshot cloning when counting ready transactions (#12432)
* perf(anvil): avoid snapshot cloning when counting ready transactions * Update transactions.rs
1 parent a91ac16 commit ed0df4e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

crates/anvil/src/eth/pool/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Pool {
7575
/// Returns the number of tx that are ready and queued for further execution
7676
pub fn txpool_status(&self) -> TxpoolStatus {
7777
// Note: naming differs here compared to geth's `TxpoolStatus`
78-
let pending: u64 = self.ready_transactions().count().try_into().unwrap_or(0);
78+
let pending: u64 = self.inner.read().ready_transactions.len().try_into().unwrap_or(0);
7979
let queued: u64 = self.inner.read().pending_transactions.len().try_into().unwrap_or(0);
8080
TxpoolStatus { pending, queued }
8181
}

crates/anvil/src/eth/pool/transactions.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ impl ReadyTransactions {
417417
self.ready_tx.read().contains_key(hash)
418418
}
419419

420+
/// Returns the number of ready transactions without cloning the snapshot
421+
pub fn len(&self) -> usize {
422+
self.ready_tx.read().len()
423+
}
424+
425+
/// Returns true if there are no ready transactions
426+
pub fn is_empty(&self) -> bool {
427+
self.ready_tx.read().is_empty()
428+
}
429+
420430
/// Returns the transaction for the hash if it's in the ready pool but not yet mined
421431
pub fn get(&self, hash: &TxHash) -> Option<ReadyTransaction> {
422432
self.ready_tx.read().get(hash).cloned()

0 commit comments

Comments
 (0)