Skip to content

Commit 594c3ed

Browse files
authored
improve MockValidationDataInherentDataProvider to support async backing (#4442)
Support async backing in `--dev` mode This PR improve the relay mock `MockValidationDataInherentDataProvider` to mach expectations of async backing runtimes. * Add para_head in the mock relay proof * Add relay slot in the mock relay proof fix #4437
1 parent fb7362f commit 594c3ed

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

cumulus/client/parachain-inherent/src/mock.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ use std::collections::BTreeMap;
2828

2929
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
3030

31+
/// Relay chain slot duration, in milliseconds.
32+
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
33+
3134
/// Inherent data provider that supplies mocked validation data.
3235
///
3336
/// 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;
4548
pub struct MockValidationDataInherentDataProvider<R = ()> {
4649
/// The current block number of the local block chain (the parachain)
4750
pub current_para_block: u32,
51+
/// The current block head data of the local block chain (the parachain)
52+
pub current_para_block_head: Option<cumulus_primitives_core::relay_chain::HeadData>,
4853
/// The relay block in which this parachain appeared to start. This will be the relay block
4954
/// number in para block #P1
5055
pub relay_offset: u32,
@@ -159,14 +164,16 @@ impl<R: Send + Sync + GenerateRandomness<u64>> InherentDataProvider
159164
&self,
160165
inherent_data: &mut InherentData,
161166
) -> Result<(), sp_inherents::Error> {
162-
// Calculate the mocked relay block based on the current para block
163-
let relay_parent_number =
164-
self.relay_offset + self.relay_blocks_per_para_block * self.current_para_block;
165-
166167
// Use the "sproof" (spoof proof) builder to build valid mock state root and proof.
167168
let mut sproof_builder =
168169
RelayStateSproofBuilder { para_id: self.xcm_config.para_id, ..Default::default() };
169170

171+
// Calculate the mocked relay block based on the current para block
172+
let relay_parent_number =
173+
self.relay_offset + self.relay_blocks_per_para_block * self.current_para_block;
174+
sproof_builder.current_slot =
175+
((relay_parent_number / RELAY_CHAIN_SLOT_DURATION_MILLIS) as u64).into();
176+
170177
// Process the downward messages and set up the correct head
171178
let mut downward_messages = Vec::new();
172179
let mut dmq_mqc = MessageQueueChain::new(self.xcm_config.starting_dmq_mqc_head);
@@ -217,6 +224,9 @@ impl<R: Send + Sync + GenerateRandomness<u64>> InherentDataProvider
217224
sproof_builder.additional_key_values = key_values.clone()
218225
}
219226

227+
// Inject current para block head, if any
228+
sproof_builder.included_para_head = self.current_para_block_head.clone();
229+
220230
let (relay_parent_storage_root, proof) = sproof_builder.into_state_root_and_proof();
221231

222232
inherent_data.put_data(

prdoc/pr_4442.prdoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Improve mock relay in --dev mode to support async backing
5+
6+
doc:
7+
- audience: Node Dev
8+
description: |
9+
Support async backing in --dev mode. Improve the relay mock MockValidationDataInherentDataProvider to mach expectations of async backing runtimes.
10+
11+
crates:
12+
- name: cumulus-client-parachain-inherent
13+
bump: patch

0 commit comments

Comments
 (0)