@@ -13,7 +13,6 @@ use sidechain_domain::{
1313 DelegatorKey , McBlockHash , ScEpochNumber , mainchain_epoch:: MainchainEpochConfig ,
1414} ;
1515use sidechain_mc_hash:: { McHashDataSource , McHashInherentDataProvider as McHashIDP } ;
16- use sidechain_slots:: ScSlotConfig ;
1716use sp_api:: ProvideRuntimeApi ;
1817use sp_block_participation:: {
1918 BlockParticipationApi ,
@@ -81,16 +80,14 @@ where
8180 governed_map_data_source,
8281 bridge_data_source,
8382 } = self ;
84- let CreateInherentDataConfig { mc_epoch_config, sc_slot_config , time_source } = config;
83+ let CreateInherentDataConfig { mc_epoch_config, slot_duration , time_source, .. } = config;
8584
86- let ( slot, timestamp) =
87- timestamp_and_slot_cidp ( sc_slot_config. slot_duration , time_source. clone ( ) ) ;
85+ let ( slot, timestamp) = timestamp_and_slot_cidp ( * slot_duration, time_source. clone ( ) ) ;
8886 let parent_header = client. expect_header ( parent_hash) ?;
8987
9088 // note: We pass slot start time to `McHashIDP` instead of timestamp for backward compatibility
9189 // with the old `McHashIDP` version that was slot-based.
92- let slot_start_timestamp =
93- Timestamp :: new ( sc_slot_config. slot_start_time ( * slot) . unix_millis ( ) ) ;
90+ let slot_start_timestamp = config. slot_start_time ( * slot) ;
9491 let mc_hash = McHashIDP :: new_proposal (
9592 parent_header,
9693 mc_hash_data_source. as_ref ( ) ,
10097
10198 let ariadne_data_provider = AriadneIDP :: new (
10299 client. as_ref ( ) ,
103- sc_slot_config . epoch_duration ( ) . as_millis ( ) as u64 ,
100+ config . sc_epoch_duration_millis ,
104101 mc_epoch_config,
105102 parent_hash,
106103 ( * timestamp) . as_millis ( ) ,
@@ -152,7 +149,7 @@ pub struct VerifierCIDP<T> {
152149
153150impl < T : Send + Sync > CurrentSlotProvider for VerifierCIDP < T > {
154151 fn slot ( & self ) -> Slot {
155- * timestamp_and_slot_cidp ( self . config . slot_duration ( ) , self . config . time_source . clone ( ) ) . 0
152+ * timestamp_and_slot_cidp ( self . config . slot_duration , self . config . time_source . clone ( ) ) . 0
156153 }
157154}
158155
@@ -187,19 +184,16 @@ where
187184 governed_map_data_source,
188185 bridge_data_source,
189186 } = self ;
190- let CreateInherentDataConfig { mc_epoch_config, sc_slot_config , .. } = config;
187+ let CreateInherentDataConfig { mc_epoch_config, .. } = config;
191188
192189 // note: Because it's not exposed during block verification, we are approximating the block
193190 // timestamp by the starting timestamp of the slots. This is also needed for backward compatibility
194191 // of [McHashIDP] for chains that used the old slot-based version of it.
195- let timestamp = TimestampIDP :: new ( Timestamp :: new (
196- sc_slot_config. slot_start_time ( verified_block_slot) . unix_millis ( ) ,
197- ) ) ;
192+ let timestamp = TimestampIDP :: new ( config. slot_start_time ( verified_block_slot) ) ;
198193
199194 let parent_header = client. expect_header ( parent_hash) ?;
200195 let parent_slot = slot_from_predigest ( & parent_header) ?;
201- let parent_slot_timestamp = parent_slot
202- . map ( |slot| Timestamp :: new ( sc_slot_config. slot_start_time ( slot) . unix_millis ( ) ) ) ;
196+ let parent_slot_timestamp = parent_slot. map ( |slot| config. slot_start_time ( slot) ) ;
203197
204198 let mc_state_reference = McHashIDP :: new_verification (
205199 parent_header,
@@ -212,7 +206,7 @@ where
212206
213207 let ariadne_data_provider = AriadneIDP :: new (
214208 client. as_ref ( ) ,
215- sc_slot_config . epoch_duration ( ) . as_millis ( ) as u64 ,
209+ config . sc_epoch_duration_millis ,
216210 mc_epoch_config,
217211 parent_hash,
218212 ( * timestamp) . as_millis ( ) ,
@@ -263,16 +257,16 @@ pub fn slot_from_predigest(
263257}
264258
265259#[ derive( new, Clone ) ]
266- pub ( crate ) struct CreateInherentDataConfig {
260+ pub struct CreateInherentDataConfig {
267261 pub mc_epoch_config : MainchainEpochConfig ,
268- // TODO ETCM-4079 make sure that this struct can be instantiated only if sidechain epoch duration is divisible by slot_duration
269- pub sc_slot_config : ScSlotConfig ,
262+ pub slot_duration : SlotDuration ,
263+ pub sc_epoch_duration_millis : u64 ,
270264 pub time_source : Arc < dyn TimeSource + Send + Sync > ,
271265}
272266
273267impl CreateInherentDataConfig {
274- pub fn slot_duration ( & self ) -> SlotDuration {
275- self . sc_slot_config . slot_duration
268+ pub fn slot_start_time ( & self , slot : Slot ) -> Timestamp {
269+ Timestamp :: new ( self . slot_duration . as_millis ( ) * u64 :: from ( slot ) )
276270 }
277271}
278272
0 commit comments