feat(payload builder): transaction pool filter (#10542)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
greged93
2024-10-24 15:13:05 +02:00
committed by GitHub
parent bea6e278df
commit 11149d295e
3 changed files with 32 additions and 2 deletions

View File

@ -208,7 +208,7 @@ pub struct BestTransactionFilter<I, P> {
impl<I, P> BestTransactionFilter<I, P> {
/// Create a new [`BestTransactionFilter`] with the given predicate.
pub(crate) const fn new(best: I, predicate: P) -> Self {
pub const fn new(best: I, predicate: P) -> Self {
Self { best, predicate }
}
}

View File

@ -814,6 +814,36 @@ impl<T> BestTransactions for std::iter::Empty<T> {
fn set_skip_blobs(&mut self, _skip_blobs: bool) {}
}
/// A filter that allows to check if a transaction satisfies a set of conditions
pub trait TransactionFilter {
/// The type of the transaction to check.
type Transaction;
/// Returns true if the transaction satisfies the conditions.
fn is_valid(&self, transaction: &Self::Transaction) -> bool;
}
/// A no-op implementation of [`TransactionFilter`] which
/// marks all transactions as valid.
#[derive(Debug, Clone)]
pub struct NoopTransactionFilter<T>(std::marker::PhantomData<T>);
// We can't derive Default because this forces T to be
// Default as well, which isn't necessary.
impl<T> Default for NoopTransactionFilter<T> {
fn default() -> Self {
Self(std::marker::PhantomData)
}
}
impl<T> TransactionFilter for NoopTransactionFilter<T> {
type Transaction = T;
fn is_valid(&self, _transaction: &Self::Transaction) -> bool {
true
}
}
/// A Helper type that bundles the best transactions attributes together.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct BestTransactionsAttributes {