Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit f2aa3b3

Browse files
authored
revert to old handle_new_activations logic in some cases (#7514)
* revert to old `handle_new_activations` logic * gate sending messages on scheduled cores to max_depth >= 2 * fmt * 2->1
1 parent 637f0c5 commit f2aa3b3

File tree

2 files changed

+64
-11
lines changed

2 files changed

+64
-11
lines changed

node/collation-generation/src/lib.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ use polkadot_node_subsystem::{
4141
SubsystemContext, SubsystemError, SubsystemResult,
4242
};
4343
use polkadot_node_subsystem_util::{
44-
request_availability_cores, request_persisted_validation_data, request_validation_code,
45-
request_validation_code_hash, request_validators,
44+
request_availability_cores, request_persisted_validation_data,
45+
request_staging_async_backing_params, request_validation_code, request_validation_code_hash,
46+
request_validators,
4647
};
4748
use polkadot_primitives::{
4849
collator_signature_payload, CandidateCommitments, CandidateDescriptor, CandidateReceipt,
@@ -201,29 +202,46 @@ async fn handle_new_activations<Context>(
201202
for relay_parent in activated {
202203
let _relay_parent_timer = metrics.time_new_activations_relay_parent();
203204

204-
let (availability_cores, validators) = join!(
205+
let (availability_cores, validators, async_backing_params) = join!(
205206
request_availability_cores(relay_parent, ctx.sender()).await,
206207
request_validators(relay_parent, ctx.sender()).await,
208+
request_staging_async_backing_params(relay_parent, ctx.sender()).await,
207209
);
208210

209211
let availability_cores = availability_cores??;
210212
let n_validators = validators??.len();
213+
let async_backing_params = async_backing_params?.ok();
211214

212215
for (core_idx, core) in availability_cores.into_iter().enumerate() {
213216
let _availability_core_timer = metrics.time_new_activations_availability_core();
214217

215218
let (scheduled_core, assumption) = match core {
216219
CoreState::Scheduled(scheduled_core) =>
217220
(scheduled_core, OccupiedCoreAssumption::Free),
218-
CoreState::Occupied(occupied_core) => {
219-
// TODO [now]: this assumes that next up == current.
220-
// in practice we should only set `OccupiedCoreAssumption::Included`
221-
// when the candidate occupying the core is also of the same para.
222-
if let Some(scheduled) = occupied_core.next_up_on_available {
223-
(scheduled, OccupiedCoreAssumption::Included)
224-
} else {
221+
CoreState::Occupied(occupied_core) => match async_backing_params {
222+
Some(params) if params.max_candidate_depth >= 1 => {
223+
// maximum candidate depth when building on top of a block
224+
// pending availability is necessarily 1 - the depth of the
225+
// pending block is 0 so the child has depth 1.
226+
227+
// TODO [now]: this assumes that next up == current.
228+
// in practice we should only set `OccupiedCoreAssumption::Included`
229+
// when the candidate occupying the core is also of the same para.
230+
if let Some(scheduled) = occupied_core.next_up_on_available {
231+
(scheduled, OccupiedCoreAssumption::Included)
232+
} else {
233+
continue
234+
}
235+
},
236+
_ => {
237+
gum::trace!(
238+
target: LOG_TARGET,
239+
core_idx = %core_idx,
240+
relay_parent = ?relay_parent,
241+
"core is occupied. Keep going.",
242+
);
225243
continue
226-
}
244+
},
227245
},
228246
CoreState::Free => {
229247
gum::trace!(

node/collation-generation/src/tests.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ fn requests_availability_per_relay_parent() {
151151
Some(AllMessages::RuntimeApi(RuntimeApiMessage::Request(_hash, RuntimeApiRequest::Validators(tx)))) => {
152152
tx.send(Ok(vec![dummy_validator(); 3])).unwrap();
153153
}
154+
Some(AllMessages::RuntimeApi(RuntimeApiMessage::Request(
155+
_hash,
156+
RuntimeApiRequest::StagingAsyncBackingParams(
157+
tx,
158+
),
159+
))) => {
160+
tx.send(Err(RuntimeApiError::NotSupported { runtime_api_name: "doesnt_matter" })).unwrap();
161+
},
154162
Some(msg) => panic!("didn't expect any other overseer requests given no availability cores; got {:?}", msg),
155163
}
156164
}
@@ -225,6 +233,15 @@ fn requests_validation_data_for_scheduled_matches() {
225233
))) => {
226234
tx.send(Ok(vec![dummy_validator(); 3])).unwrap();
227235
},
236+
Some(AllMessages::RuntimeApi(RuntimeApiMessage::Request(
237+
_hash,
238+
RuntimeApiRequest::StagingAsyncBackingParams(tx),
239+
))) => {
240+
tx.send(Err(RuntimeApiError::NotSupported {
241+
runtime_api_name: "doesnt_matter",
242+
}))
243+
.unwrap();
244+
},
228245
Some(msg) => {
229246
panic!("didn't expect any other overseer requests; got {:?}", msg)
230247
},
@@ -313,6 +330,15 @@ fn sends_distribute_collation_message() {
313330
))) => {
314331
tx.send(Ok(Some(ValidationCode(vec![1, 2, 3]).hash()))).unwrap();
315332
},
333+
Some(AllMessages::RuntimeApi(RuntimeApiMessage::Request(
334+
_hash,
335+
RuntimeApiRequest::StagingAsyncBackingParams(tx),
336+
))) => {
337+
tx.send(Err(RuntimeApiError::NotSupported {
338+
runtime_api_name: "doesnt_matter",
339+
}))
340+
.unwrap();
341+
},
316342
Some(msg @ AllMessages::CollatorProtocol(_)) => {
317343
inner_to_collator_protocol.lock().await.push(msg);
318344
},
@@ -466,6 +492,15 @@ fn fallback_when_no_validation_code_hash_api() {
466492
))) => {
467493
tx.send(Ok(Some(ValidationCode(vec![1, 2, 3])))).unwrap();
468494
},
495+
Some(AllMessages::RuntimeApi(RuntimeApiMessage::Request(
496+
_hash,
497+
RuntimeApiRequest::StagingAsyncBackingParams(tx),
498+
))) => {
499+
tx.send(Err(RuntimeApiError::NotSupported {
500+
runtime_api_name: "doesnt_matter",
501+
}))
502+
.unwrap();
503+
},
469504
Some(msg @ AllMessages::CollatorProtocol(_)) => {
470505
inner_to_collator_protocol.lock().await.push(msg);
471506
},

0 commit comments

Comments
 (0)