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: use Pooled type for get_pooled_transaction_element in pool trait #12867

Merged
merged 3 commits into from
Nov 26, 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
5 changes: 4 additions & 1 deletion crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 17 additions & 2 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Loading