From 9fc9c65c8ae853233337bdd3e483269187c82ef1 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 10 Aug 2023 15:40:46 +0000 Subject: [PATCH] Properly report the best parablock in block announces handshakes (#1012) * Properly report the best parablock in block announces handshakes * PR link --- light-base/src/sync_service.rs | 1 + light-base/src/sync_service/parachain.rs | 33 ++++++++++++++++++++++++ wasm-node/CHANGELOG.md | 1 + 3 files changed, 35 insertions(+) diff --git a/light-base/src/sync_service.rs b/light-base/src/sync_service.rs index b379b2980d..17b7ffbb3e 100644 --- a/light-base/src/sync_service.rs +++ b/light-base/src/sync_service.rs @@ -165,6 +165,7 @@ impl SyncService { config_parachain.relay_chain_block_number_bytes, config_parachain.parachain_id, from_foreground, + config.network_service.0.clone(), config.network_service.1, config.network_events_receiver, )), diff --git a/light-base/src/sync_service/parachain.rs b/light-base/src/sync_service/parachain.rs index 68a6773003..792ad9d15b 100644 --- a/light-base/src/sync_service/parachain.rs +++ b/light-base/src/sync_service/parachain.rs @@ -49,6 +49,7 @@ pub(super) async fn start_parachain( relay_chain_block_number_bytes: usize, parachain_id: u32, from_foreground: async_channel::Receiver, + network_service: Arc>, network_chain_index: usize, from_network_service: stream::BoxStream<'static, network_service::Event>, ) { @@ -58,6 +59,7 @@ pub(super) async fn start_parachain( block_number_bytes, relay_chain_block_number_bytes, parachain_id, + network_service, network_chain_index, from_network_service: from_network_service.fuse(), sync_sources: sources::AllForksSources::new( @@ -117,6 +119,9 @@ struct ParachainBackgroundTask { /// Id of the parachain registered within the relay chain. Chosen by the user. parachain_id: u32, + /// Networking service connected to the peer-to-peer network of the parachain. + network_service: Arc>, + /// Index of the chain within the associated network service. /// /// Used to filter events from [`ParachainBackgroundTask::from_network_service`]. @@ -924,6 +929,20 @@ impl ParachainBackgroundTask { { runtime_subscription.reported_best_parahead_hash = Some(parahash); + // The networking service needs to be kept up to date with what the local + // node considers as the best block. + if let Ok(header) = + header::decode(finalized_parahead, self.block_number_bytes) + { + self.network_service + .set_local_best_block( + self.network_chain_index, + parahash, + header.number, + ) + .await; + } + log::debug!( target: &self.log_target, "Subscriptions <= BestBlockChanged(hash={})", @@ -980,6 +999,20 @@ impl ParachainBackgroundTask { { runtime_subscription.reported_best_parahead_hash = Some(parahash); + // The networking service needs to be kept up to date with what the + // local node considers as the best block. + if let Ok(header) = + header::decode(finalized_parahead, self.block_number_bytes) + { + self.network_service + .set_local_best_block( + self.network_chain_index, + parahash, + header.number, + ) + .await; + } + log::debug!( target: &self.log_target, "Subscriptions <= BestBlockChanged(hash={})", diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index dbbb1b5003..47ffaaef07 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed +- The block announces substream handshake of a parachain peer-to-peer network now properly contains the block that smoldot thinks is the best. The genesis block was previously always reported. ([#1012](https://github.com/smol-dot/smoldot/pull/1012)) - Fix panic when removing a chain while a networking connection is being opened. ([#1011](https://github.com/smol-dot/smoldot/pull/1011)) - Fix epoch start slot calculation when epochs have been skipped. ([#1015](https://github.com/smol-dot/smoldot/pull/1015))