Skip to content

Abstract txpool, decoupling it from reth #513

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions crates/op-rbuilder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod primitives;
mod tester;
mod tx_signer;
use monitor_tx_pool::monitor_tx_pool;
mod txpool_trait;

fn main() {
Cli::<OpChainSpecParser, args::OpRbuilderArgs>::parse()
Expand Down
9 changes: 5 additions & 4 deletions crates/op-rbuilder/src/payload_builder_vanilla.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::txpool_trait::BuilderTransactionPool;
use crate::{
generator::{BlockCell, BlockPayloadJobGenerator, BuildArguments, PayloadBuilder},
metrics::OpRBuilderMetrics,
Expand Down Expand Up @@ -772,30 +773,30 @@ impl<Txs> OpBuilder<'_, Txs> {
pub trait OpPayloadTransactions<Transaction>: Clone + Send + Sync + Unpin + 'static {
/// Returns an iterator that yields the transaction in the order they should get included in the
/// new payload.
fn best_transactions<Pool: TransactionPool<Transaction = Transaction>>(
fn best_transactions<Pool: BuilderTransactionPool<Transaction = Transaction>>(
&self,
pool: Pool,
attr: BestTransactionsAttributes,
) -> impl PayloadTransactions<Transaction = Transaction>;

/// Removes invalid transactions from the tx pool
fn remove_invalid<Pool: TransactionPool<Transaction = Transaction>>(
fn remove_invalid<Pool: BuilderTransactionPool<Transaction = Transaction>>(
&self,
pool: Pool,
hashes: Vec<TxHash>,
);
}

impl<T: PoolTransaction> OpPayloadTransactions<T> for () {
fn best_transactions<Pool: TransactionPool<Transaction = T>>(
fn best_transactions<Pool: BuilderTransactionPool<Transaction = T>>(
&self,
pool: Pool,
attr: BestTransactionsAttributes,
) -> impl PayloadTransactions<Transaction = T> {
BestPayloadTransactions::new(pool.best_transactions_with_attributes(attr))
}

fn remove_invalid<Pool: TransactionPool<Transaction = T>>(
fn remove_invalid<Pool: BuilderTransactionPool<Transaction = T>>(
&self,
pool: Pool,
hashes: Vec<TxHash>,
Expand Down
46 changes: 46 additions & 0 deletions crates/op-rbuilder/src/txpool_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use alloy_primitives::TxHash;
use reth_transaction_pool::TransactionPool;
use reth_transaction_pool::{
BestTransactions, BestTransactionsAttributes, EthPoolTransaction, ValidPoolTransaction,
};
use std::sync::Arc;

pub trait BuilderTransactionPool: Send + Sync + Clone {
/// The transaction type of the pool
type Transaction: EthPoolTransaction;

/// Returns an iterator that yields transactions that are ready for block production with the
/// given base fee and optional blob fee attributes.
///
/// Consumer: Block production
fn best_transactions_with_attributes(
&self,
best_transactions_attributes: BestTransactionsAttributes,
) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>>;

/// Removes all transactions corresponding to the given hashes.
///
/// Consumer: Utility
fn remove_transactions(
&self,
hashes: Vec<TxHash>,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
}

impl<T: TransactionPool> BuilderTransactionPool for T {
type Transaction = T::Transaction;

fn best_transactions_with_attributes(
&self,
best_transactions_attributes: BestTransactionsAttributes,
) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {
TransactionPool::best_transactions_with_attributes(self, best_transactions_attributes)
}

fn remove_transactions(
&self,
hashes: Vec<TxHash>,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
TransactionPool::remove_transactions(self, hashes)
}
}
Loading