Skip to content

Commit

Permalink
sanity check the provided parent head data hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Feb 20, 2024
1 parent 3320447 commit 10a3e9c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions polkadot/node/network/collator-protocol/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ pub enum SecondingError {

#[error("Received duplicate collation from the peer")]
Duplicate,

#[error("The provided parent head data does not match the hash")]
ParentHeadDataMismatch,
}

impl SecondingError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub fn fetched_collation_sanity_check(
advertised: &PendingCollation,
fetched: &CandidateReceipt,
persisted_validation_data: &PersistedValidationData,
maybe_parent_head_and_hash: Option<(HeadData, Hash)>,
) -> Result<(), SecondingError> {
if persisted_validation_data.hash() != fetched.descriptor().persisted_validation_data_hash {
Err(SecondingError::PersistedValidationDataMismatch)
Expand All @@ -152,6 +153,8 @@ pub fn fetched_collation_sanity_check(
.map_or(false, |pc| pc.candidate_hash() != fetched.hash())
{
Err(SecondingError::CandidateHashMismatch)
} else if maybe_parent_head_and_hash.map_or(false, |(head, hash)| head.hash() != hash) {
Err(SecondingError::ParentHeadDataMismatch)
} else {
Ok(())
}
Expand Down
25 changes: 16 additions & 9 deletions polkadot/node/network/collator-protocol/src/validator_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,39 +1827,46 @@ async fn kick_off_seconding<Context>(
collation_event.pending_collation.commitments_hash =
Some(candidate_receipt.commitments_hash);

let pvd = match (
let (maybe_pvd, maybe_parent_head_and_hash) = match (
collation_event.collator_protocol_version,
collation_event.pending_collation.prospective_candidate,
) {
(CollationVersion::V2, Some(ProspectiveCandidate { parent_head_data_hash, .. }))
if per_relay_parent.prospective_parachains_mode.is_enabled() =>
request_prospective_validation_data(
{
let pvd = request_prospective_validation_data(
ctx.sender(),
relay_parent,
parent_head_data_hash,
pending_collation.para_id,
maybe_parent_head_data,
maybe_parent_head_data.clone(),
)
.await?,
.await?;

(pvd, maybe_parent_head_data.map(|head_data| (head_data, parent_head_data_hash)))
},
// Support V2 collators without async backing enabled.
(CollationVersion::V2, Some(_)) | (CollationVersion::V1, _) =>
request_persisted_validation_data(
(CollationVersion::V2, Some(_)) | (CollationVersion::V1, _) => {
let pvd = request_persisted_validation_data(
ctx.sender(),
candidate_receipt.descriptor().relay_parent,
candidate_receipt.descriptor().para_id,
)
.await?,
.await?;
(pvd, None)
},
_ => {
// `handle_advertisement` checks for protocol mismatch.
return Ok(())
},
}
.ok_or(SecondingError::PersistedValidationDataNotFound)?;
};
let pvd = maybe_pvd.ok_or(SecondingError::PersistedValidationDataNotFound)?;

fetched_collation_sanity_check(
&collation_event.pending_collation,
&candidate_receipt,
&pvd,
maybe_parent_head_and_hash,
)?;

ctx.send_message(CandidateBackingMessage::Second(
Expand Down

0 comments on commit 10a3e9c

Please sign in to comment.