Trait TransactionValidator
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(&self, _new_tip_block: &SealedBlock) { ... }
}
Expand description
Provides support for validating transaction at any given state of the chain
Required Associated Types§
type Transaction: PoolTransaction
type Transaction: PoolTransaction
The transaction type to validate.
Required Methods§
fn validate_transaction(
&self,
origin: TransactionOrigin,
transaction: Self::Transaction,
) -> impl Future<Output = TransactionValidationOutcome<Self::Transaction>> + Send
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§
fn validate_transactions(
&self,
transactions: Vec<(TransactionOrigin, Self::Transaction)>,
) -> impl Future<Output = Vec<TransactionValidationOutcome<Self::Transaction>>> + Send
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
.
fn on_new_head_block(&self, _new_tip_block: &SealedBlock)
fn on_new_head_block(&self, _new_tip_block: &SealedBlock)
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.