From 3e928cb54e702beef0f1a2afa51608d631400581 Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 22 Jun 2023 05:58:56 +0800 Subject: [PATCH] Skip processing needless block in the bundle validator We only keep track of the state of the last K blocks, if there are more than K blocks left to process we can skip some blocks as their result will simply be dumpped after processing, this also help to prevent the bundle validator from stuck on some pruned blocks because these block will be skip as the chain grows. Signed-off-by: linning --- crates/subspace-transaction-pool/src/bundle_validator.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/subspace-transaction-pool/src/bundle_validator.rs b/crates/subspace-transaction-pool/src/bundle_validator.rs index d96e0fd4b5..a1607be152 100644 --- a/crates/subspace-transaction-pool/src/bundle_validator.rs +++ b/crates/subspace-transaction-pool/src/bundle_validator.rs @@ -140,8 +140,12 @@ where } } - // Add bundles from the new block of the best fork - for enacted_block in enacted { + // Add bundles from the new block of the best fork, only need to process at most the last K + // blocks as the result of other blocks will be dumpped immediately, this also help to prevent + // the bundle validator from stuck on some pruned blocks because these blocks will be skip as + // the chain grows. + let needless_block = enacted.len().saturating_sub(self.confirm_depth_k); + for enacted_block in enacted.iter().skip(needless_block) { let bundles = self.successfully_submitted_bundles_at(enacted_block.hash)?; bundle_stored_in_last_k.push_front(BlockBundle::new( enacted_block.hash,