Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly report the best parablock in block announces handshakes #1012

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions light-base/src/sync_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl<TPlat: PlatformRef> SyncService<TPlat> {
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,
)),
Expand Down
33 changes: 33 additions & 0 deletions light-base/src/sync_service/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub(super) async fn start_parachain<TPlat: PlatformRef>(
relay_chain_block_number_bytes: usize,
parachain_id: u32,
from_foreground: async_channel::Receiver<ToBackground>,
network_service: Arc<network_service::NetworkService<TPlat>>,
network_chain_index: usize,
from_network_service: stream::BoxStream<'static, network_service::Event>,
) {
Expand All @@ -58,6 +59,7 @@ pub(super) async fn start_parachain<TPlat: PlatformRef>(
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(
Expand Down Expand Up @@ -117,6 +119,9 @@ struct ParachainBackgroundTask<TPlat: PlatformRef> {
/// 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<network_service::NetworkService<TPlat>>,

/// Index of the chain within the associated network service.
///
/// Used to filter events from [`ParachainBackgroundTask::from_network_service`].
Expand Down Expand Up @@ -924,6 +929,20 @@ impl<TPlat: PlatformRef> ParachainBackgroundTask<TPlat> {
{
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={})",
Expand Down Expand Up @@ -980,6 +999,20 @@ impl<TPlat: PlatformRef> ParachainBackgroundTask<TPlat> {
{
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={})",
Expand Down
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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))

## 1.0.15 - 2023-08-08
Expand Down