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

collation-generation: Avoid using para_backing_state if runtime is ancient #4070

Merged
merged 8 commits into from
Apr 11, 2024
Merged
Changes from 1 commit
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
68 changes: 48 additions & 20 deletions polkadot/node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ async fn handle_new_activations<Context>(
if config.collator.is_none() {
return Ok(())
}

// If there is no collation function provided, bail out early.
// Important: Lookahead collator and slot based collator do not use `CollatorFn`.
if config.collator.is_none() {
return Ok(())
}

let para_id = config.para_id;

let _overall_timer = metrics.time_new_activations();
Expand All @@ -232,9 +239,14 @@ async fn handle_new_activations<Context>(
// The loop bellow will fill in cores that the para is allowed to build on.
let mut cores_to_build_on = Vec::new();

// This assumption refers to all cores of the parachain, taking elastic scaling
// into account.
let mut para_assumption = None;
for (core_idx, core) in availability_cores.into_iter().enumerate() {
let scheduled_core = match core {
CoreState::Scheduled(scheduled_core) => scheduled_core,
// This nested assumption refers only to the core being iterated.
let (core_assumption, scheduled_core) = match core {
CoreState::Scheduled(scheduled_core) =>
(OccupiedCoreAssumption::Free, scheduled_core),
CoreState::Occupied(occupied_core) => match async_backing_params {
Some(params) if params.max_candidate_depth >= 1 => {
// maximum candidate depth when building on top of a block
Expand All @@ -257,7 +269,7 @@ async fn handle_new_activations<Context>(
};

match res {
Some(res) => res,
Some(res) => (OccupiedCoreAssumption::Included, res),
None => continue,
}
},
Expand Down Expand Up @@ -291,6 +303,10 @@ async fn handle_new_activations<Context>(
"core is not assigned to our para. Keep going.",
);
} else {
// This does not work for elastic scaling, but it should be enough for single
// core parachains. If async backing runtime is available we later override
// the assumption based on the `para_backing_state` API response.
para_assumption = Some(core_assumption);
// Accumulate cores for building collation(s) outside the loop.
cores_to_build_on.push(CoreIndex(core_idx as u32));
}
Expand All @@ -301,34 +317,46 @@ async fn handle_new_activations<Context>(
continue
}

let para_backing_state =
request_para_backing_state(relay_parent, config.para_id, ctx.sender())
.await
.await??
.ok_or(crate::error::Error::MissingParaBackingState)?;

// We are being very optimistic here, but one of the cores could pend availability some more
// block, ore even time out.
// For timeout assumption the collator can't really know because it doesn't receive bitfield
// gossip.
let assumption = if para_backing_state.pending_availability.is_empty() {
OccupiedCoreAssumption::Free
} else {
OccupiedCoreAssumption::Included
// If at least one core is assigned to us, `para_assumption` is `Some`.
let Some(mut para_assumption) = para_assumption else { continue };

match async_backing_params {
// We are being very optimistic here, but one of the cores could pend availability some
// more block, ore even time out.
// For timeout assumption the collator can't really know because it doesn't receive
// bitfield gossip.
Some(_) => {
let para_backing_state = request_para_backing_state(relay_parent, config.para_id, ctx.sender())
.await
.await??
.ok_or(crate::error::Error::MissingParaBackingState)?;

// Override the assumption about the para's assigned cores.
para_assumption = if para_backing_state.pending_availability.is_empty() {
OccupiedCoreAssumption::Free
} else {
OccupiedCoreAssumption::Included
}
},
None => {
// If we are here it means that neither async backing or elastic scaling (which
// depends on it) are supported. We'll use the `para_assumption` we got from
// iterating cores.
},
};

gum::debug!(
target: LOG_TARGET,
relay_parent = ?relay_parent,
our_para = %config.para_id,
?assumption,
?para_assumption,
"Occupied core(s) assumption",
);

let mut validation_data = match request_persisted_validation_data(
relay_parent,
config.para_id,
assumption,
para_assumption,
ctx.sender(),
)
.await
Expand All @@ -349,7 +377,7 @@ async fn handle_new_activations<Context>(
let validation_code_hash = match obtain_validation_code_hash_with_assumption(
relay_parent,
config.para_id,
assumption,
para_assumption,
ctx.sender(),
)
.await?
Expand Down
Loading