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

Commit

Permalink
update find_potential_parents to account for sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed Jul 27, 2023
1 parent e37ab0a commit 763134b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/consensus/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ pub struct PotentialParent<B: BlockT> {
/// parachain block (when `max_depth` >= 1), or all of the following hold:
/// * its parent is a potential parent
/// * its relay-parent is within `ancestry_lookback` of the targeted relay-parent.
/// * its relay-parent is within the same session as the targeted relay-parent.
/// * the block number is within `max_depth` blocks of the included block
pub async fn find_potential_parents<B: BlockT>(
params: ParentSearchParams,
Expand All @@ -262,12 +263,24 @@ pub async fn find_potential_parents<B: BlockT>(
let rp_ancestry = {
let mut ancestry = Vec::with_capacity(params.ancestry_lookback + 1);
let mut current_rp = params.relay_parent;
let mut required_session = None;

while ancestry.len() <= params.ancestry_lookback {
let header = match relay_client.header(RBlockId::hash(current_rp)).await? {
None => break,
Some(h) => h,
};

let session = relay_client.session_index_for_child(current_rp).await?;
if let Some(required_session) = required_session {
// Respect the relay-chain rule not to cross session boundaries.
if session != required_session {
break
}
} else {
required_session = Some(session);
}

ancestry.push((current_rp, *header.state_root()));
current_rp = *header.parent_hash();

Expand Down

0 comments on commit 763134b

Please sign in to comment.