mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 08:37:59 -05:00
tx-pool: rm constraint for PoolTransaction (#10024)
This commit is contained in:
@@ -1004,7 +1004,7 @@ where
|
||||
Entry::Vacant(entry) => {
|
||||
if !self.bad_imports.contains(tx.hash()) {
|
||||
// this is a new transaction that should be imported into the pool
|
||||
let pool_transaction: Pool::Transaction = tx.into();
|
||||
let pool_transaction = Pool::Transaction::from_pooled(tx);
|
||||
new_txs.push(pool_transaction);
|
||||
|
||||
entry.insert(HashSet::from([peer_id]));
|
||||
|
||||
@@ -250,7 +250,8 @@ pub trait EthTransactions: LoadTransaction {
|
||||
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
|
||||
async move {
|
||||
let recovered = recover_raw_transaction(tx.clone())?;
|
||||
let pool_transaction: <Self::Pool as TransactionPool>::Transaction = recovered.into();
|
||||
let pool_transaction =
|
||||
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);
|
||||
|
||||
// On optimism, transactions are forwarded directly to the sequencer to be included in
|
||||
// blocks that it builds.
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
error::PoolError,
|
||||
metrics::MaintainPoolMetrics,
|
||||
traits::{CanonicalStateUpdate, ChangedAccount, TransactionPool, TransactionPoolExt},
|
||||
BlockInfo,
|
||||
BlockInfo, PoolTransaction,
|
||||
};
|
||||
use futures_util::{
|
||||
future::{BoxFuture, Fuse, FusedFuture},
|
||||
@@ -331,7 +331,9 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
.map(Into::into)
|
||||
.map(|tx| {
|
||||
<<P as TransactionPool>::Transaction as PoolTransaction>::from_pooled(tx)
|
||||
})
|
||||
} else {
|
||||
tx.try_into().ok()
|
||||
}
|
||||
@@ -674,7 +676,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
blobstore::InMemoryBlobStore, validate::EthTransactionValidatorBuilder,
|
||||
CoinbaseTipOrdering, EthPooledTransaction, Pool, PoolTransaction, TransactionOrigin,
|
||||
CoinbaseTipOrdering, EthPooledTransaction, Pool, TransactionOrigin,
|
||||
};
|
||||
use reth_chainspec::MAINNET;
|
||||
use reth_fs_util as fs;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::traits::PoolTransaction;
|
||||
use reth_primitives::U256;
|
||||
use reth_primitives::{PooledTransactionsElementEcRecovered, U256};
|
||||
use std::{fmt, marker::PhantomData};
|
||||
|
||||
/// Priority of the transaction that can be missing.
|
||||
@@ -31,7 +31,7 @@ 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;
|
||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
||||
|
||||
/// Returns the priority score for the given transaction.
|
||||
fn priority(
|
||||
@@ -51,7 +51,7 @@ pub struct CoinbaseTipOrdering<T>(PhantomData<T>);
|
||||
|
||||
impl<T> TransactionOrdering for CoinbaseTipOrdering<T>
|
||||
where
|
||||
T: PoolTransaction + 'static,
|
||||
T: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered> + 'static,
|
||||
{
|
||||
type PriorityValue = U256;
|
||||
type Transaction = T;
|
||||
|
||||
@@ -562,6 +562,10 @@ impl PoolTransaction for MockTransaction {
|
||||
|
||||
type Pooled = PooledTransactionsElementEcRecovered;
|
||||
|
||||
fn from_pooled(pooled: Self::Pooled) -> Self {
|
||||
pooled.into()
|
||||
}
|
||||
|
||||
fn hash(&self) -> &TxHash {
|
||||
match self {
|
||||
Self::Legacy { hash, .. } |
|
||||
|
||||
@@ -41,7 +41,7 @@ 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;
|
||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
||||
|
||||
/// Returns stats about the pool and all sub-pools.
|
||||
fn pool_size(&self) -> PoolSize;
|
||||
@@ -759,7 +759,6 @@ pub trait PoolTransaction:
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Clone
|
||||
+ From<PooledTransactionsElementEcRecovered>
|
||||
+ TryFrom<TransactionSignedEcRecovered>
|
||||
+ Into<TransactionSignedEcRecovered>
|
||||
{
|
||||
@@ -769,6 +768,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 `Pooled` type to `Self`
|
||||
fn from_pooled(pooled: Self::Pooled) -> Self;
|
||||
|
||||
/// Hash of the transaction.
|
||||
fn hash(&self) -> &TxHash;
|
||||
|
||||
@@ -865,7 +867,9 @@ pub trait PoolTransaction:
|
||||
|
||||
/// An extension trait that provides additional interfaces for the
|
||||
/// [`EthTransactionValidator`](crate::EthTransactionValidator).
|
||||
pub trait EthPoolTransaction: PoolTransaction {
|
||||
pub trait EthPoolTransaction:
|
||||
PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>
|
||||
{
|
||||
/// Extracts the blob sidecar from the transaction.
|
||||
fn take_blob(&mut self) -> EthBlobTransactionSidecar;
|
||||
|
||||
@@ -1004,6 +1008,10 @@ impl PoolTransaction for EthPooledTransaction {
|
||||
|
||||
type Pooled = PooledTransactionsElementEcRecovered;
|
||||
|
||||
fn from_pooled(pooled: Self::Pooled) -> Self {
|
||||
pooled.into()
|
||||
}
|
||||
|
||||
/// Returns hash of the transaction.
|
||||
fn hash(&self) -> &TxHash {
|
||||
self.transaction.hash_ref()
|
||||
|
||||
@@ -6,8 +6,9 @@ use crate::{
|
||||
traits::{PoolTransaction, TransactionOrigin},
|
||||
};
|
||||
use reth_primitives::{
|
||||
Address, BlobTransactionSidecar, IntoRecoveredTransaction, SealedBlock,
|
||||
TransactionSignedEcRecovered, TxHash, B256, U256,
|
||||
Address, BlobTransactionSidecar, IntoRecoveredTransaction,
|
||||
PooledTransactionsElementEcRecovered, SealedBlock, TransactionSignedEcRecovered, TxHash, B256,
|
||||
U256,
|
||||
};
|
||||
use std::{fmt, future::Future, time::Instant};
|
||||
|
||||
@@ -152,7 +153,7 @@ 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;
|
||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
||||
|
||||
/// Validates the transaction and returns a [`TransactionValidationOutcome`] describing the
|
||||
/// validity of the given transaction.
|
||||
|
||||
Reference in New Issue
Block a user