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