mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Quickly skip invalid transactions during block authorship. (#9789)
* Support skipping invalid transactions in the iterator. * Expose concrete iterator. * cargo +nightly fmt --all * More consistent placement. * Update Cargo.lock * Pass transaction to 'report_invalid'
This commit is contained in:
@@ -223,13 +223,14 @@ pub trait TransactionPool: Send + Sync {
|
||||
at: NumberFor<Self::Block>,
|
||||
) -> Pin<
|
||||
Box<
|
||||
dyn Future<Output = Box<dyn Iterator<Item = Arc<Self::InPoolTransaction>> + Send>>
|
||||
+ Send,
|
||||
dyn Future<
|
||||
Output = Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send>,
|
||||
> + Send,
|
||||
>,
|
||||
>;
|
||||
|
||||
/// Get an iterator for ready transactions ordered by priority.
|
||||
fn ready(&self) -> Box<dyn Iterator<Item = Arc<Self::InPoolTransaction>> + Send>;
|
||||
fn ready(&self) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send>;
|
||||
|
||||
// *** Block production
|
||||
/// Remove transactions identified by given hashes (and dependent transactions) from the pool.
|
||||
@@ -254,6 +255,27 @@ pub trait TransactionPool: Send + Sync {
|
||||
fn ready_transaction(&self, hash: &TxHash<Self>) -> Option<Arc<Self::InPoolTransaction>>;
|
||||
}
|
||||
|
||||
/// An iterator of ready transactions.
|
||||
///
|
||||
/// The trait extends regular [`std::iter::Iterator`] trait and allows reporting
|
||||
/// last-returned element as invalid.
|
||||
///
|
||||
/// The implementation is then allowed, for performance reasons, to change the elements
|
||||
/// returned next, by e.g. skipping elements that are known to depend on the reported
|
||||
/// transaction, which yields them invalid as well.
|
||||
pub trait ReadyTransactions: Iterator {
|
||||
/// Report given transaction as invalid.
|
||||
///
|
||||
/// This might affect subsequent elements returned by the iterator, so dependent transactions
|
||||
/// are skipped for performance reasons.
|
||||
fn report_invalid(&mut self, _tx: &Self::Item);
|
||||
}
|
||||
|
||||
/// A no-op implementation for an empty iterator.
|
||||
impl<T> ReadyTransactions for std::iter::Empty<T> {
|
||||
fn report_invalid(&mut self, _tx: &T) {}
|
||||
}
|
||||
|
||||
/// Events that the transaction pool listens for.
|
||||
pub enum ChainEvent<B: BlockT> {
|
||||
/// New best block have been added to the chain
|
||||
|
||||
Reference in New Issue
Block a user