mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
Revalidate transactions only on latest best block (#6824)
* Revalidate transactions only on latest best block We should revalidate transactions only on the latest best block and not on any arbitrary block. The revalidation before failed when there were multiple blocks on the height given to the revalidation function, but no block was imported as best block. * Update test-utils/runtime/transaction-pool/src/lib.rs Co-authored-by: Jaco Greeff <jacogr@gmail.com> * Fix tests * Only process best blocks in the transaction pool Co-authored-by: Jaco Greeff <jacogr@gmail.com>
This commit is contained in:
@@ -34,7 +34,7 @@ pub mod testing;
|
||||
pub use sc_transaction_graph as txpool;
|
||||
pub use crate::api::{FullChainApi, LightChainApi};
|
||||
|
||||
use std::{collections::{HashMap, HashSet}, sync::Arc, pin::Pin};
|
||||
use std::{collections::{HashMap, HashSet}, sync::Arc, pin::Pin, convert::TryInto};
|
||||
use futures::{prelude::*, future::{self, ready}, channel::oneshot};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
@@ -549,7 +549,7 @@ impl<PoolApi, Block> MaintainedTransactionPool for BasicPool<PoolApi, Block>
|
||||
{
|
||||
fn maintain(&self, event: ChainEvent<Self::Block>) -> Pin<Box<dyn Future<Output=()> + Send>> {
|
||||
match event {
|
||||
ChainEvent::NewBlock { hash, tree_route, is_new_best, .. } => {
|
||||
ChainEvent::NewBestBlock { hash, tree_route } => {
|
||||
let pool = self.pool.clone();
|
||||
let api = self.api.clone();
|
||||
|
||||
@@ -608,10 +608,7 @@ impl<PoolApi, Block> MaintainedTransactionPool for BasicPool<PoolApi, Block>
|
||||
})
|
||||
}
|
||||
|
||||
// If this is a new best block, we need to prune its transactions from the pool.
|
||||
if is_new_best {
|
||||
pruned_log.extend(prune_known_txs_for_block(id.clone(), &*api, &*pool).await);
|
||||
}
|
||||
pruned_log.extend(prune_known_txs_for_block(id.clone(), &*api, &*pool).await);
|
||||
|
||||
metrics.report(
|
||||
|metrics| metrics.block_transactions_pruned.inc_by(pruned_log.len() as u64)
|
||||
@@ -690,9 +687,9 @@ impl<PoolApi, Block> MaintainedTransactionPool for BasicPool<PoolApi, Block>
|
||||
.map(|tx| tx.hash.clone())
|
||||
.collect();
|
||||
revalidation_queue.revalidate_later(block_number, hashes).await;
|
||||
}
|
||||
|
||||
revalidation_strategy.lock().clear();
|
||||
revalidation_strategy.lock().clear();
|
||||
}
|
||||
}.boxed()
|
||||
}
|
||||
ChainEvent::Finalized { hash } => {
|
||||
@@ -721,7 +718,9 @@ pub async fn notification_future<Client, Pool, Block>(
|
||||
Client: sc_client_api::BlockchainEvents<Block>,
|
||||
Pool: MaintainedTransactionPool<Block=Block>,
|
||||
{
|
||||
let import_stream = client.import_notification_stream().map(Into::into).fuse();
|
||||
let import_stream = client.import_notification_stream()
|
||||
.filter_map(|n| ready(n.try_into().ok()))
|
||||
.fuse();
|
||||
let finality_stream = client.finality_notification_stream()
|
||||
.map(Into::into)
|
||||
.fuse();
|
||||
|
||||
Reference in New Issue
Block a user