mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 07:25:44 +00:00
Ease parachain candidate code fetching (#2593)
* code stored in para + modify CandidateDescriptor. * WIP: digest + some more impl * validation_code_hash in payload + check in inclusion * check in client + refator * tests * fix encoding indices * remove old todos * fix test * fix test * add test * fetch validation code inside collation-generation from the relay-chain * HashMismatch -> PoVHashMismatch + miscompilation * refactor, store hash when needed * storage rename: more specific but slightly too verbose * do not hash on candidate validation, fetch hash instead * better test * fix test * guide updates * don't panic in runtime Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
This commit is contained in:
committed by
GitHub
parent
98082c5326
commit
beca01f118
@@ -211,14 +211,16 @@ pub fn collator_signature_payload<H: AsRef<[u8]>>(
|
||||
para_id: &Id,
|
||||
persisted_validation_data_hash: &Hash,
|
||||
pov_hash: &Hash,
|
||||
) -> [u8; 100] {
|
||||
validation_code_hash: &Hash,
|
||||
) -> [u8; 132] {
|
||||
// 32-byte hash length is protected in a test below.
|
||||
let mut payload = [0u8; 100];
|
||||
let mut payload = [0u8; 132];
|
||||
|
||||
payload[0..32].copy_from_slice(relay_parent.as_ref());
|
||||
u32::from(*para_id).using_encoded(|s| payload[32..32 + s.len()].copy_from_slice(s));
|
||||
payload[36..68].copy_from_slice(persisted_validation_data_hash.as_ref());
|
||||
payload[68..100].copy_from_slice(pov_hash.as_ref());
|
||||
payload[100..132].copy_from_slice(validation_code_hash.as_ref());
|
||||
|
||||
payload
|
||||
}
|
||||
@@ -228,6 +230,7 @@ fn check_collator_signature<H: AsRef<[u8]>>(
|
||||
para_id: &Id,
|
||||
persisted_validation_data_hash: &Hash,
|
||||
pov_hash: &Hash,
|
||||
validation_code_hash: &Hash,
|
||||
collator: &CollatorId,
|
||||
signature: &CollatorSignature,
|
||||
) -> Result<(),()> {
|
||||
@@ -236,6 +239,7 @@ fn check_collator_signature<H: AsRef<[u8]>>(
|
||||
para_id,
|
||||
persisted_validation_data_hash,
|
||||
pov_hash,
|
||||
validation_code_hash,
|
||||
);
|
||||
|
||||
if signature.verify(&payload[..], collator) {
|
||||
@@ -268,6 +272,8 @@ pub struct CandidateDescriptor<H = Hash> {
|
||||
pub signature: CollatorSignature,
|
||||
/// Hash of the para header that is being generated by this candidate.
|
||||
pub para_head: Hash,
|
||||
/// The blake2-256 hash of the validation code bytes.
|
||||
pub validation_code_hash: Hash,
|
||||
}
|
||||
|
||||
impl<H: AsRef<[u8]>> CandidateDescriptor<H> {
|
||||
@@ -278,6 +284,7 @@ impl<H: AsRef<[u8]>> CandidateDescriptor<H> {
|
||||
&self.para_id,
|
||||
&self.persisted_validation_data_hash,
|
||||
&self.pov_hash,
|
||||
&self.validation_code_hash,
|
||||
&self.collator,
|
||||
&self.signature,
|
||||
)
|
||||
@@ -872,6 +879,10 @@ sp_api::decl_runtime_apis! {
|
||||
/// messages in them are also included.
|
||||
#[skip_initialize_block]
|
||||
fn inbound_hrmp_channels_contents(recipient: Id) -> BTreeMap<Id, Vec<InboundHrmpMessage<N>>>;
|
||||
|
||||
/// Get the validation code from its hash.
|
||||
#[skip_initialize_block]
|
||||
fn validation_code_by_hash(hash: Hash) -> Option<ValidationCode>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1107,6 +1118,7 @@ mod tests {
|
||||
&5u32.into(),
|
||||
&Hash::repeat_byte(2),
|
||||
&Hash::repeat_byte(3),
|
||||
&Hash::repeat_byte(4),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user