From 9f057899d217bbbbcfb1c8bfbc7bf7fc00164972 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 21 Jan 2021 13:59:25 -0500 Subject: [PATCH 1/2] Add relay parent to inherent and to digest. --- collator/src/lib.rs | 1 + parachain-system/src/lib.rs | 9 +++++++++ primitives/src/lib.rs | 3 +++ test/client/src/block_builder.rs | 1 + 4 files changed, 14 insertions(+) diff --git a/collator/src/lib.rs b/collator/src/lib.rs index ce70b4fb23a..925e4fd679b 100644 --- a/collator/src/lib.rs +++ b/collator/src/lib.rs @@ -297,6 +297,7 @@ where horizontal_messages, validation_data: validation_data.clone(), relay_chain_state, + relay_parent, } }; diff --git a/parachain-system/src/lib.rs b/parachain-system/src/lib.rs index 26f19eb4cd0..ff6db11e8cd 100644 --- a/parachain-system/src/lib.rs +++ b/parachain-system/src/lib.rs @@ -44,6 +44,8 @@ use sp_std::{vec::Vec, cmp}; mod relay_state_snapshot; use relay_state_snapshot::MessagingStateSnapshot; +use sp_runtime::DigestItem; +use codec::Encode; /// The pallet's configuration trait. pub trait Config: frame_system::Config { @@ -153,6 +155,7 @@ decl_module! { relay_chain_state, downward_messages, horizontal_messages, + relay_parent, } = data; // initialization logic: we know that this runs exactly once every block, @@ -219,6 +222,12 @@ decl_module! { ); } + // Add the relay parent to a digest to track which parents this block was built on. + frame_system::Module::::deposit_log(DigestItem::::Consensus( + *b"rlyp", // "rlyp" -> "relay parent" + relay_parent.encode(), + )); + Ok(()) } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 9ea4a67e055..3a99eadcd3d 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -45,6 +45,7 @@ pub mod inherents { use super::{InboundDownwardMessage, InboundHrmpMessage, ParaId}; use sp_inherents::InherentIdentifier; use sp_std::{collections::btree_map::BTreeMap, vec::Vec}; + use polkadot_primitives::v1::Hash as PHash; /// The identifier for the parachain-system inherent. pub const SYSTEM_INHERENT_IDENTIFIER: InherentIdentifier = *b"sysi1337"; @@ -68,6 +69,8 @@ pub mod inherents { /// were sent. In combination with the rule of no more than one message in a channel per block, /// this means `sent_at` is **strictly** greater than the previous one (if any). pub horizontal_messages: BTreeMap>, + /// The hash of the relay parent block on which this block is built. + pub relay_parent: PHash, } } diff --git a/test/client/src/block_builder.rs b/test/client/src/block_builder.rs index 12f0f000ebb..294b7e64f43 100644 --- a/test/client/src/block_builder.rs +++ b/test/client/src/block_builder.rs @@ -107,6 +107,7 @@ impl InitBlockBuilder for Client { relay_chain_state, downward_messages: Default::default(), horizontal_messages: Default::default(), + relay_parent: Default::default(), }, ) .expect("Put validation function params failed"); From 9d6f7c79c7c9d234c15a2619bb80048654050712 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 21 Jan 2021 14:20:21 -0500 Subject: [PATCH 2/2] fix test --- parachain-system/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/parachain-system/src/lib.rs b/parachain-system/src/lib.rs index ff6db11e8cd..766d6519296 100644 --- a/parachain-system/src/lib.rs +++ b/parachain-system/src/lib.rs @@ -941,6 +941,7 @@ mod tests { relay_chain_state, downward_messages: Default::default(), horizontal_messages: Default::default(), + relay_parent: Default::default(), }) .expect("failed to put VFP inherent"); inherent_data