reth_transaction_pool::validate

Trait TransactionValidator

Source
pub trait TransactionValidator: Send + Sync {
    type Transaction: PoolTransaction;

    // Required method
    fn validate_transaction(
        &self,
        origin: TransactionOrigin,
        transaction: Self::Transaction,
    ) -> impl Future<Output = TransactionValidationOutcome<Self::Transaction>> + Send;

    // Provided methods
    fn validate_transactions(
        &self,
        transactions: Vec<(TransactionOrigin, Self::Transaction)>,
    ) -> impl Future<Output = Vec<TransactionValidationOutcome<Self::Transaction>>> + Send { ... }
    fn on_new_head_block<H, B>(&self, _new_tip_block: &SealedBlock<H, B>)
       where H: BlockHeader,
             B: BlockBody { ... }
}
Expand description

Provides support for validating transaction at any given state of the chain

Required Associated Types§

Source

type Transaction: PoolTransaction

The transaction type to validate.

Required Methods§

Source

fn validate_transaction( &self, origin: TransactionOrigin, transaction: Self::Transaction, ) -> impl Future<Output = TransactionValidationOutcome<Self::Transaction>> + Send

Validates the transaction and returns a TransactionValidationOutcome describing the validity of the given transaction.

This will be used by the transaction-pool to check whether the transaction should be inserted into the pool or discarded right away.

Implementers of this trait must ensure that the transaction is well-formed, i.e. that it complies at least all static constraints, which includes checking for:

  • chain id
  • gas limit
  • max cost
  • nonce >= next nonce of the sender

See InvalidTransactionError for common errors variants.

The transaction pool makes no additional assumptions about the validity of the transaction at the time of this call before it inserts it into the pool. However, the validity of this transaction is still subject to future (dynamic) changes enforced by the pool, for example nonce or balance changes. Hence, any validation checks must be applied in this function.

See TransactionValidationTaskExecutor for a reference implementation.

Provided Methods§

Source

fn validate_transactions( &self, transactions: Vec<(TransactionOrigin, Self::Transaction)>, ) -> impl Future<Output = Vec<TransactionValidationOutcome<Self::Transaction>>> + Send

Validates a batch of transactions.

Must return all outcomes for the given transactions in the same order.

See also Self::validate_transaction.

Source

fn on_new_head_block<H, B>(&self, _new_tip_block: &SealedBlock<H, B>)
where H: BlockHeader, B: BlockBody,

Invoked when the head block changes.

This can be used to update fork specific values (timestamp).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<A, B> TransactionValidator for Either<A, B>
where A: TransactionValidator, B: TransactionValidator<Transaction = A::Transaction>,

Source§

type Transaction = <A as TransactionValidator>::Transaction

Source§

async fn validate_transaction( &self, origin: TransactionOrigin, transaction: Self::Transaction, ) -> TransactionValidationOutcome<Self::Transaction>

Source§

async fn validate_transactions( &self, transactions: Vec<(TransactionOrigin, Self::Transaction)>, ) -> Vec<TransactionValidationOutcome<Self::Transaction>>

Source§

fn on_new_head_block<H, Body>(&self, new_tip_block: &SealedBlock<H, Body>)
where H: BlockHeader, Body: BlockBody,

Implementors§