mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21: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,
|
persisted_validation_data_hash,
|
||||||
pov_hash,
|
pov_hash,
|
||||||
erasure_root,
|
erasure_root,
|
||||||
|
para_head: commitments.head_data.hash(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -738,6 +739,7 @@ mod tests {
|
|||||||
persisted_validation_data_hash: expect_validation_data_hash,
|
persisted_validation_data_hash: expect_validation_data_hash,
|
||||||
pov_hash: expect_pov_hash,
|
pov_hash: expect_pov_hash,
|
||||||
erasure_root: Default::default(), // this isn't something we're checking right now
|
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);
|
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()))),
|
Ok(ValidationResult::Invalid(InvalidCandidate::ExecutionError(e.to_string()))),
|
||||||
Err(ValidationError::Internal(e)) => Err(ValidationFailed(e.to_string())),
|
Err(ValidationError::Internal(e)) => Err(ValidationFailed(e.to_string())),
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
|
if res.head_data.hash() != descriptor.para_head {
|
||||||
|
return Ok(ValidationResult::Invalid(InvalidCandidate::ParaHeadHashMismatch));
|
||||||
|
}
|
||||||
|
|
||||||
let outputs = CandidateCommitments {
|
let outputs = CandidateCommitments {
|
||||||
head_data: res.head_data,
|
head_data: res.head_data,
|
||||||
upward_messages: res.upward_messages,
|
upward_messages: res.upward_messages,
|
||||||
@@ -887,15 +891,17 @@ mod tests {
|
|||||||
let validation_data = PersistedValidationData { max_pov_size: 1024, ..Default::default() };
|
let validation_data = PersistedValidationData { max_pov_size: 1024, ..Default::default() };
|
||||||
|
|
||||||
let pov = PoV { block_data: BlockData(vec![1; 32]) };
|
let pov = PoV { block_data: BlockData(vec![1; 32]) };
|
||||||
|
let head_data = HeadData(vec![1, 1, 1]);
|
||||||
|
|
||||||
let mut descriptor = CandidateDescriptor::default();
|
let mut descriptor = CandidateDescriptor::default();
|
||||||
descriptor.pov_hash = pov.hash();
|
descriptor.pov_hash = pov.hash();
|
||||||
|
descriptor.para_head = head_data.hash();
|
||||||
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
|
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
|
||||||
|
|
||||||
assert!(perform_basic_checks(&descriptor, validation_data.max_pov_size, &pov).is_ok());
|
assert!(perform_basic_checks(&descriptor, validation_data.max_pov_size, &pov).is_ok());
|
||||||
|
|
||||||
let validation_result = WasmValidationResult {
|
let validation_result = WasmValidationResult {
|
||||||
head_data: HeadData(vec![1, 1, 1]),
|
head_data,
|
||||||
new_validation_code: Some(vec![2, 2, 2].into()),
|
new_validation_code: Some(vec![2, 2, 2].into()),
|
||||||
upward_messages: Vec::new(),
|
upward_messages: Vec::new(),
|
||||||
horizontal_messages: Vec::new(),
|
horizontal_messages: Vec::new(),
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ pub enum InvalidCandidate {
|
|||||||
HashMismatch,
|
HashMismatch,
|
||||||
/// Bad collator signature.
|
/// Bad collator signature.
|
||||||
BadSignature,
|
BadSignature,
|
||||||
|
/// Para head hash does not match.
|
||||||
|
ParaHeadHashMismatch,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Result of the validation of the candidate.
|
/// 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))]
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Default, Hash))]
|
||||||
pub struct HeadData(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
|
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.
|
/// Parachain validation code.
|
||||||
#[derive(Default, PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, derive_more::From)]
|
#[derive(Default, PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, derive_more::From)]
|
||||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash))]
|
#[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:
|
/// Signature on blake2-256 of components of this receipt:
|
||||||
/// The parachain index, the relay parent, the validation data hash, and the pov_hash.
|
/// The parachain index, the relay parent, the validation data hash, and the pov_hash.
|
||||||
pub signature: CollatorSignature,
|
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> {
|
impl<H: AsRef<[u8]>> CandidateDescriptor<H> {
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ struct CandidateDescriptor {
|
|||||||
/// Signature on blake2-256 of components of this receipt:
|
/// Signature on blake2-256 of components of this receipt:
|
||||||
/// The parachain index, the relay parent, the validation data hash, and the pov_hash.
|
/// The parachain index, the relay parent, the validation data hash, and the pov_hash.
|
||||||
signature: CollatorSignature,
|
signature: CollatorSignature,
|
||||||
|
/// Hash of the para header that is being generated by this candidate.
|
||||||
|
para_head: Hash,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user