From cfe9481f4deea42e7eb08eb5d8753decefe0429f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 13 May 2024 11:29:25 +0200 Subject: [PATCH 1/5] improve MockValidationDataInherentDataProvider to support async backing --- cumulus/client/parachain-inherent/src/mock.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cumulus/client/parachain-inherent/src/mock.rs b/cumulus/client/parachain-inherent/src/mock.rs index 22691006f93e..7d29d9ec2cf2 100644 --- a/cumulus/client/parachain-inherent/src/mock.rs +++ b/cumulus/client/parachain-inherent/src/mock.rs @@ -28,6 +28,9 @@ use std::collections::BTreeMap; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; +/// Relay chain slot duration, in milliseconds. +pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + /// Inherent data provider that supplies mocked validation data. /// /// This is useful when running a node that is not actually backed by any relay chain. @@ -45,6 +48,8 @@ use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; pub struct MockValidationDataInherentDataProvider { /// The current block number of the local block chain (the parachain) pub current_para_block: u32, + /// The current block head data of the local block chain (the parachain) + pub current_para_block_head: Option, /// The relay block in which this parachain appeared to start. This will be the relay block /// number in para block #P1 pub relay_offset: u32, @@ -159,14 +164,16 @@ impl> InherentDataProvider &self, inherent_data: &mut InherentData, ) -> Result<(), sp_inherents::Error> { - // Calculate the mocked relay block based on the current para block - let relay_parent_number = - self.relay_offset + self.relay_blocks_per_para_block * self.current_para_block; - // Use the "sproof" (spoof proof) builder to build valid mock state root and proof. let mut sproof_builder = RelayStateSproofBuilder { para_id: self.xcm_config.para_id, ..Default::default() }; + + // Calculate the mocked relay block based on the current para block + let relay_parent_number = + self.relay_offset + self.relay_blocks_per_para_block * self.current_para_block; + sproof_builder.current_slot = (relay_parent_number as u64).into() / RELAY_CHAIN_SLOT_DURATION_MILLIS; + // Process the downward messages and set up the correct head let mut downward_messages = Vec::new(); let mut dmq_mqc = MessageQueueChain::new(self.xcm_config.starting_dmq_mqc_head); @@ -217,6 +224,9 @@ impl> InherentDataProvider sproof_builder.additional_key_values = key_values.clone() } + // Inject current para block head, if any + sproof_builder.included_para_head = self.current_para_block_head.clone(); + let (relay_parent_storage_root, proof) = sproof_builder.into_state_root_and_proof(); inherent_data.put_data( From 068179287a993c3990f5023cb7ad4e1da72c8db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 13 May 2024 16:28:11 +0200 Subject: [PATCH 2/5] add PR doc --- prdoc/pr_4442.prdoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 prdoc/pr_4442.prdoc diff --git a/prdoc/pr_4442.prdoc b/prdoc/pr_4442.prdoc new file mode 100644 index 000000000000..ee6ac29e1a10 --- /dev/null +++ b/prdoc/pr_4442.prdoc @@ -0,0 +1,13 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Improve mock relay in --dev mode to support async backing + +doc: + - audience: Node Dev + description: | + Support async backing in --dev mode. Improve the relay mock MockValidationDataInherentDataProvider to mach expectations of async backing runtimes. + +crates: + - name: cumulus-client-parachain-inherent + bump: patch From f3bab06ed0773fee12ad99e59dbabee869484b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 13 May 2024 16:29:39 +0200 Subject: [PATCH 3/5] rustfmt --- cumulus/client/parachain-inherent/src/mock.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/client/parachain-inherent/src/mock.rs b/cumulus/client/parachain-inherent/src/mock.rs index 7d29d9ec2cf2..c8be24fd13ba 100644 --- a/cumulus/client/parachain-inherent/src/mock.rs +++ b/cumulus/client/parachain-inherent/src/mock.rs @@ -167,12 +167,12 @@ impl> InherentDataProvider // Use the "sproof" (spoof proof) builder to build valid mock state root and proof. let mut sproof_builder = RelayStateSproofBuilder { para_id: self.xcm_config.para_id, ..Default::default() }; - // Calculate the mocked relay block based on the current para block let relay_parent_number = self.relay_offset + self.relay_blocks_per_para_block * self.current_para_block; - sproof_builder.current_slot = (relay_parent_number as u64).into() / RELAY_CHAIN_SLOT_DURATION_MILLIS; + sproof_builder.current_slot = + (relay_parent_number as u64).into() / RELAY_CHAIN_SLOT_DURATION_MILLIS; // Process the downward messages and set up the correct head let mut downward_messages = Vec::new(); From 1d63b384e2bad89128389caddd62c5304335aa8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 13 May 2024 17:44:11 +0200 Subject: [PATCH 4/5] remove tabs --- cumulus/client/parachain-inherent/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/client/parachain-inherent/src/mock.rs b/cumulus/client/parachain-inherent/src/mock.rs index c8be24fd13ba..991a9a94a7b6 100644 --- a/cumulus/client/parachain-inherent/src/mock.rs +++ b/cumulus/client/parachain-inherent/src/mock.rs @@ -167,7 +167,7 @@ impl> InherentDataProvider // Use the "sproof" (spoof proof) builder to build valid mock state root and proof. let mut sproof_builder = RelayStateSproofBuilder { para_id: self.xcm_config.para_id, ..Default::default() }; - + // Calculate the mocked relay block based on the current para block let relay_parent_number = self.relay_offset + self.relay_blocks_per_para_block * self.current_para_block; From bbda32dc41981e9dd4207a63412a43a04c77e452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 13 May 2024 17:55:24 +0200 Subject: [PATCH 5/5] fix type convertion to Slot --- cumulus/client/parachain-inherent/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/client/parachain-inherent/src/mock.rs b/cumulus/client/parachain-inherent/src/mock.rs index 991a9a94a7b6..896df7a72425 100644 --- a/cumulus/client/parachain-inherent/src/mock.rs +++ b/cumulus/client/parachain-inherent/src/mock.rs @@ -172,7 +172,7 @@ impl> InherentDataProvider let relay_parent_number = self.relay_offset + self.relay_blocks_per_para_block * self.current_para_block; sproof_builder.current_slot = - (relay_parent_number as u64).into() / RELAY_CHAIN_SLOT_DURATION_MILLIS; + ((relay_parent_number / RELAY_CHAIN_SLOT_DURATION_MILLIS) as u64).into(); // Process the downward messages and set up the correct head let mut downward_messages = Vec::new();