1
1
use anyhow:: Error ;
2
2
use chrono:: Local ;
3
+ use mithril_protocol_config:: model:: MithrilNetworkConfiguration ;
3
4
use slog:: { Logger , debug, info} ;
4
5
use std:: { fmt:: Display , ops:: Deref , sync:: Arc , time:: Duration } ;
5
6
use tokio:: sync:: Mutex ;
6
7
7
8
use mithril_common:: {
8
9
crypto_helper:: ProtocolInitializerError ,
9
- entities:: { Epoch , TimePoint } ,
10
+ entities:: { Epoch , Signer , TimePoint } ,
10
11
logging:: LoggerExtensions ,
11
12
} ;
12
13
13
- use crate :: {
14
- MetricsService ,
15
- entities:: { BeaconToSign , SignerEpochSettings } ,
16
- services:: AggregatorClientError ,
17
- } ;
14
+ use crate :: { MetricsService , entities:: BeaconToSign , services:: AggregatorClientError } ;
18
15
19
16
use super :: { Runner , RuntimeError } ;
20
17
@@ -167,7 +164,7 @@ impl StateMachine {
167
164
"→ Epoch has changed, transiting to Unregistered"
168
165
) ;
169
166
* state = self . transition_from_unregistered_to_unregistered ( new_epoch) . await ?;
170
- } else if let Some ( epoch_settings ) = self
167
+ } else if let Some ( signer_settings ) = self
171
168
. runner
172
169
. get_epoch_settings ( )
173
170
. await
@@ -176,19 +173,33 @@ impl StateMachine {
176
173
nested_error : Some ( e) ,
177
174
} ) ?
178
175
{
179
- info ! ( self . logger, "→ Epoch settings found" ) ;
180
- if epoch_settings. epoch >= * epoch {
176
+ info ! ( self . logger, "→ Epoch settings found" ) ; //TODO Do we switch the logs and type from SignerEpochSettings to SignerSettings since now we only read current and next signer from it ?
177
+ let network_configuration = self
178
+ . runner
179
+ . get_mithril_network_configuration ( )
180
+ . await
181
+ . map_err ( |e| RuntimeError :: KeepState {
182
+ message : "could not retrieve mithril network configuration" . to_string ( ) ,
183
+ nested_error : Some ( e) ,
184
+ } ) ?;
185
+ info ! ( self . logger, "→ Mithril network configuration found" ) ;
186
+
187
+ if network_configuration. epoch >= * epoch {
181
188
info ! ( self . logger, "New Epoch found" ) ;
182
189
info ! ( self . logger, " ⋅ Transiting to Registered" ) ;
183
190
* state = self
184
191
. transition_from_unregistered_to_one_of_registered_states (
185
- epoch_settings,
192
+ network_configuration,
193
+ signer_settings. current_signers ,
194
+ signer_settings. next_signers ,
186
195
)
187
196
. await ?;
188
197
} else {
189
198
info ! (
190
- self . logger, " ⋅ Epoch settings found, but its epoch is behind the known epoch, waiting…" ;
191
- "epoch_settings" => ?epoch_settings,
199
+ self . logger, " ⋅ Signer settings and Network Configuration found, but its epoch is behind the known epoch, waiting…" ;
200
+ "network_configuration" => ?network_configuration,
201
+ "current_singer" => ?signer_settings. current_signers,
202
+ "next_signer" => ?signer_settings. next_signers,
192
203
"known_epoch" => ?epoch,
193
204
) ;
194
205
}
@@ -286,7 +297,9 @@ impl StateMachine {
286
297
/// Launch the transition process from the `Unregistered` to `ReadyToSign` or `RegisteredNotAbleToSign` state.
287
298
async fn transition_from_unregistered_to_one_of_registered_states (
288
299
& self ,
289
- epoch_settings : SignerEpochSettings ,
300
+ mithril_network_configuration : MithrilNetworkConfiguration ,
301
+ current_signer : Vec < Signer > ,
302
+ next_signer : Vec < Signer > ,
290
303
) -> Result < SignerState , RuntimeError > {
291
304
self . metrics_service
292
305
. get_signer_registration_total_since_startup_counter ( )
@@ -302,7 +315,7 @@ impl StateMachine {
302
315
} ) ?;
303
316
304
317
self . runner
305
- . inform_epoch_settings ( epoch_settings )
318
+ . inform_epoch_settings ( mithril_network_configuration , current_signer , next_signer )
306
319
. await
307
320
. map_err ( |e| RuntimeError :: KeepState {
308
321
message : format ! (
@@ -474,11 +487,13 @@ impl StateMachine {
474
487
mod tests {
475
488
use anyhow:: anyhow;
476
489
use chrono:: DateTime ;
490
+ use mithril_protocol_config:: model:: MithrilNetworkConfiguration ;
477
491
use mockall:: predicate;
478
492
479
493
use mithril_common:: entities:: { ChainPoint , Epoch , ProtocolMessage , SignedEntityType } ;
480
494
use mithril_common:: test:: double:: { Dummy , fake_data} ;
481
495
496
+ use crate :: SignerEpochSettings ;
482
497
use crate :: runtime:: runner:: MockSignerRunner ;
483
498
use crate :: services:: AggregatorClientError ;
484
499
use crate :: test_tools:: TestLogger ;
@@ -528,7 +543,7 @@ mod tests {
528
543
async fn unregistered_epoch_settings_behind_known_epoch ( ) {
529
544
let mut runner = MockSignerRunner :: new ( ) ;
530
545
let epoch_settings = SignerEpochSettings {
531
- epoch : Epoch ( 3 ) ,
546
+ epoch : Epoch ( 999 ) , // epoch is no longer read from get_epoch_settings anymore but from mithril network configuration
532
547
registration_protocol_parameters : fake_data:: protocol_parameters ( ) ,
533
548
current_signers : vec ! [ ] ,
534
549
next_signers : vec ! [ ] ,
@@ -539,6 +554,17 @@ mod tests {
539
554
. expect_get_epoch_settings ( )
540
555
. once ( )
541
556
. returning ( move || Ok ( Some ( epoch_settings. to_owned ( ) ) ) ) ;
557
+ runner
558
+ . expect_get_mithril_network_configuration ( )
559
+ . once ( )
560
+ . returning ( || {
561
+ Ok ( MithrilNetworkConfiguration {
562
+ epoch : Epoch ( 3 ) ,
563
+ signer_registration_protocol_parameters : fake_data:: protocol_parameters ( ) ,
564
+ available_signed_entity_types : Default :: default ( ) ,
565
+ signed_entity_types_config : Default :: default ( ) ,
566
+ } )
567
+ } ) ;
542
568
runner. expect_get_current_time_point ( ) . once ( ) . returning ( || {
543
569
Ok ( TimePoint {
544
570
epoch : Epoch ( 4 ) ,
@@ -567,11 +593,21 @@ mod tests {
567
593
. once ( )
568
594
. returning ( || Ok ( Some ( SignerEpochSettings :: dummy ( ) ) ) ) ;
569
595
596
+ runner
597
+ . expect_get_mithril_network_configuration ( )
598
+ . once ( )
599
+ . returning ( || Ok ( MithrilNetworkConfiguration :: dummy ( ) ) ) ;
600
+
570
601
runner
571
602
. expect_inform_epoch_settings ( )
572
- . with ( predicate:: eq ( SignerEpochSettings :: dummy ( ) ) )
603
+ . with (
604
+ //todo do we really want to specify a WITH ?
605
+ predicate:: eq ( MithrilNetworkConfiguration :: dummy ( ) ) ,
606
+ predicate:: eq ( SignerEpochSettings :: dummy ( ) . current_signers ) ,
607
+ predicate:: eq ( SignerEpochSettings :: dummy ( ) . next_signers ) ,
608
+ )
573
609
. once ( )
574
- . returning ( |_| Ok ( ( ) ) ) ;
610
+ . returning ( |_, _ , _ | Ok ( ( ) ) ) ;
575
611
576
612
runner
577
613
. expect_get_current_time_point ( )
@@ -615,11 +651,21 @@ mod tests {
615
651
. once ( )
616
652
. returning ( || Ok ( Some ( SignerEpochSettings :: dummy ( ) ) ) ) ;
617
653
654
+ runner
655
+ . expect_get_mithril_network_configuration ( )
656
+ . once ( )
657
+ . returning ( || Ok ( MithrilNetworkConfiguration :: dummy ( ) ) ) ;
658
+
618
659
runner
619
660
. expect_inform_epoch_settings ( )
620
- . with ( predicate:: eq ( SignerEpochSettings :: dummy ( ) ) )
661
+ . with (
662
+ //todo do we really want to specify a WITH ?
663
+ predicate:: eq ( MithrilNetworkConfiguration :: dummy ( ) ) ,
664
+ predicate:: eq ( SignerEpochSettings :: dummy ( ) . current_signers ) ,
665
+ predicate:: eq ( SignerEpochSettings :: dummy ( ) . next_signers ) ,
666
+ )
621
667
. once ( )
622
- . returning ( |_| Ok ( ( ) ) ) ;
668
+ . returning ( |_, _ , _ | Ok ( ( ) ) ) ;
623
669
624
670
runner
625
671
. expect_get_current_time_point ( )
@@ -667,11 +713,21 @@ mod tests {
667
713
. once ( )
668
714
. returning ( || Ok ( Some ( SignerEpochSettings :: dummy ( ) ) ) ) ;
669
715
716
+ runner
717
+ . expect_get_mithril_network_configuration ( )
718
+ . once ( )
719
+ . returning ( || Ok ( MithrilNetworkConfiguration :: dummy ( ) ) ) ;
720
+
670
721
runner
671
722
. expect_inform_epoch_settings ( )
672
- . with ( predicate:: eq ( SignerEpochSettings :: dummy ( ) ) )
723
+ . with (
724
+ //todo do we really want to specify a WITH ?
725
+ predicate:: eq ( MithrilNetworkConfiguration :: dummy ( ) ) ,
726
+ predicate:: eq ( SignerEpochSettings :: dummy ( ) . current_signers ) ,
727
+ predicate:: eq ( SignerEpochSettings :: dummy ( ) . next_signers ) ,
728
+ )
673
729
. once ( )
674
- . returning ( |_| Ok ( ( ) ) ) ;
730
+ . returning ( |_, _ , _ | Ok ( ( ) ) ) ;
675
731
676
732
runner
677
733
. expect_get_current_time_point ( )
0 commit comments