Skip to content
Open
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
20 changes: 19 additions & 1 deletion cumulus/client/consensus/aura/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,23 @@ where
},
};

let session_index = match params
.relay_client
.session_index_for_child(relay_parent)
.await
{
Ok(session_index) => session_index,
Err(err) => {
tracing::error!(
target: crate::LOG_TARGET,
?err,
?relay_parent,
"Failed to fetch session index."
);
continue;
},
};

let parent_search_result = match crate::collators::find_parent(
relay_parent,
params.para_id,
Expand Down Expand Up @@ -501,11 +518,12 @@ where
SubmitCollationParams {
relay_parent,
collation,
parent_head: parent_header.encode().into(),
validation_code_hash,
result_sender: None,
core_index,
scheduling_parent: None,
session_index,
validation_data,
},
),
"SubmitCollation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ where
parachain_candidate: candidate.into(),
validation_code_hash,
core_index: core.core_index(),
max_pov_size: validation_data.max_pov_size,
validation_data,
}) {
tracing::error!(target: crate::LOG_TARGET, ?err, "Unable to send block to collation task.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <https://www.gnu.org/licenses/>.

use codec::Encode;
use std::path::PathBuf;

use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface;
Expand Down Expand Up @@ -126,7 +125,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface +
validation_code_hash,
relay_parent,
core_index,
max_pov_size,
validation_data,
} = message;

let hash = parachain_candidate.block.header().hash();
Expand Down Expand Up @@ -156,7 +155,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface +
parent_header.clone(),
relay_parent_header.state_root,
relay_parent_header.number,
max_pov_size,
validation_data.max_pov_size,
);
}
} else {
Expand All @@ -171,18 +170,32 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface +
);
}

let session_index = match relay_client.session_index_for_child(relay_parent).await {
Ok(session_index) => session_index,
Err(err) => {
tracing::error!(
target: LOG_TARGET,
?err,
?relay_parent,
"Failed to fetch session index."
);
return;
},
};

tracing::debug!(target: LOG_TARGET, ?core_index, ?hash, %number, "Submitting collation for core.");

overseer_handle
.send_msg(
CollationGenerationMessage::SubmitCollation(SubmitCollationParams {
relay_parent,
collation,
parent_head: parent_header.encode().into(),
validation_code_hash,
core_index,
result_sender: None,
scheduling_parent: None,
session_index,
validation_data,
}),
"SubmitCollation",
)
Expand Down
7 changes: 4 additions & 3 deletions cumulus/client/consensus/aura/src/collators/slot_based/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ use cumulus_primitives_core::{KeyToIncludeInRelayProof, RelayParentOffsetApi};
use cumulus_relay_chain_interface::RelayChainInterface;
use futures::FutureExt;
use polkadot_primitives::{
CollatorPair, CoreIndex, Hash as RelayHash, Id as ParaId, ValidationCodeHash,
CollatorPair, CoreIndex, Hash as RelayHash, Id as ParaId, PersistedValidationData,
ValidationCodeHash,
};
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider};
use sc_consensus::BlockImport;
Expand Down Expand Up @@ -267,6 +268,6 @@ struct CollatorMessage<Block: BlockT> {
pub validation_code_hash: ValidationCodeHash,
/// Core index that this block should be submitted on
pub core_index: CoreIndex,
/// Maximum pov size. Currently needed only for exporting PoV.
pub max_pov_size: u32,
/// The persisted validation data for this collation.
pub validation_data: PersistedValidationData,
}
72 changes: 32 additions & 40 deletions polkadot/node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,44 +229,28 @@ impl CollationGenerationSubsystem {
let SubmitCollationParams {
relay_parent,
collation,
parent_head,
validation_code_hash,
result_sender,
core_index,
scheduling_parent,
session_index,
validation_data,
} = params;

let mut validation_data = match request_persisted_validation_data(
relay_parent,
config.para_id,
OccupiedCoreAssumption::TimedOut,
ctx.sender(),
)
.await
.await??
{
Some(v) => v,
None => {
gum::debug!(
target: LOG_TARGET,
relay_parent = ?relay_parent,
our_para = %config.para_id,
"No validation data for para - does it exist at this relay-parent?",
);
return Ok(());
},
};

// We need to swap the parent-head data, but all other fields here will be correct.
validation_data.parent_head = parent_head;

let claim_queue = request_claim_queue(relay_parent, ctx.sender()).await.await??;
// For V2 descriptors, scheduling_parent is None and relay_parent serves both roles.
let scheduling_parent_or_relay = scheduling_parent.unwrap_or(relay_parent);
let claim_queue =
request_claim_queue(scheduling_parent_or_relay, ctx.sender()).await.await??;

let session_index =
request_session_index_for_child(relay_parent, ctx.sender()).await.await??;
let scheduling_session =
request_session_index_for_child(scheduling_parent_or_relay, ctx.sender())
.await
.await??;

let session_info =
self.session_info_cache.get(relay_parent, session_index, ctx.sender()).await?;
let session_info = self
.session_info_cache
.get(scheduling_parent_or_relay, scheduling_session, ctx.sender())
.await?;
let collation = PreparedCollation {
collation,
relay_parent,
Expand All @@ -276,6 +260,7 @@ impl CollationGenerationSubsystem {
n_validators: session_info.n_validators,
core_index,
session_index,
scheduling_session,
};

construct_and_distribute_receipt(
Expand All @@ -300,7 +285,7 @@ impl CollationGenerationSubsystem {
return Ok(());
};

let Some(relay_parent) = maybe_activated else { return Ok(()) };
let Some(activated) = maybe_activated else { return Ok(()) };

// If there is no collation function provided, bail out early.
// Important: Lookahead collator and slot based collator do not use `CollatorFn`.
Expand All @@ -313,14 +298,14 @@ impl CollationGenerationSubsystem {
let _timer = self.metrics.time_new_activation();

let session_index =
request_session_index_for_child(relay_parent, ctx.sender()).await.await??;
request_session_index_for_child(activated, ctx.sender()).await.await??;

let session_info =
self.session_info_cache.get(relay_parent, session_index, ctx.sender()).await?;
self.session_info_cache.get(activated, session_index, ctx.sender()).await?;
let n_validators = session_info.n_validators;

let claim_queue =
ClaimQueueSnapshot::from(request_claim_queue(relay_parent, ctx.sender()).await.await??);
ClaimQueueSnapshot::from(request_claim_queue(activated, ctx.sender()).await.await??);

let assigned_cores = claim_queue
.iter_all_claims()
Expand All @@ -338,7 +323,7 @@ impl CollationGenerationSubsystem {
// for some more blocks, or even time out. We assume all cores are being freed.

let mut validation_data = match request_persisted_validation_data(
relay_parent,
activated,
para_id,
// Just use included assumption always. If there are no pending candidates it's a
// no-op.
Expand All @@ -352,7 +337,7 @@ impl CollationGenerationSubsystem {
None => {
gum::debug!(
target: LOG_TARGET,
relay_parent = ?relay_parent,
relay_parent = ?activated,
our_para = %para_id,
"validation data is not available",
);
Expand All @@ -361,7 +346,7 @@ impl CollationGenerationSubsystem {
};

let validation_code_hash = match request_validation_code_hash(
relay_parent,
activated,
para_id,
// Just use included assumption always. If there are no pending candidates it's a
// no-op.
Expand All @@ -375,7 +360,7 @@ impl CollationGenerationSubsystem {
None => {
gum::debug!(
target: LOG_TARGET,
relay_parent = ?relay_parent,
relay_parent = ?activated,
our_para = %para_id,
"validation code hash is not found.",
);
Expand Down Expand Up @@ -403,7 +388,7 @@ impl CollationGenerationSubsystem {
};

let (collation, result_sender) =
match collator_fn(relay_parent, &validation_data).await {
match collator_fn(activated, &validation_data).await {
Some(collation) => collation.into_inner(),
None => {
gum::debug!(
Expand Down Expand Up @@ -486,12 +471,14 @@ impl CollationGenerationSubsystem {
PreparedCollation {
collation,
para_id,
relay_parent,
relay_parent: activated,
validation_data: validation_data.clone(),
validation_code_hash,
n_validators,
core_index: descriptor_core_index,
session_index,
// V2 only: relay_parent == scheduling_parent, same session.
scheduling_session: session_index,
},
&mut task_sender,
result_sender,
Expand Down Expand Up @@ -572,7 +559,10 @@ struct PreparedCollation {
validation_code_hash: ValidationCodeHash,
n_validators: usize,
core_index: CoreIndex,
/// The relay parent's session index.
session_index: SessionIndex,
/// The scheduling parent's session index.
scheduling_session: SessionIndex,
}

/// Takes a prepared collation, along with its context, and produces a candidate receipt
Expand All @@ -594,6 +584,7 @@ async fn construct_and_distribute_receipt(
n_validators,
core_index,
session_index,
scheduling_session,
} = collation;

let persisted_validation_data_hash = validation_data.hash();
Expand Down Expand Up @@ -641,6 +632,7 @@ async fn construct_and_distribute_receipt(
relay_parent,
core_index,
session_index,
scheduling_session,
persisted_validation_data_hash,
pov_hash,
erasure_root,
Expand Down
Loading
Loading