From 1c2421fbc3b1d86288620050195966bb91488e71 Mon Sep 17 00:00:00 2001 From: Chris Sosnin <48099298+slumber@users.noreply.github.com> Date: Tue, 21 Mar 2023 16:13:20 +0300 Subject: [PATCH] introduce new well known key (#6915) --- primitives/src/v4/mod.rs | 17 +++++++++++++++++ runtime/parachains/src/paras/tests.rs | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/primitives/src/v4/mod.rs b/primitives/src/v4/mod.rs index 82d7954b8090..efd6db836c21 100644 --- a/primitives/src/v4/mod.rs +++ b/primitives/src/v4/mod.rs @@ -187,6 +187,23 @@ pub mod well_known_keys { pub const ACTIVE_CONFIG: &[u8] = &hex!["06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385"]; + /// Hash of the committed head data for a given registered para. + /// + /// The storage entry stores wrapped `HeadData(Vec)`. + pub fn para_head(para_id: Id) -> Vec { + let prefix = hex!["cd710b30bd2eab0352ddcc26417aa1941b3c252fcb29d88eff4f3de5de4476c3"]; + + para_id.using_encoded(|para_id: &[u8]| { + prefix + .as_ref() + .iter() + .chain(twox_64(para_id).iter()) + .chain(para_id.iter()) + .cloned() + .collect() + }) + } + /// The upward message dispatch queue for the given para id. /// /// The storage entry stores a tuple of two values: diff --git a/runtime/parachains/src/paras/tests.rs b/runtime/parachains/src/paras/tests.rs index 567829b9aeff..dff5222baa3c 100644 --- a/runtime/parachains/src/paras/tests.rs +++ b/runtime/parachains/src/paras/tests.rs @@ -1700,6 +1700,21 @@ fn verify_upgrade_restriction_signal_is_externally_accessible() { }); } +#[test] +fn verify_para_head_is_externally_accessible() { + use primitives::well_known_keys; + + let a = ParaId::from(2020); + let expected_head_data = HeadData(vec![0, 1, 2, 3]); + + new_test_ext(Default::default()).execute_with(|| { + Heads::::insert(&a, expected_head_data.clone()); + let encoded = sp_io::storage::get(&well_known_keys::para_head(a)).unwrap(); + let head_data = HeadData::decode(&mut encoded.as_ref()); + assert_eq!(head_data, Ok(expected_head_data)); + }); +} + #[test] fn parakind_encodes_decodes_to_bool_scale() { let chain_kind = ParaKind::Parachain.encode();