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§
Sourcetype Transaction: PoolTransaction
type Transaction: PoolTransaction
The transaction type to validate.
Required Methods§
Sourcefn 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§
Sourcefn 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
.
Sourcefn on_new_head_block<H, B>(&self, _new_tip_block: &SealedBlock<H, B>)where
H: BlockHeader,
B: BlockBody,
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.