Skip to content

Commit

Permalink
Remove the prospective-parachains subsystem from collators
Browse files Browse the repository at this point in the history
  • Loading branch information
alindima committed May 15, 2024
1 parent f2b367e commit 9c037e7
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 77 deletions.
58 changes: 35 additions & 23 deletions polkadot/node/network/collator-protocol/src/collator_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ struct State {
/// never included in the fragment chains of active leaves which do. In
/// particular, this means that if a given relay parent belongs to implicit
/// ancestry of some active leaf, then it does support prospective parachains.
implicit_view: ImplicitView,
///
/// It's `None` if the collator is not yet collating for a paraid.
implicit_view: Option<ImplicitView>,

/// All active leaves observed by us, including both that do and do not
/// support prospective parachains. This mapping works as a replacement for
Expand Down Expand Up @@ -334,7 +336,7 @@ impl State {
metrics,
collating_on: Default::default(),
peer_data: Default::default(),
implicit_view: Default::default(),
implicit_view: None,
active_leaves: Default::default(),
per_relay_parent: Default::default(),
span_per_relay_parent: Default::default(),
Expand Down Expand Up @@ -539,11 +541,12 @@ async fn distribute_collation<Context>(
.filter(|(_, PeerData { view: v, .. })| match relay_parent_mode {
ProspectiveParachainsMode::Disabled => v.contains(&candidate_relay_parent),
ProspectiveParachainsMode::Enabled { .. } => v.iter().any(|block_hash| {
state
.implicit_view
.known_allowed_relay_parents_under(block_hash, Some(id))
.unwrap_or_default()
.contains(&candidate_relay_parent)
state.implicit_view.as_ref().map(|implicit_view| {
implicit_view
.known_allowed_relay_parents_under(block_hash, Some(id))
.unwrap_or_default()
.contains(&candidate_relay_parent)
}) == Some(true)
}),
});

Expand Down Expand Up @@ -830,6 +833,7 @@ async fn process_msg<Context>(
match msg {
CollateOn(id) => {
state.collating_on = Some(id);
state.implicit_view = Some(ImplicitView::new(Some(id)));
},
DistributeCollation {
candidate_receipt,
Expand Down Expand Up @@ -1215,7 +1219,10 @@ async fn handle_peer_view_change<Context>(
Some(ProspectiveParachainsMode::Disabled) => std::slice::from_ref(&added),
Some(ProspectiveParachainsMode::Enabled { .. }) => state
.implicit_view
.known_allowed_relay_parents_under(&added, state.collating_on)
.as_ref()
.and_then(|implicit_view| {
implicit_view.known_allowed_relay_parents_under(&added, state.collating_on)
})
.unwrap_or_default(),
None => {
gum::trace!(
Expand Down Expand Up @@ -1353,21 +1360,22 @@ where
state.per_relay_parent.insert(*leaf, PerRelayParent::new(mode));

if mode.is_enabled() {
state
.implicit_view
.activate_leaf(sender, *leaf)
.await
.map_err(Error::ImplicitViewFetchError)?;
if let Some(ref mut implicit_view) = state.implicit_view {
implicit_view
.activate_leaf(sender, *leaf)
.await
.map_err(Error::ImplicitViewFetchError)?;

let allowed_ancestry = state
.implicit_view
.known_allowed_relay_parents_under(leaf, state.collating_on)
.unwrap_or_default();
for block_hash in allowed_ancestry {
state
.per_relay_parent
.entry(*block_hash)
.or_insert_with(|| PerRelayParent::new(mode));
let allowed_ancestry = implicit_view
.known_allowed_relay_parents_under(leaf, state.collating_on)
.unwrap_or_default();

for block_hash in allowed_ancestry {
state
.per_relay_parent
.entry(*block_hash)
.or_insert_with(|| PerRelayParent::new(mode));
}
}
}
}
Expand All @@ -1378,7 +1386,11 @@ where
// of implicit ancestry. Only update the state after the hash is actually
// pruned from the block info storage.
let pruned = if mode.is_enabled() {
state.implicit_view.deactivate_leaf(*leaf)
state
.implicit_view
.as_mut()
.map(|view| view.deactivate_leaf(*leaf))
.unwrap_or_default()
} else {
vec![*leaf]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ async fn update_view(

let min_number = leaf_number.saturating_sub(ASYNC_BACKING_PARAMETERS.allowed_ancestry_len);

assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::ProspectiveParachains(
ProspectiveParachainsMessage::GetMinimumRelayParents(parent, tx),
) if parent == leaf_hash => {
tx.send(vec![(test_state.para_id, min_number)]).unwrap();
}
);
// assert_matches!(
// overseer_recv(virtual_overseer).await,
// AllMessages::ProspectiveParachains(
// ProspectiveParachainsMessage::GetMinimumRelayParents(parent, tx),
// ) if parent == leaf_hash => {
// tx.send(vec![(test_state.para_id, min_number)]).unwrap();
// }
// );

let ancestry_len = leaf_number + 1 - min_number;
let ancestry_hashes = std::iter::successors(Some(leaf_hash), |h| Some(get_parent_hash(*h)))
Expand Down
4 changes: 2 additions & 2 deletions polkadot/node/service/src/overseer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub fn collator_overseer_builder<Spawner, RuntimeClient>(
DummySubsystem,
DummySubsystem,
DummySubsystem,
ProspectiveParachainsSubsystem,
DummySubsystem,
>,
Error,
>
Expand Down Expand Up @@ -462,7 +462,7 @@ where
.dispute_coordinator(DummySubsystem)
.dispute_distribution(DummySubsystem)
.chain_selection(DummySubsystem)
.prospective_parachains(ProspectiveParachainsSubsystem::new(Metrics::register(registry)?))
.prospective_parachains(DummySubsystem)
.activation_external_listeners(Default::default())
.span_per_active_leaf(Default::default())
.active_leaves(Default::default())
Expand Down
Loading

0 comments on commit 9c037e7

Please sign in to comment.