feat: use Pooled type for get_pooled_transaction_element in pool trait (#12867)

This commit is contained in:
Matthias Seitz
2024-11-26 12:44:44 +01:00
committed by GitHub
parent 1b4048e47d
commit a28fa243c0
4 changed files with 24 additions and 6 deletions

View File

@ -420,7 +420,10 @@ where
self.pool.get_pooled_transaction_elements(tx_hashes, limit)
}
fn get_pooled_transaction_element(&self, tx_hash: TxHash) -> Option<PooledTransactionsElement> {
fn get_pooled_transaction_element(
&self,
tx_hash: TxHash,
) -> Option<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled> {
self.pool.get_pooled_transaction_element(tx_hash)
}

View File

@ -142,7 +142,7 @@ impl TransactionPool for NoopTransactionPool {
fn get_pooled_transaction_element(
&self,
_tx_hash: TxHash,
) -> Option<PooledTransactionsElement> {
) -> Option<<Self::Transaction as PoolTransaction>::Pooled> {
None
}

View File

@ -373,11 +373,11 @@ where
pub(crate) fn get_pooled_transaction_element(
&self,
tx_hash: TxHash,
) -> Option<PooledTransactionsElement>
) -> Option<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled>
where
<V as TransactionValidator>::Transaction: EthPoolTransaction,
{
self.get(&tx_hash).and_then(|tx| self.to_pooled_transaction(tx).map(Into::into))
self.get(&tx_hash).and_then(|tx| self.to_pooled_transaction(tx))
}
/// Updates the entire pool after a new block was executed.

View File

@ -233,15 +233,30 @@ pub trait TransactionPool: Send + Sync + Clone {
limit: GetPooledTransactionLimit,
) -> Vec<PooledTransactionsElement>;
/// Returns converted [PooledTransactionsElement] for the given transaction hash.
/// Returns the pooled transaction variant 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.
///
/// It is expected that this variant represents the valid p2p format for full transactions.
/// E.g. for EIP-4844 transactions this is the consensus transaction format with the blob
/// sidecar.
///
/// Consumer: P2P
fn get_pooled_transaction_element(&self, tx_hash: TxHash) -> Option<PooledTransactionsElement>;
fn get_pooled_transaction_element(
&self,
tx_hash: TxHash,
) -> Option<<Self::Transaction as PoolTransaction>::Pooled>;
/// Returns the pooled transaction variant for the given transaction hash as the requested type.
fn get_pooled_transaction_as<T>(&self, tx_hash: TxHash) -> Option<T>
where
<Self::Transaction as PoolTransaction>::Pooled: Into<T>,
{
self.get_pooled_transaction_element(tx_hash).map(Into::into)
}
/// Returns an iterator that yields transactions that are ready for block production.
///