chore: retrieve single pooled tx by hash (#6785)

This commit is contained in:
Emmanuel Ekpenyong
2024-02-26 13:07:54 +01:00
committed by GitHub
parent 6930734a13
commit be6d505745
4 changed files with 36 additions and 0 deletions

View File

@ -417,6 +417,10 @@ where
self.pool.get_pooled_transaction_elements(tx_hashes, limit)
}
fn get_pooled_transaction_element(&self, tx_hash: TxHash) -> Option<PooledTransactionsElement> {
self.pool.get_pooled_transaction_element(tx_hash)
}
fn best_transactions(
&self,
) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {

View File

@ -135,6 +135,13 @@ impl TransactionPool for NoopTransactionPool {
vec![]
}
fn get_pooled_transaction_element(
&self,
_tx_hash: TxHash,
) -> Option<PooledTransactionsElement> {
None
}
fn best_transactions(
&self,
) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {

View File

@ -341,6 +341,21 @@ where
elements
}
/// Returns converted [PooledTransactionsElement] for the given transaction hash.
pub(crate) fn get_pooled_transaction_element(
&self,
tx_hash: TxHash,
) -> Option<PooledTransactionsElement> {
self.get(&tx_hash).and_then(|transaction| {
let tx = transaction.to_recovered_transaction().into_signed();
if tx.is_eip4844() {
self.get_blob_transaction(tx).map(PooledTransactionsElement::BlobTransaction)
} else {
Some(PooledTransactionsElement::from(tx))
}
})
}
/// Updates the entire pool after a new block was executed.
pub(crate) fn on_canonical_state_change(&self, update: CanonicalStateUpdate<'_>) {
trace!(target: "txpool", ?update, "updating pool on canonical state change");

View File

@ -221,6 +221,16 @@ pub trait TransactionPool: Send + Sync + Clone {
limit: GetPooledTransactionLimit,
) -> Vec<PooledTransactionsElement>;
/// Returns converted [PooledTransactionsElement] for the given transaction hash.
///
/// This adheres to the expected behavior of
/// [`GetPooledTransactions`](https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getpooledtransactions-0x09):
///
/// If the transaction is a blob transaction, the sidecar will be included.
///
/// Consumer: P2P
fn get_pooled_transaction_element(&self, tx_hash: TxHash) -> Option<PooledTransactionsElement>;
/// Returns an iterator that yields transactions that are ready for block production.
///
/// Consumer: Block production