From 127ea7dff3f34cfc2fdc81c95038abe04cd46554 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 2 May 2024 11:44:30 +0200 Subject: [PATCH] Assume that all parachain peers know all paraheads (#1812) * Assume that all parachain peers know all paraheads * PR link --- light-base/src/sync_service/parachain.rs | 43 ++++++++++++++++++------ wasm-node/CHANGELOG.md | 4 +++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/light-base/src/sync_service/parachain.rs b/light-base/src/sync_service/parachain.rs index d27bb9bb2b..508364cb91 100644 --- a/light-base/src/sync_service/parachain.rs +++ b/light-base/src/sync_service/parachain.rs @@ -1225,18 +1225,34 @@ impl ParachainBackgroundTask { block_number, block_hash, }), - _, + runtime_subscription, ) => { - // If `block_number` is over the finalized block, then which source knows which - // block is precisely tracked. Otherwise, it is assumed that all sources are on - // the finalized chain and thus that all sources whose best block is superior - // to `block_number` have it. - let list = if block_number > self.sync_sources.finalized_block_height() { - self.sync_sources - .knows_non_finalized_block(block_number, &block_hash) - .map(|local_id| self.sync_sources[local_id].0.clone()) - .collect() - } else { + // If `block_number` is inferior or equal to the finalized block, or that + // it is a parahead of the relay chain, then we assume that all parachain + // nodes know this block. + // Otherwise, which source knows which block is precisely tracked. + let any_source_goes = + if block_number > self.sync_sources.finalized_block_height() { + if let ParachainBackgroundState::Subscribed(runtime_subscription) = + runtime_subscription + { + runtime_subscription + .async_tree + .input_output_iter_unordered() + .filter_map(|item| item.async_op_user_data) + .filter_map(|block| block.as_ref()) + .any(|item| { + // TODO: CPU-expensive + header::hash_from_scale_encoded_header(item) == block_hash + }) + } else { + false + } + } else { + true + }; + + let list = if any_source_goes { self.sync_sources .keys() .filter(|local_id| { @@ -1244,6 +1260,11 @@ impl ParachainBackgroundTask { }) .map(|local_id| self.sync_sources[local_id].0.clone()) .collect() + } else { + self.sync_sources + .knows_non_finalized_block(block_number, &block_hash) + .map(|local_id| self.sync_sources[local_id].0.clone()) + .collect() }; let _ = send_back.send(list); diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index 6bf30f1e4b..a589552ffe 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Changed + +- When it comes to determining which peers know which block, smoldot now assumes that all parachain nodes know all paraheads found in the relay chain. This solves some issues when. ([#1812](https://github.com/smol-dot/smoldot/pull/1812)) + ## 2.0.25 - 2024-04-29 ### Changed