@@ -47,7 +47,9 @@ pub trait EpochSettingsStorer:
4747 ) -> StdResult < ( ) > {
4848 for ( epoch, epoch_configuration) in [
4949 (
50- network_configuration. epoch . offset_to_signer_retrieval_epoch ( ) ?,
50+ network_configuration
51+ . epoch
52+ . offset_to_signer_retrieval_epoch_saturating ( ) ,
5153 & network_configuration. configuration_for_aggregation ,
5254 ) ,
5355 (
@@ -242,4 +244,43 @@ mod tests {
242244 let epoch_settings_stored = store. get_epoch_settings ( epoch + 2 ) . await . unwrap ( ) ;
243245 assert ! ( epoch_settings_stored. is_none( ) ) ;
244246 }
247+
248+ #[ tokio:: test]
249+ async fn test_handle_discrepancies_at_startup_at_epoch_zero_clamps_the_aggregation_epoch ( ) {
250+ let epoch_settings = AggregatorEpochSettings :: dummy ( ) ;
251+ let mut aggregation_epoch_settings = epoch_settings. clone ( ) ;
252+ aggregation_epoch_settings. protocol_parameters . k += 15 ;
253+
254+ let mut next_aggregation_epoch_settings = epoch_settings. clone ( ) ;
255+ next_aggregation_epoch_settings. protocol_parameters . k += 26 ;
256+
257+ let mut registration_epoch_settings = epoch_settings. clone ( ) ;
258+ registration_epoch_settings. protocol_parameters . k += 37 ;
259+
260+ let epoch = Epoch ( 0 ) ;
261+ let store = FakeEpochSettingsStorer :: new ( vec ! [ ] ) ;
262+ store
263+ . handle_discrepancies_at_startup ( & MithrilNetworkConfiguration {
264+ epoch,
265+ configuration_for_aggregation : aggregation_epoch_settings
266+ . clone ( )
267+ . into_network_configuration_for_epoch ( BTreeSet :: new ( ) ) ,
268+ configuration_for_next_aggregation : next_aggregation_epoch_settings
269+ . into_network_configuration_for_epoch ( BTreeSet :: new ( ) ) ,
270+ configuration_for_registration : registration_epoch_settings
271+ . clone ( )
272+ . into_network_configuration_for_epoch ( BTreeSet :: new ( ) ) ,
273+ } )
274+ . await
275+ . unwrap ( ) ;
276+
277+ let epoch_settings_stored = store. get_epoch_settings ( Epoch ( 0 ) ) . await . unwrap ( ) ;
278+ assert_eq ! ( Some ( aggregation_epoch_settings) , epoch_settings_stored) ;
279+
280+ let epoch_settings_stored = store. get_epoch_settings ( Epoch ( 1 ) ) . await . unwrap ( ) ;
281+ assert_eq ! ( Some ( registration_epoch_settings) , epoch_settings_stored) ;
282+
283+ let epoch_settings_stored = store. get_epoch_settings ( Epoch ( 2 ) ) . await . unwrap ( ) ;
284+ assert ! ( epoch_settings_stored. is_none( ) ) ;
285+ }
245286}
0 commit comments