Skip to content

Commit

Permalink
Properly report the best parablock in block announces handshakes (#1012)
Browse files Browse the repository at this point in the history
* Properly report the best parablock in block announces handshakes

* PR link
  • Loading branch information
tomaka authored Aug 10, 2023
1 parent 726dd51 commit 9fc9c65
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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 @@ -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))

Expand Down

0 comments on commit 9fc9c65

Please sign in to comment.