Skip to content

Commit

Permalink
address review: use enum for parent head-data
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Feb 27, 2024
1 parent 10a3e9c commit b7466c2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
18 changes: 12 additions & 6 deletions polkadot/node/core/prospective-parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ use futures::{channel::oneshot, prelude::*};
use polkadot_node_subsystem::{
messages::{
ChainApiMessage, FragmentTreeMembership, HypotheticalCandidate,
HypotheticalFrontierRequest, IntroduceCandidateRequest, ProspectiveParachainsMessage,
ProspectiveValidationDataRequest, RuntimeApiMessage, RuntimeApiRequest,
HypotheticalFrontierRequest, IntroduceCandidateRequest, ParentHeadData,
ProspectiveParachainsMessage, ProspectiveValidationDataRequest, RuntimeApiMessage,
RuntimeApiRequest,
},
overseer, ActiveLeavesUpdate, FromOrchestra, OverseerSignal, SpawnedSubsystem, SubsystemError,
};
Expand Down Expand Up @@ -771,9 +772,14 @@ fn answer_prospective_validation_data_request(
Some(s) => s,
};

let mut head_data = request
.maybe_parent_head_data
.or_else(|| storage.head_data_by_hash(&request.parent_head_data_hash).map(|x| x.clone()));
let (mut head_data, parent_head_data_hash) = match request.parent_head_data {
ParentHeadData::OnlyHash(parent_head_data_hash) => (
storage.head_data_by_hash(&parent_head_data_hash).map(|x| x.clone()),
parent_head_data_hash,
),
ParentHeadData::WithData { head_data, hash } => (Some(head_data), hash),
};

let mut relay_parent_info = None;
let mut max_pov_size = None;

Expand All @@ -791,7 +797,7 @@ fn answer_prospective_validation_data_request(
}
if head_data.is_none() {
let required_parent = &fragment_tree.scope().base_constraints().required_parent;
if required_parent.hash() == request.parent_head_data_hash {
if required_parent.hash() == parent_head_data_hash {
head_data = Some(required_parent.clone());
}
}
Expand Down
5 changes: 2 additions & 3 deletions polkadot/node/core/prospective-parachains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use assert_matches::assert_matches;
use polkadot_node_subsystem::{
errors::RuntimeApiError,
messages::{
AllMessages, HypotheticalFrontierRequest, ProspectiveParachainsMessage,
AllMessages, HypotheticalFrontierRequest, ParentHeadData, ProspectiveParachainsMessage,
ProspectiveValidationDataRequest,
},
};
Expand Down Expand Up @@ -472,8 +472,7 @@ async fn get_pvd(
let request = ProspectiveValidationDataRequest {
para_id,
candidate_relay_parent,
parent_head_data_hash: parent_head_data.hash(),
maybe_parent_head_data: None,
parent_head_data: ParentHeadData::OnlyHash(parent_head_data.hash()),
};
let (tx, rx) = oneshot::channel();
virtual_overseer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use polkadot_node_subsystem::{
jaeger,
messages::{
CanSecondRequest, CandidateBackingMessage, CollatorProtocolMessage, IfDisconnected,
NetworkBridgeEvent, NetworkBridgeTxMessage, ProspectiveParachainsMessage,
NetworkBridgeEvent, NetworkBridgeTxMessage, ParentHeadData, ProspectiveParachainsMessage,
ProspectiveValidationDataRequest,
},
overseer, CollatorProtocolSenderTrait, FromOrchestra, OverseerSignal, PerLeafSpan,
Expand Down Expand Up @@ -1784,13 +1784,15 @@ where
{
let (tx, rx) = oneshot::channel();

let request = ProspectiveValidationDataRequest {
para_id,
candidate_relay_parent,
parent_head_data_hash,
maybe_parent_head_data,
let parent_head_data = if let Some(head_data) = maybe_parent_head_data {
ParentHeadData::WithData { head_data, hash: parent_head_data_hash }
} else {
ParentHeadData::OnlyHash(parent_head_data_hash)
};

let request =
ProspectiveValidationDataRequest { para_id, candidate_relay_parent, parent_head_data };

sender
.send_message(ProspectiveParachainsMessage::GetProspectiveValidationData(request, tx))
.await;
Expand Down
21 changes: 16 additions & 5 deletions polkadot/node/subsystem-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,11 +1108,22 @@ pub struct ProspectiveValidationDataRequest {
pub para_id: ParaId,
/// The relay-parent of the candidate.
pub candidate_relay_parent: Hash,
/// The parent head-data hash.
pub parent_head_data_hash: Hash,
/// Optionally, the head-data of the parent.
/// This will be provided for collations with elastic scaling enabled.
pub maybe_parent_head_data: Option<HeadData>,
/// The parent head-data.
pub parent_head_data: ParentHeadData,
}

/// The parent head-data hash with optional data itself.
#[derive(Debug)]
pub enum ParentHeadData {
/// Parent head-data hash.
OnlyHash(Hash),
/// Parent head-data along with its hash.
WithData {
/// This will be provided for collations with elastic scaling enabled.
head_data: HeadData,
/// Parent head-data hash.
hash: Hash,
},
}

/// Indicates the relay-parents whose fragment tree a candidate
Expand Down

0 comments on commit b7466c2

Please sign in to comment.