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
12 changes: 7 additions & 5 deletions cumulus/client/consensus/aura/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

use codec::{Codec, Encode};
use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface;
use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockImportMarker};
use cumulus_client_consensus_common::{
self as consensus_common, ParachainBlockImportMarker, ParentSearchParams,
};
use cumulus_primitives_aura::AuraUnincludedSegmentApi;
use cumulus_primitives_core::{
CollectCollationInfo, KeyToIncludeInRelayProof, PersistedValidationData,
Expand Down Expand Up @@ -334,10 +336,10 @@ where
};

let parent_search_result = match crate::collators::find_parent(
relay_parent,
params.para_id,
&*params.para_backend,
&params.relay_client,
&*params.para_backend,
params.para_id,
ParentSearchParams::V2 { scheduling_parent: relay_parent },
|_| true,
)
.await
Expand All @@ -346,7 +348,7 @@ where
None => continue,
};

let included_header = &parent_search_result.included_header;
let included_header = &parent_search_result.included_at_scheduling;
let para_client = &*params.para_client;
let keystore = &params.keystore;
let included_block_hash = included_header.hash();
Expand Down
27 changes: 10 additions & 17 deletions cumulus/client/consensus/aura/src/collators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use polkadot_node_subsystem::messages::CollatorProtocolMessage;
use polkadot_node_subsystem_util::runtime::ClaimQueueSnapshot;
use polkadot_primitives::{
Hash as RelayHash, Id as ParaId, OccupiedCoreAssumption, ValidationCodeHash,
DEFAULT_SCHEDULING_LOOKAHEAD,
};
use sc_client_api::HeaderBackend;
use sc_consensus_aura::{standalone as aura_internal, AuraApi};
Expand Down Expand Up @@ -238,42 +237,36 @@ where
/// If the best parent does not pass `filter_parent`, walks backwards through ancestors
/// until finding one that does, or reaching the included block.
async fn find_parent<Block>(
relay_parent: RelayHash,
para_id: ParaId,
para_backend: &impl sc_client_api::Backend<Block>,
relay_client: &impl RelayChainInterface,
para_backend: &impl sc_client_api::Backend<Block>,
para_id: ParaId,
params: ParentSearchParams<Block>,
filter_parent: impl Fn(&Block::Header) -> bool,
) -> Option<consensus_common::ParentSearchResult<Block>>
where
Block: BlockT,
{
let ancestry_lookback = relay_client
.scheduling_lookahead(relay_parent)
.await
.unwrap_or(DEFAULT_SCHEDULING_LOOKAHEAD)
.saturating_sub(1) as usize;
let parent_search_params = ParentSearchParams { relay_parent, para_id, ancestry_lookback };

let mut result = match cumulus_client_consensus_common::find_parent_for_building::<Block>(
parent_search_params,
para_backend,
relay_client,
para_backend,
para_id,
params.clone(),
)
.await
{
Ok(Some(result)) => result,
Ok(None) => {
tracing::warn!(
target: crate::LOG_TARGET,
?relay_parent,
?params,
"Could not find parent to build upon.",
);
return None;
},
Err(e) => {
tracing::error!(
target: crate::LOG_TARGET,
?relay_parent,
?params,
err = ?e,
"Could not find parent to build upon"
);
Expand All @@ -290,12 +283,12 @@ where
match para_backend.blockchain().header(parent_hash) {
Ok(Some(header)) => {
result.best_parent_header = header;
if parent_hash == result.included_header.hash() {
if parent_hash == result.included_at_scheduling.hash() {
break;
}
},
_ => {
result.best_parent_header = result.included_header.clone();
result.best_parent_header = result.included_at_scheduling.clone();
break;
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use crate::{
use codec::{Codec, Encode};
use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface;
use cumulus_client_consensus_common::{
self as consensus_common, get_relay_slot, ParachainBlockImportMarker,
self as consensus_common, fetch_included_from_pvd, get_relay_slot, ParachainBlockImportMarker,
ParentSearchParams,
};
use cumulus_client_proof_size_recording::prepare_proof_size_recording_aux_data;
use cumulus_primitives_aura::{AuraUnincludedSegmentApi, Slot};
Expand Down Expand Up @@ -287,11 +288,18 @@ where
let relay_parent_header = relay_parent_data.relay_parent().clone();
let relay_parent_hash = relay_parent_header.hash();

let parent_search_params = match v3_enabled {
false => ParentSearchParams::V2 { scheduling_parent: relay_parent_hash },
true => ParentSearchParams::V3 {
scheduling_parent: scheduling_parent_hash,
para_best_hash,
},
};
let Some(parent_search_result) = crate::collators::find_parent(
relay_parent_hash,
para_id,
&*para_backend,
&relay_client,
&*para_backend,
para_id,
parent_search_params,
|parent| {
// We never want to build on any "middle block" that isn't the last block in a
// core.
Expand All @@ -305,11 +313,31 @@ where
continue;
};

let included_header = parent_search_result.included_header;
// For the logic that follows we need the included header at the relay parent since
// it will be used for checking the unincluded segment len.
// Corresponding checks related to the unincluded segment len are also done by the
// runtime in the `set_validation_data` inherent, using the relay parent context.
let included_header_at_execution = match v3_enabled {
false => parent_search_result.included_at_scheduling,
true => {
let Ok(Some((_, included_header))) = fetch_included_from_pvd(
&relay_client,
&*para_backend,
relay_parent_hash,
para_id,
)
.await
else {
continue;
};
included_header
},
};
let initial_parent_hash = parent_search_result.best_parent_header.hash();
let initial_parent_header = parent_search_result.best_parent_header;
let unincluded_segment_len =
initial_parent_header.number().saturating_sub(*included_header.number());
let unincluded_segment_len = initial_parent_header
.number()
.saturating_sub(*included_header_at_execution.number());

let Ok(para_slot_duration) =
crate::slot_duration_at(&*para_client, initial_parent_hash)
Expand Down Expand Up @@ -353,7 +381,7 @@ where

let Some(relay_slot) = get_relay_slot(&relay_parent_header) else { continue };

let included_header_hash = included_header.hash();
let included_hash_at_execution = included_header_at_execution.hash();

{
let mut runtime_api = para_client.runtime_api();
Expand All @@ -378,8 +406,8 @@ where
?unincluded_segment_len,
relay_parent = ?relay_parent_hash,
relay_parent_num = %relay_parent_header.number(),
included_hash = ?included_header_hash,
included_num = %included_header.number(),
?included_hash_at_execution,
included_num_at_execution = %included_header_at_execution.number(),
initial_parent = ?initial_parent_hash,
slot = ?para_slot.slot,
"Not eligible to claim slot."
Expand All @@ -393,8 +421,8 @@ where
relay_parent = ?relay_parent_hash,
relay_parent_num = %relay_parent_header.number(),
relay_parent_offset,
included_hash = ?included_header_hash,
included_num = %included_header.number(),
?included_hash_at_execution,
included_num_at_execution = %included_header_at_execution.number(),
initial_parent = ?initial_parent_hash,
slot = ?para_slot.slot,
"Claiming slot."
Expand Down Expand Up @@ -514,7 +542,7 @@ where
collator_peer_id,
relay_parent_data: relay_parent_data.clone(),
total_number_of_blocks: number_of_blocks,
included_header_hash,
included_hash_at_execution,
relay_slot,
para_slot: para_slot.slot,
para_client: &*para_client,
Expand Down Expand Up @@ -574,7 +602,7 @@ struct BuildCollationParams<
collator_peer_id: PeerId,
relay_parent_data: RelayParentData,
total_number_of_blocks: u32,
included_header_hash: Block::Hash,
included_hash_at_execution: Block::Hash,
relay_slot: cumulus_primitives_aura::Slot,
para_slot: cumulus_primitives_aura::Slot,
para_client: &'a Client,
Expand Down Expand Up @@ -617,7 +645,7 @@ async fn build_collation_for_core<
collator_peer_id,
mut relay_parent_data,
total_number_of_blocks,
included_header_hash,
included_hash_at_execution,
relay_slot,
para_slot,
para_client,
Expand Down Expand Up @@ -701,7 +729,7 @@ where
// Check if we can build the next block
if !crate::collators::can_build_upon::<Block, Client>(
parent_hash,
included_header_hash,
included_hash_at_execution,
relay_slot,
para_slot,
para_client,
Expand All @@ -711,7 +739,7 @@ where
tracing::debug!(
target: LOG_TARGET,
?parent_hash,
?included_header_hash,
?included_hash_at_execution,
"Cannot build next block due to unincluded segment constraints, skipping entire bundle. Will continue at the next slot."
);

Expand Down
13 changes: 11 additions & 2 deletions cumulus/client/consensus/aura/src/collators/slot_based/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use cumulus_relay_chain_interface::*;
use futures::Stream;
use polkadot_node_subsystem_util::runtime::ClaimQueueSnapshot;
use polkadot_primitives::{
CandidateEvent, CommittedCandidateReceiptV2, CoreIndex, Hash as RelayHash,
Header as RelayHeader, Id as ParaId, NodeFeatures,
vstaging::RelayParentInfo, CandidateEvent, CommittedCandidateReceiptV2, CoreIndex,
Hash as RelayHash, Header as RelayHeader, Id as ParaId, NodeFeatures,
};
use sc_consensus_babe::{
AuthorityId, ConsensusLog as BabeConsensusLog, NextEpochDescriptor, BABE_ENGINE_ID,
Expand Down Expand Up @@ -509,6 +509,15 @@ impl RelayChainInterface for TestRelayClient {
async fn node_features(&self, _at: RelayHash) -> RelayChainResult<NodeFeatures> {
Ok(NodeFeatures::default())
}

async fn ancestor_relay_parent_info(
&self,
_at: RelayHash,
_session_index: SessionIndex,
_relay_parent: RelayHash,
) -> RelayChainResult<Option<RelayParentInfo<RelayHash, BlockNumber>>> {
unimplemented!("Not needed for test")
}
}

/// Build a consecutive set of relay headers whose digest entries optionally carry a BABE
Expand Down
Loading
Loading