From c3c0f12832e14917cd472cff4855db6e09664994 Mon Sep 17 00:00:00 2001 From: Alexandru Gheorghe Date: Wed, 24 Apr 2024 15:42:35 +0300 Subject: [PATCH 1/2] Fix polkadot parachains not producing blocks until next session ... a few sessions too late :(, this already happened on polkadot, so as of now there are no known relay-chains without async backing enabled in runtime, but let's fix in case someone else wannts to repeat our steps. Signed-off-by: Alexandru Gheorghe --- .../network/statement-distribution/src/v2/mod.rs | 16 +++++++++++++++- .../statement-distribution/src/v2/tests/mod.rs | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/polkadot/node/network/statement-distribution/src/v2/mod.rs b/polkadot/node/network/statement-distribution/src/v2/mod.rs index 68caa5f0e700..3bb64db70ed7 100644 --- a/polkadot/node/network/statement-distribution/src/v2/mod.rs +++ b/polkadot/node/network/statement-distribution/src/v2/mod.rs @@ -826,7 +826,21 @@ pub(crate) fn handle_deactivate_leaves(state: &mut State, leaves: &[Hash]) { // clean up sessions based on everything remaining. let sessions: HashSet<_> = state.per_relay_parent.values().map(|r| r.session).collect(); state.per_session.retain(|s, _| sessions.contains(s)); - state.unused_topologies.retain(|s, _| sessions.contains(s)); + + let last_session_index = state + .unused_topologies + .keys() + .max() + .map(|session_index| *session_index) + .unwrap_or(0); + // Do not clean-up the last saved toplogy unless we moved to the next session + // This is needed because handle_deactive_leaves, gets also called when + // prospective_parachains APIs are not present, so we would actually remove + // the topology without using it because `per_relay_parent` is empty until + // prospective_parachains gets enabled + state + .unused_topologies + .retain(|s, _| sessions.contains(s) || last_session_index == *s); } #[overseer::contextbounds(StatementDistribution, prefix=self::overseer)] diff --git a/polkadot/node/network/statement-distribution/src/v2/tests/mod.rs b/polkadot/node/network/statement-distribution/src/v2/tests/mod.rs index 8dda7219cd12..3d987d3fc433 100644 --- a/polkadot/node/network/statement-distribution/src/v2/tests/mod.rs +++ b/polkadot/node/network/statement-distribution/src/v2/tests/mod.rs @@ -509,6 +509,12 @@ async fn setup_test_and_connect_peers( // Send gossip topology and activate leaf. if send_topology_before_leaf { send_new_topology(overseer, state.make_dummy_topology()).await; + // Send cleaning up of a leaf to make sure it does not clear the save topology as well. + overseer + .send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves( + ActiveLeavesUpdate::stop_work(Hash::random()), + ))) + .await; activate_leaf(overseer, &test_leaf, &state, true, vec![]).await; } else { activate_leaf(overseer, &test_leaf, &state, true, vec![]).await; From 2ffaa42d0bb9a8f5d68308388c15e95055fcffd1 Mon Sep 17 00:00:00 2001 From: Alexandru Gheorghe Date: Wed, 24 Apr 2024 16:56:21 +0300 Subject: [PATCH 2/2] Address review feedback Signed-off-by: Alexandru Gheorghe --- .../node/network/statement-distribution/src/v2/mod.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/polkadot/node/network/statement-distribution/src/v2/mod.rs b/polkadot/node/network/statement-distribution/src/v2/mod.rs index 3bb64db70ed7..118e34e92063 100644 --- a/polkadot/node/network/statement-distribution/src/v2/mod.rs +++ b/polkadot/node/network/statement-distribution/src/v2/mod.rs @@ -827,12 +827,7 @@ pub(crate) fn handle_deactivate_leaves(state: &mut State, leaves: &[Hash]) { let sessions: HashSet<_> = state.per_relay_parent.values().map(|r| r.session).collect(); state.per_session.retain(|s, _| sessions.contains(s)); - let last_session_index = state - .unused_topologies - .keys() - .max() - .map(|session_index| *session_index) - .unwrap_or(0); + let last_session_index = state.unused_topologies.keys().max().copied(); // Do not clean-up the last saved toplogy unless we moved to the next session // This is needed because handle_deactive_leaves, gets also called when // prospective_parachains APIs are not present, so we would actually remove @@ -840,7 +835,7 @@ pub(crate) fn handle_deactivate_leaves(state: &mut State, leaves: &[Hash]) { // prospective_parachains gets enabled state .unused_topologies - .retain(|s, _| sessions.contains(s) || last_session_index == *s); + .retain(|s, _| sessions.contains(s) || last_session_index == Some(*s)); } #[overseer::contextbounds(StatementDistribution, prefix=self::overseer)]