mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-17 10:22:32 -05:00
tx-pool: rm into tx constraint for PoolTransaction (#10057)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::traits::PoolTransaction;
|
||||
use reth_primitives::{PooledTransactionsElementEcRecovered, U256};
|
||||
use reth_primitives::{PooledTransactionsElementEcRecovered, TransactionSignedEcRecovered, U256};
|
||||
use std::{fmt, marker::PhantomData};
|
||||
|
||||
/// Priority of the transaction that can be missing.
|
||||
@@ -31,7 +31,10 @@ pub trait TransactionOrdering: Send + Sync + 'static {
|
||||
type PriorityValue: Ord + Clone + Default + fmt::Debug + Send + Sync;
|
||||
|
||||
/// The transaction type to determine the priority of.
|
||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
||||
type Transaction: PoolTransaction<
|
||||
Pooled = PooledTransactionsElementEcRecovered,
|
||||
Consensus = TransactionSignedEcRecovered,
|
||||
>;
|
||||
|
||||
/// Returns the priority score for the given transaction.
|
||||
fn priority(
|
||||
@@ -51,7 +54,10 @@ pub struct CoinbaseTipOrdering<T>(PhantomData<T>);
|
||||
|
||||
impl<T> TransactionOrdering for CoinbaseTipOrdering<T>
|
||||
where
|
||||
T: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered> + 'static,
|
||||
T: PoolTransaction<
|
||||
Pooled = PooledTransactionsElementEcRecovered,
|
||||
Consensus = TransactionSignedEcRecovered,
|
||||
> + 'static,
|
||||
{
|
||||
type PriorityValue = U256;
|
||||
type Transaction = T;
|
||||
|
||||
@@ -562,6 +562,10 @@ impl PoolTransaction for MockTransaction {
|
||||
|
||||
type Pooled = PooledTransactionsElementEcRecovered;
|
||||
|
||||
fn into_consensus(self) -> Self::Consensus {
|
||||
self.into()
|
||||
}
|
||||
|
||||
fn from_pooled(pooled: Self::Pooled) -> Self {
|
||||
pooled.into()
|
||||
}
|
||||
|
||||
@@ -42,7 +42,10 @@ pub type PeerId = reth_primitives::B512;
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait TransactionPool: Send + Sync + Clone {
|
||||
/// The transaction type of the pool
|
||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
||||
type Transaction: PoolTransaction<
|
||||
Pooled = PooledTransactionsElementEcRecovered,
|
||||
Consensus = TransactionSignedEcRecovered,
|
||||
>;
|
||||
|
||||
/// Returns stats about the pool and all sub-pools.
|
||||
fn pool_size(&self) -> PoolSize;
|
||||
@@ -484,13 +487,13 @@ pub struct AllPoolTransactions<T: PoolTransaction> {
|
||||
|
||||
impl<T: PoolTransaction> AllPoolTransactions<T> {
|
||||
/// Returns an iterator over all pending [`TransactionSignedEcRecovered`] transactions.
|
||||
pub fn pending_recovered(&self) -> impl Iterator<Item = TransactionSignedEcRecovered> + '_ {
|
||||
self.pending.iter().map(|tx| tx.transaction.clone().into())
|
||||
pub fn pending_recovered(&self) -> impl Iterator<Item = T::Consensus> + '_ {
|
||||
self.pending.iter().map(|tx| tx.transaction.clone().into_consensus())
|
||||
}
|
||||
|
||||
/// Returns an iterator over all queued [`TransactionSignedEcRecovered`] transactions.
|
||||
pub fn queued_recovered(&self) -> impl Iterator<Item = TransactionSignedEcRecovered> + '_ {
|
||||
self.queued.iter().map(|tx| tx.transaction.clone().into())
|
||||
pub fn queued_recovered(&self) -> impl Iterator<Item = T::Consensus> + '_ {
|
||||
self.queued.iter().map(|tx| tx.transaction.clone().into_consensus())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,12 +774,7 @@ impl BestTransactionsAttributes {
|
||||
|
||||
/// Trait for transaction types used inside the pool
|
||||
pub trait PoolTransaction:
|
||||
fmt::Debug
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Clone
|
||||
+ TryFrom<TransactionSignedEcRecovered>
|
||||
+ Into<TransactionSignedEcRecovered>
|
||||
fmt::Debug + Send + Sync + Clone + TryFrom<TransactionSignedEcRecovered>
|
||||
{
|
||||
/// Associated type representing the raw consensus variant of the transaction.
|
||||
type Consensus: From<Self> + TryInto<Self>;
|
||||
@@ -784,6 +782,9 @@ pub trait PoolTransaction:
|
||||
/// Associated type representing the recovered pooled variant of the transaction.
|
||||
type Pooled: Into<Self>;
|
||||
|
||||
/// Define a method to convert from the `Self` type to `Consensus`
|
||||
fn into_consensus(self) -> Self::Consensus;
|
||||
|
||||
/// Define a method to convert from the `Pooled` type to `Self`
|
||||
fn from_pooled(pooled: Self::Pooled) -> Self;
|
||||
|
||||
@@ -884,7 +885,10 @@ pub trait PoolTransaction:
|
||||
/// An extension trait that provides additional interfaces for the
|
||||
/// [`EthTransactionValidator`](crate::EthTransactionValidator).
|
||||
pub trait EthPoolTransaction:
|
||||
PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>
|
||||
PoolTransaction<
|
||||
Pooled = PooledTransactionsElementEcRecovered,
|
||||
Consensus = TransactionSignedEcRecovered,
|
||||
>
|
||||
{
|
||||
/// Extracts the blob sidecar from the transaction.
|
||||
fn take_blob(&mut self) -> EthBlobTransactionSidecar;
|
||||
@@ -1024,6 +1028,10 @@ impl PoolTransaction for EthPooledTransaction {
|
||||
|
||||
type Pooled = PooledTransactionsElementEcRecovered;
|
||||
|
||||
fn into_consensus(self) -> Self::Consensus {
|
||||
self.into()
|
||||
}
|
||||
|
||||
fn from_pooled(pooled: Self::Pooled) -> Self {
|
||||
pooled.into()
|
||||
}
|
||||
|
||||
@@ -154,7 +154,10 @@ impl<T: PoolTransaction> ValidTransaction<T> {
|
||||
/// Provides support for validating transaction at any given state of the chain
|
||||
pub trait TransactionValidator: Send + Sync {
|
||||
/// The transaction type to validate.
|
||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
||||
type Transaction: PoolTransaction<
|
||||
Pooled = PooledTransactionsElementEcRecovered,
|
||||
Consensus = TransactionSignedEcRecovered,
|
||||
>;
|
||||
|
||||
/// Validates the transaction and returns a [`TransactionValidationOutcome`] describing the
|
||||
/// validity of the given transaction.
|
||||
@@ -377,14 +380,16 @@ impl<T: PoolTransaction> ValidPoolTransaction<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PoolTransaction> IntoRecoveredTransaction for ValidPoolTransaction<T> {
|
||||
impl<T: PoolTransaction<Consensus = TransactionSignedEcRecovered>> IntoRecoveredTransaction
|
||||
for ValidPoolTransaction<T>
|
||||
{
|
||||
fn to_recovered_transaction(&self) -> TransactionSignedEcRecovered {
|
||||
self.transaction.clone().into()
|
||||
self.transaction.clone().into_consensus()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<T: PoolTransaction + Clone> Clone for ValidPoolTransaction<T> {
|
||||
impl<T: PoolTransaction> Clone for ValidPoolTransaction<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
transaction: self.transaction.clone(),
|
||||
|
||||
Reference in New Issue
Block a user