mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 12:51:02 +00:00
Put parachain head hash into CandidateDescriptor (#2310)
* Put parachain head hash into `CandidateDescriptor` * Update guide * Add some checks
This commit is contained in:
@@ -333,6 +333,7 @@ async fn handle_new_activations<Context: SubsystemContext>(
|
||||
persisted_validation_data_hash,
|
||||
pov_hash,
|
||||
erasure_root,
|
||||
para_head: commitments.head_data.hash(),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -738,6 +739,7 @@ mod tests {
|
||||
persisted_validation_data_hash: expect_validation_data_hash,
|
||||
pov_hash: expect_pov_hash,
|
||||
erasure_root: Default::default(), // this isn't something we're checking right now
|
||||
para_head: test_collation().head_data.hash(),
|
||||
};
|
||||
|
||||
assert_eq!(sent_messages.len(), 1);
|
||||
|
||||
@@ -459,6 +459,10 @@ fn validate_candidate_exhaustive<B: ValidationBackend, S: SpawnNamed + 'static>(
|
||||
Ok(ValidationResult::Invalid(InvalidCandidate::ExecutionError(e.to_string()))),
|
||||
Err(ValidationError::Internal(e)) => Err(ValidationFailed(e.to_string())),
|
||||
Ok(res) => {
|
||||
if res.head_data.hash() != descriptor.para_head {
|
||||
return Ok(ValidationResult::Invalid(InvalidCandidate::ParaHeadHashMismatch));
|
||||
}
|
||||
|
||||
let outputs = CandidateCommitments {
|
||||
head_data: res.head_data,
|
||||
upward_messages: res.upward_messages,
|
||||
@@ -887,15 +891,17 @@ mod tests {
|
||||
let validation_data = PersistedValidationData { max_pov_size: 1024, ..Default::default() };
|
||||
|
||||
let pov = PoV { block_data: BlockData(vec![1; 32]) };
|
||||
let head_data = HeadData(vec![1, 1, 1]);
|
||||
|
||||
let mut descriptor = CandidateDescriptor::default();
|
||||
descriptor.pov_hash = pov.hash();
|
||||
descriptor.para_head = head_data.hash();
|
||||
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
|
||||
|
||||
assert!(perform_basic_checks(&descriptor, validation_data.max_pov_size, &pov).is_ok());
|
||||
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data: HeadData(vec![1, 1, 1]),
|
||||
head_data,
|
||||
new_validation_code: Some(vec![2, 2, 2].into()),
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
|
||||
@@ -150,6 +150,8 @@ pub enum InvalidCandidate {
|
||||
HashMismatch,
|
||||
/// Bad collator signature.
|
||||
BadSignature,
|
||||
/// Para head hash does not match.
|
||||
ParaHeadHashMismatch,
|
||||
}
|
||||
|
||||
/// Result of the validation of the candidate.
|
||||
|
||||
@@ -38,6 +38,15 @@ pub use polkadot_core_primitives::BlockNumber as RelayChainBlockNumber;
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Default, Hash))]
|
||||
pub struct HeadData(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl HeadData {
|
||||
/// Returns the hash of this head data.
|
||||
pub fn hash(&self) -> Hash {
|
||||
use sp_runtime::traits::Hash;
|
||||
sp_runtime::traits::BlakeTwo256::hash(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Parachain validation code.
|
||||
#[derive(Default, PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, derive_more::From)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash))]
|
||||
|
||||
@@ -211,6 +211,8 @@ pub struct CandidateDescriptor<H = Hash> {
|
||||
/// Signature on blake2-256 of components of this receipt:
|
||||
/// The parachain index, the relay parent, the validation data hash, and the pov_hash.
|
||||
pub signature: CollatorSignature,
|
||||
/// Hash of the para header that is being generated by this candidate.
|
||||
pub para_head: Hash,
|
||||
}
|
||||
|
||||
impl<H: AsRef<[u8]>> CandidateDescriptor<H> {
|
||||
|
||||
@@ -85,6 +85,8 @@ struct CandidateDescriptor {
|
||||
/// Signature on blake2-256 of components of this receipt:
|
||||
/// The parachain index, the relay parent, the validation data hash, and the pov_hash.
|
||||
signature: CollatorSignature,
|
||||
/// Hash of the para header that is being generated by this candidate.
|
||||
para_head: Hash,
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user