11use anyhow:: { Context , anyhow} ;
22use async_trait:: async_trait;
3- use mithril_protocol_config:: interface:: MithrilNetworkConfigurationProvider ;
43use slog:: { Logger , debug} ;
54use std:: collections:: BTreeSet ;
65use std:: sync:: Arc ;
@@ -10,13 +9,15 @@ use mithril_cardano_node_chain::chain_observer::ChainObserver;
109use mithril_common:: StdResult ;
1110use mithril_common:: crypto_helper:: ProtocolAggregateVerificationKey ;
1211use mithril_common:: entities:: {
13- CardanoEra , CardanoTransactionsSigningConfig , Epoch , ProtocolParameters , SignedEntityConfig ,
14- SignedEntityTypeDiscriminants , Signer , SignerWithStake , Stake , SupportedEra , TotalSPOs ,
12+ CardanoEra , Epoch , ProtocolParameters , SignedEntityConfig , SignedEntityTypeDiscriminants ,
13+ Signer , SignerWithStake , Stake , SupportedEra , TotalSPOs ,
1514} ;
1615use mithril_common:: logging:: LoggerExtensions ;
1716use mithril_common:: protocol:: { MultiSigner as ProtocolMultiSigner , SignerBuilder } ;
1817use mithril_era:: EraChecker ;
1918use mithril_persistence:: store:: StakeStorer ;
19+ use mithril_protocol_config:: interface:: MithrilNetworkConfigurationProvider ;
20+ use mithril_protocol_config:: model:: MithrilNetworkConfiguration ;
2021
2122use crate :: { EpochSettingsStorer , VerificationKeyStorer , entities:: AggregatorEpochSettings } ;
2223
@@ -62,19 +63,32 @@ pub trait EpochService: Sync + Send {
6263 /// Get the current epoch for which the data stored in this service are computed.
6364 fn epoch_of_current_data ( & self ) -> StdResult < Epoch > ;
6465
66+ /// Get the network configuration for the current epoch.
67+ fn network_configuration ( & self ) -> StdResult < & MithrilNetworkConfiguration > ;
68+
6569 /// Get protocol parameters used for signing in the current epoch.
66- fn current_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > ;
70+ fn current_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
71+ Ok ( & self
72+ . network_configuration ( ) ?
73+ . configuration_for_aggregation
74+ . protocol_parameters )
75+ }
6776
6877 /// Get protocol parameters used for signing in the next epoch.
69- fn next_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > ;
78+ fn next_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
79+ Ok ( & self
80+ . network_configuration ( ) ?
81+ . configuration_for_next_aggregation
82+ . protocol_parameters )
83+ }
7084
7185 /// Get protocol parameters for signer registration.
72- fn signer_registration_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > ;
73-
74- /// Get cardano transactions signing configuration used in current epoch
75- fn current_cardano_transactions_signing_config (
76- & self ,
77- ) -> StdResult < & CardanoTransactionsSigningConfig > ;
86+ fn signer_registration_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
87+ Ok ( & self
88+ . network_configuration ( ) ?
89+ . configuration_for_registration
90+ . protocol_parameters )
91+ }
7892
7993 /// Get aggregate verification key for current epoch
8094 fn current_aggregate_verification_key ( & self ) -> StdResult < & ProtocolAggregateVerificationKey > ;
@@ -124,9 +138,7 @@ struct EpochData {
124138 cardano_era : CardanoEra ,
125139 mithril_era : SupportedEra ,
126140 epoch : Epoch ,
127- current_epoch_settings : AggregatorEpochSettings ,
128- next_epoch_settings : AggregatorEpochSettings ,
129- signer_registration_epoch_settings : AggregatorEpochSettings ,
141+ network_configuration : MithrilNetworkConfiguration ,
130142 current_signers_with_stake : Vec < SignerWithStake > ,
131143 next_signers_with_stake : Vec < SignerWithStake > ,
132144 current_signers : Vec < Signer > ,
@@ -295,45 +307,18 @@ impl EpochService for MithrilEpochService {
295307 . get_network_configuration ( epoch)
296308 . await ?;
297309
298- let current_epoch_settings = AggregatorEpochSettings {
299- protocol_parameters : network_configuration
300- . configuration_for_aggregation
301- . protocol_parameters ,
302- cardano_transactions_signing_config : network_configuration
303- . configuration_for_aggregation
304- . signed_entity_types_config
305- . cardano_transactions
306- . ok_or ( anyhow ! (
307- "Missing cardano transactions signing config for aggregation epoch {:?}" ,
308- epoch
309- ) ) ?,
310- } ;
311-
312- let next_epoch_settings = AggregatorEpochSettings {
313- protocol_parameters : network_configuration
314- . configuration_for_next_aggregation
315- . protocol_parameters ,
316- cardano_transactions_signing_config : network_configuration
317- . configuration_for_next_aggregation
318- . signed_entity_types_config
319- . cardano_transactions
320- . ok_or ( anyhow ! (
321- "Missing cardano transactions signing config for next aggregation epoch {:?}" ,
322- epoch
323- ) ) ?,
324- } ;
325-
326310 let signer_registration_epoch_settings = AggregatorEpochSettings {
327311 protocol_parameters : network_configuration
328312 . configuration_for_registration
329- . protocol_parameters ,
313+ . protocol_parameters
314+ . clone ( ) ,
330315 cardano_transactions_signing_config : network_configuration
331316 . configuration_for_registration
332317 . signed_entity_types_config
333318 . cardano_transactions
319+ . clone ( )
334320 . ok_or ( anyhow ! (
335- "Missing cardano transactions signing config for registration epoch {:?}" ,
336- epoch
321+ "Missing cardano transactions signing config for registration epoch {epoch:?}"
337322 ) ) ?,
338323 } ;
339324 self . insert_epoch_settings (
@@ -362,9 +347,14 @@ impl EpochService for MithrilEpochService {
362347 )
363348 . cloned ( )
364349 . collect ( ) ,
365- cardano_transactions_signing_config : current_epoch_settings
366- . cardano_transactions_signing_config
367- . clone ( ) ,
350+ cardano_transactions_signing_config : network_configuration
351+ . configuration_for_aggregation
352+ . signed_entity_types_config
353+ . cardano_transactions
354+ . clone ( )
355+ . ok_or ( anyhow ! (
356+ "Missing cardano transactions signing config for current epoch {epoch:?}"
357+ ) ) ?,
368358 } ;
369359
370360 let ( total_spo, total_stake) =
@@ -374,9 +364,7 @@ impl EpochService for MithrilEpochService {
374364 cardano_era,
375365 mithril_era,
376366 epoch,
377- current_epoch_settings,
378- next_epoch_settings,
379- signer_registration_epoch_settings,
367+ network_configuration,
380368 current_signers_with_stake,
381369 next_signers_with_stake,
382370 current_signers,
@@ -422,14 +410,20 @@ impl EpochService for MithrilEpochService {
422410
423411 let protocol_multi_signer = SignerBuilder :: new (
424412 & data. current_signers_with_stake ,
425- & data. current_epoch_settings . protocol_parameters ,
413+ & data
414+ . network_configuration
415+ . configuration_for_aggregation
416+ . protocol_parameters ,
426417 )
427418 . with_context ( || "Epoch service failed to build protocol multi signer" ) ?
428419 . build_multi_signer ( ) ;
429420
430421 let next_protocol_multi_signer = SignerBuilder :: new (
431422 & data. next_signers_with_stake ,
432- & data. next_epoch_settings . protocol_parameters ,
423+ & data
424+ . network_configuration
425+ . configuration_for_next_aggregation
426+ . protocol_parameters ,
433427 )
434428 . with_context ( || "Epoch service failed to build next protocol multi signer" ) ?
435429 . build_multi_signer ( ) ;
@@ -457,28 +451,8 @@ impl EpochService for MithrilEpochService {
457451 Ok ( self . unwrap_data ( ) ?. epoch )
458452 }
459453
460- fn current_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
461- Ok ( & self . unwrap_data ( ) ?. current_epoch_settings . protocol_parameters )
462- }
463-
464- fn next_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
465- Ok ( & self . unwrap_data ( ) ?. next_epoch_settings . protocol_parameters )
466- }
467-
468- fn signer_registration_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
469- Ok ( & self
470- . unwrap_data ( ) ?
471- . signer_registration_epoch_settings
472- . protocol_parameters )
473- }
474-
475- fn current_cardano_transactions_signing_config (
476- & self ,
477- ) -> StdResult < & CardanoTransactionsSigningConfig > {
478- Ok ( & self
479- . unwrap_data ( ) ?
480- . current_epoch_settings
481- . cardano_transactions_signing_config )
454+ fn network_configuration ( & self ) -> StdResult < & MithrilNetworkConfiguration > {
455+ Ok ( & self . unwrap_data ( ) ?. network_configuration )
482456 }
483457
484458 fn current_aggregate_verification_key ( & self ) -> StdResult < & ProtocolAggregateVerificationKey > {
@@ -600,14 +574,31 @@ impl FakeEpochServiceBuilder {
600574 . unwrap ( )
601575 . build_multi_signer ( ) ;
602576
577+ let network_configuration = MithrilNetworkConfiguration {
578+ epoch : self . epoch ,
579+ configuration_for_aggregation : self
580+ . current_epoch_settings
581+ . into_network_configuration_for_epoch (
582+ self . signed_entity_config . allowed_discriminants . clone ( ) ,
583+ ) ,
584+ configuration_for_next_aggregation : self
585+ . next_epoch_settings
586+ . into_network_configuration_for_epoch (
587+ self . signed_entity_config . allowed_discriminants . clone ( ) ,
588+ ) ,
589+ configuration_for_registration : self
590+ . signer_registration_epoch_settings
591+ . into_network_configuration_for_epoch (
592+ self . signed_entity_config . allowed_discriminants . clone ( ) ,
593+ ) ,
594+ } ;
595+
603596 FakeEpochService {
604597 epoch_data : Some ( EpochData {
605598 cardano_era : self . cardano_era ,
606599 mithril_era : self . mithril_era ,
607600 epoch : self . epoch ,
608- current_epoch_settings : self . current_epoch_settings ,
609- next_epoch_settings : self . next_epoch_settings ,
610- signer_registration_epoch_settings : self . signer_registration_epoch_settings ,
601+ network_configuration,
611602 current_signers_with_stake : self . current_signers_with_stake ,
612603 next_signers_with_stake : self . next_signers_with_stake ,
613604 current_signers,
@@ -712,16 +703,16 @@ impl EpochService for FakeEpochService {
712703 Ok ( ( ) )
713704 }
714705
715- async fn precompute_epoch_data ( & mut self ) -> StdResult < ( ) > {
716- if self . precompute_epoch_data_error {
717- anyhow:: bail!( "precompute_epoch_data fake error" ) ;
706+ async fn update_next_signers_with_stake ( & mut self ) -> StdResult < ( ) > {
707+ if self . update_next_signers_with_stake_error {
708+ anyhow:: bail!( "update_next_signers_with_stake fake error" ) ;
718709 }
719710 Ok ( ( ) )
720711 }
721712
722- async fn update_next_signers_with_stake ( & mut self ) -> StdResult < ( ) > {
723- if self . update_next_signers_with_stake_error {
724- anyhow:: bail!( "update_next_signers_with_stake fake error" ) ;
713+ async fn precompute_epoch_data ( & mut self ) -> StdResult < ( ) > {
714+ if self . precompute_epoch_data_error {
715+ anyhow:: bail!( "precompute_epoch_data fake error" ) ;
725716 }
726717 Ok ( ( ) )
727718 }
@@ -738,28 +729,8 @@ impl EpochService for FakeEpochService {
738729 Ok ( self . unwrap_data ( ) ?. epoch )
739730 }
740731
741- fn current_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
742- Ok ( & self . unwrap_data ( ) ?. current_epoch_settings . protocol_parameters )
743- }
744-
745- fn next_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
746- Ok ( & self . unwrap_data ( ) ?. next_epoch_settings . protocol_parameters )
747- }
748-
749- fn signer_registration_protocol_parameters ( & self ) -> StdResult < & ProtocolParameters > {
750- Ok ( & self
751- . unwrap_data ( ) ?
752- . signer_registration_epoch_settings
753- . protocol_parameters )
754- }
755-
756- fn current_cardano_transactions_signing_config (
757- & self ,
758- ) -> StdResult < & CardanoTransactionsSigningConfig > {
759- Ok ( & self
760- . unwrap_data ( ) ?
761- . current_epoch_settings
762- . cardano_transactions_signing_config )
732+ fn network_configuration ( & self ) -> StdResult < & MithrilNetworkConfiguration > {
733+ Ok ( & self . unwrap_data ( ) ?. network_configuration )
763734 }
764735
765736 fn current_aggregate_verification_key ( & self ) -> StdResult < & ProtocolAggregateVerificationKey > {
@@ -857,7 +828,6 @@ mod tests {
857828 epoch : Epoch ,
858829 protocol_parameters : ProtocolParameters ,
859830 next_protocol_parameters : ProtocolParameters ,
860- cardano_signing_config : CardanoTransactionsSigningConfig ,
861831 signer_registration_protocol_parameters : ProtocolParameters ,
862832 current_signers_with_stake : BTreeSet < SignerWithStake > ,
863833 next_signers_with_stake : BTreeSet < SignerWithStake > ,
@@ -885,9 +855,6 @@ mod tests {
885855 signer_registration_protocol_parameters : service
886856 . signer_registration_protocol_parameters ( ) ?
887857 . clone ( ) ,
888- cardano_signing_config : service
889- . current_cardano_transactions_signing_config ( ) ?
890- . clone ( ) ,
891858 current_signers_with_stake : service
892859 . current_signers_with_stake ( ) ?
893860 . clone ( )
@@ -1082,7 +1049,6 @@ mod tests {
10821049 protocol_parameters: current_epoch_fixture. protocol_parameters( ) ,
10831050 next_protocol_parameters: next_epoch_fixture. protocol_parameters( ) ,
10841051 signer_registration_protocol_parameters,
1085- cardano_signing_config: CardanoTransactionsSigningConfig :: dummy( ) ,
10861052 current_signers_with_stake: current_epoch_fixture
10871053 . signers_with_stake( )
10881054 . into_iter( )
@@ -1377,10 +1343,6 @@ mod tests {
13771343 "signer_registration_protocol_parameters" ,
13781344 service. signer_registration_protocol_parameters ( ) . err ( ) ,
13791345 ) ,
1380- (
1381- "current_cardano_transactions_signing_config" ,
1382- service. current_cardano_transactions_signing_config ( ) . err ( ) ,
1383- ) ,
13841346 (
13851347 "current_signers_with_stake" ,
13861348 service. current_signers_with_stake ( ) . err ( ) ,
@@ -1434,7 +1396,6 @@ mod tests {
14341396 assert ! ( service. current_protocol_parameters( ) . is_ok( ) ) ;
14351397 assert ! ( service. next_protocol_parameters( ) . is_ok( ) ) ;
14361398 assert ! ( service. signer_registration_protocol_parameters( ) . is_ok( ) ) ;
1437- assert ! ( service. current_cardano_transactions_signing_config( ) . is_ok( ) ) ;
14381399 assert ! ( service. current_signers_with_stake( ) . is_ok( ) ) ;
14391400 assert ! ( service. next_signers_with_stake( ) . is_ok( ) ) ;
14401401 assert ! ( service. current_signers( ) . is_ok( ) ) ;
0 commit comments