@@ -28,6 +28,9 @@ use std::collections::BTreeMap;
2828
2929use 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;
4548pub 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 (
0 commit comments