2121use std:: { ops:: DerefMut , sync:: Arc } ;
2222
2323use parity_scale_codec:: { Decode , Encode } ;
24- use polkadot_primitives:: { BlockNumber , HeadData } ;
24+ use polkadot_primitives:: HeadData ;
2525use sp_consensus_babe:: SlotDuration ;
2626use sp_core:: twox_128;
2727use sp_inherents:: InherentIdentifier ;
28- use sp_runtime:: traits:: { Block as BlockT , HashingFor , NumberFor } ;
28+ use sp_runtime:: traits:: { Block as BlockT , HashingFor } ;
2929use sp_state_machine:: TestExternalities ;
3030use tokio:: sync:: Mutex ;
3131
@@ -37,26 +37,6 @@ pub fn get_para_id<B: BlockT>(ext: &mut TestExternalities<HashingFor<B>>) -> Opt
3737 . and_then ( |b| -> Option < u32 > { Decode :: decode ( & mut & b[ ..] ) . ok ( ) } )
3838}
3939
40- /// Get the last relay chain block number if it exists
41- pub fn get_last_relay_chain_block_number < B : BlockT > (
42- ext : & mut TestExternalities < HashingFor < B > > ,
43- ) -> Option < BlockNumber > {
44- let last_relay_chain_block_number_key = [
45- twox_128 ( b"ParachainSystem" ) ,
46- twox_128 ( b"LastRelayChainBlockNumber" ) ,
47- ]
48- . concat ( ) ;
49-
50- ext. execute_with ( || sp_io:: storage:: get ( & last_relay_chain_block_number_key) )
51- . and_then ( |b| -> Option < NumberFor < B > > { Decode :: decode ( & mut & b[ ..] ) . ok ( ) } )
52- . map ( |n| match n. try_into ( ) {
53- Ok ( block_number) => block_number,
54- Err ( _) => {
55- panic ! ( "Failed to convert relay chain block number" )
56- }
57- } )
58- }
59-
6040/// Provides parachain-system pallet inherents.
6141pub struct InherentDataProvider < B : BlockT > {
6242 pub timestamp : sp_timestamp:: Timestamp ,
@@ -74,46 +54,21 @@ impl<B: BlockT> sp_inherents::InherentDataProvider for InherentDataProvider<B> {
7454 ) -> Result < ( ) , sp_inherents:: Error > {
7555 let mut ext_guard = self . ext_mutex . lock ( ) . await ;
7656 let ext = ext_guard. deref_mut ( ) ;
77- let maybe_last_relay_chain_block_number = get_last_relay_chain_block_number :: < B > ( ext) ;
78- let maybe_para_id = get_para_id :: < B > ( ext) ;
79- let ( last_relay_chain_block_number, para_id) =
80- match ( maybe_last_relay_chain_block_number, maybe_para_id) {
81- ( Some ( last_relay_chain_block_number) , Some ( para_id) ) => {
82- ( last_relay_chain_block_number, para_id)
83- }
84- _ => {
85- log:: debug!( "Unable to provide para parachains inherent for this chain." ) ;
86- return Ok ( ( ) ) ;
87- }
88- } ;
57+ let Some ( para_id) = get_para_id :: < B > ( ext) else {
58+ log:: debug!( "Unable to provide para parachains inherent for this chain." ) ;
59+ return Ok ( ( ) ) ;
60+ } ;
8961
9062 let relay_chain_slot = cumulus_primitives_core:: relay_chain:: Slot :: from_timestamp (
9163 self . timestamp ,
9264 SlotDuration :: from_millis ( self . blocktime_millis ) ,
93- )
94- . encode ( ) ;
95-
96- let additional_key_values: Vec < ( Vec < u8 > , Vec < u8 > ) > = vec ! [
97- // Insert relay chain slot to pass Aura check
98- // https://github.com/paritytech/polkadot-sdk/blob/ef114a422291b44f8973739ab7858a29a523e6a2/cumulus/pallets/aura-ext/src/consensus_hook.rs#L69
99- (
100- cumulus_primitives_core:: relay_chain:: well_known_keys:: CURRENT_SLOT . to_vec( ) ,
101- relay_chain_slot,
102- ) ,
103- // Insert para header info to pass para inherent check
104- // https://github.com/paritytech/polkadot-sdk/blob/17b56fae2d976a3df87f34076875de8c26da0355/cumulus/pallets/parachain-system/src/lib.rs#L1296
105- (
106- cumulus_primitives_core:: relay_chain:: well_known_keys:: para_head( para_id. into( ) ) ,
107- HeadData ( self . parent_header. encode( ) ) . encode( ) ,
108- ) ,
109- ] ;
65+ ) ;
11066
11167 cumulus_client_parachain_inherent:: MockValidationDataInherentDataProvider {
112- relay_offset : last_relay_chain_block_number + 1u32 ,
68+ relay_offset : * relay_chain_slot as u32 ,
69+ current_para_block_head : Some ( HeadData ( self . parent_header . encode ( ) ) ) ,
11370 relay_parent_offset : self . relay_parent_offset ,
11471 relay_randomness_config : ( ) ,
115- xcm_config : cumulus_client_parachain_inherent:: MockXcmConfig :: default ( ) ,
116- additional_key_values : Some ( additional_key_values) ,
11772 para_id : para_id. into ( ) ,
11873 ..Default :: default ( )
11974 }
0 commit comments