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

Fix OurViewChange small race #5356

Merged
merged 3 commits into from
Aug 14, 2024
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
30 changes: 15 additions & 15 deletions polkadot/node/network/bridge/src/rx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,21 @@ fn update_our_view<Context>(
)
};

let our_view = OurView::new(
live_heads.iter().take(MAX_VIEW_HEADS).cloned().map(|a| (a.hash, a.span)),
finalized_number,
);

dispatch_validation_event_to_all_unbounded(
NetworkBridgeEvent::OurViewChange(our_view.clone()),
ctx.sender(),
);

dispatch_collation_event_to_all_unbounded(
NetworkBridgeEvent::OurViewChange(our_view),
ctx.sender(),
);

let v1_validation_peers =
filter_by_peer_version(&validation_peers, ValidationVersion::V1.into());
let v1_collation_peers = filter_by_peer_version(&collation_peers, CollationVersion::V1.into());
Expand Down Expand Up @@ -1007,21 +1022,6 @@ fn update_our_view<Context>(
metrics,
notification_sinks,
);

let our_view = OurView::new(
live_heads.iter().take(MAX_VIEW_HEADS).cloned().map(|a| (a.hash, a.span)),
finalized_number,
);

dispatch_validation_event_to_all_unbounded(
NetworkBridgeEvent::OurViewChange(our_view.clone()),
ctx.sender(),
);

dispatch_collation_event_to_all_unbounded(
NetworkBridgeEvent::OurViewChange(our_view),
ctx.sender(),
);
}

// Handle messages on a specific v1 peer-set. The peer is expected to be connected on that
Expand Down
18 changes: 18 additions & 0 deletions prdoc/pr_5356.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Fix OurViewChange small race

doc:
- audience: Node Dev
description: |
Always queue OurViewChange event before we send view changes to our peers, because otherwise we risk
the peers sending us a message that can be processed by our subsystems before OurViewChange.
Normally, this is not really a problem because the latency of the ViewChange we send to our peers
is way higher than that of our subsystem processing OurViewChange, however on testnets like versi
where CPUs are sometimes overcommitted this race gets triggered occasionally, so let's fix it by
sending the messages in the right order.

crates:
- name: polkadot-network-bridge
bump: minor
Loading