feat(tx-pool): add get_transactions_by_sender_and_nonce for TransactionPool trait (#5912)

This commit is contained in:
Thomas Coratger
2024-01-02 14:39:59 +01:00
committed by GitHub
parent 8dff31e3ac
commit 4cd30bdc9b
6 changed files with 38 additions and 4 deletions

View File

@@ -184,6 +184,7 @@ once_cell = "1.17"
syn = "2.0"
ahash = "0.8.6"
# proc-macros
proc-macro2 = "1.0"
quote = "1.0"
@@ -231,4 +232,4 @@ serial_test = "2"
[workspace.metadata.cargo-udeps.ignore]
# ignored because this is mutually exclusive with the optimism payload builder via feature flags
normal = ["reth-ethereum-payload-builder"]
normal = ["reth-ethereum-payload-builder"]

View File

@@ -144,7 +144,7 @@
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use crate::pool::PoolInner;
use crate::{identifier::TransactionId, pool::PoolInner};
use aquamarine as _;
use reth_primitives::{Address, BlobTransactionSidecar, PooledTransactionsElement, TxHash, U256};
use reth_provider::StateProviderFactory;
@@ -473,6 +473,20 @@ where
self.pool.get_transactions_by_sender(sender)
}
fn get_transactions_by_sender_and_nonce(
&self,
sender: Address,
nonce: u64,
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
let transaction_id = TransactionId::new(self.pool.get_sender_id(sender), nonce);
self.inner()
.get_pool_data()
.all()
.get(&transaction_id)
.map(|tx| Arc::clone(&tx.transaction))
}
fn get_transactions_by_origin(
&self,
origin: TransactionOrigin,

View File

@@ -192,6 +192,14 @@ impl TransactionPool for NoopTransactionPool {
vec![]
}
fn get_transactions_by_sender_and_nonce(
&self,
_sender: Address,
_nonce: u64,
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
None
}
fn unique_senders(&self) -> HashSet<Address> {
Default::default()
}

View File

@@ -81,7 +81,7 @@ use crate::{
CanonicalStateUpdate, ChangedAccount, PoolConfig, TransactionOrdering, TransactionValidator,
};
use best::BestTransactions;
use parking_lot::{Mutex, RwLock};
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
use reth_primitives::{
Address, BlobTransaction, BlobTransactionSidecar, IntoRecoveredTransaction,
PooledTransactionsElement, TransactionSigned, TxHash, B256,
@@ -279,6 +279,11 @@ where
self.event_listener.write().subscribe_all()
}
/// Returns a read lock to the pool's data.
pub(crate) fn get_pool_data(&self) -> RwLockReadGuard<'_, TxPool<T>> {
self.pool.read()
}
/// Returns hashes of _all_ transactions in the pool.
pub(crate) fn pooled_transactions_hashes(&self) -> Vec<TxHash> {
let pool = self.pool.read();

View File

@@ -929,7 +929,6 @@ impl<T: PoolTransaction> AllTransactions<T> {
}
/// Returns the internal transaction with additional metadata
#[cfg(test)]
pub(crate) fn get(&self, id: &TransactionId) -> Option<&PoolInternalTransaction<T>> {
self.txs.get(id)
}

View File

@@ -306,6 +306,13 @@ pub trait TransactionPool: Send + Sync + Clone {
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns a transaction sent by a given user with a given nonce
fn get_transactions_by_sender_and_nonce(
&self,
sender: Address,
nonce: u64,
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns all transactions that where submitted with the given [TransactionOrigin]
fn get_transactions_by_origin(
&self,