1
- use crate :: {
2
- database:: provider:: OpenMessageRecord ,
3
- runtime:: { AggregatorRunnerTrait , RuntimeError } ,
4
- } ;
1
+ use crate :: runtime:: { AggregatorRunnerTrait , RuntimeError } ;
5
2
6
- use mithril_common:: entities:: { Beacon , SignedEntityType } ;
3
+ use mithril_common:: entities:: { Beacon , ProtocolMessage , SignedEntityType } ;
7
4
use slog_scope:: { crit, info, trace, warn} ;
8
5
use std:: fmt:: Display ;
9
6
use std:: sync:: Arc ;
@@ -22,7 +19,8 @@ pub struct ReadyState {
22
19
#[ derive( Clone , Debug , PartialEq ) ]
23
20
pub struct SigningState {
24
21
current_beacon : Beacon ,
25
- open_message : OpenMessageRecord ,
22
+ signed_entity_type : SignedEntityType ,
23
+ protocol_message : ProtocolMessage ,
26
24
}
27
25
28
26
#[ derive( Clone , Debug , PartialEq ) ]
@@ -276,7 +274,7 @@ impl AggregatorRuntime {
276
274
trace ! ( "launching transition from SIGNING to IDLE state" ) ;
277
275
let certificate = self
278
276
. runner
279
- . create_certificate ( & state. open_message . signed_entity_type )
277
+ . create_certificate ( & state. signed_entity_type )
280
278
. await ?
281
279
. ok_or_else ( || RuntimeError :: KeepState {
282
280
message : "not enough signature yet to create a certificate, waiting…" . to_string ( ) ,
@@ -286,7 +284,7 @@ impl AggregatorRuntime {
286
284
self . runner . drop_pending_certificate ( ) . await ?;
287
285
let ongoing_snapshot = self
288
286
. runner
289
- . create_snapshot_archive ( & state. current_beacon , & state. open_message . protocol_message )
287
+ . create_snapshot_archive ( & state. current_beacon , & state. protocol_message )
290
288
. await ?;
291
289
let locations = self
292
290
. runner
@@ -333,8 +331,7 @@ impl AggregatorRuntime {
333
331
. runner
334
332
. compute_protocol_message ( digester_result)
335
333
. await ?;
336
- let open_message = self
337
- . runner
334
+ self . runner
338
335
. create_open_message ( & signed_entity_type, & protocol_message)
339
336
. await ?;
340
337
let certificate_pending = self
@@ -349,7 +346,8 @@ impl AggregatorRuntime {
349
346
. await ?;
350
347
let state = SigningState {
351
348
current_beacon : new_beacon,
352
- open_message,
349
+ signed_entity_type,
350
+ protocol_message,
353
351
} ;
354
352
355
353
Ok ( state)
@@ -359,12 +357,14 @@ impl AggregatorRuntime {
359
357
#[ cfg( test) ]
360
358
mod tests {
361
359
360
+ use std:: path:: Path ;
361
+
362
362
use crate :: database:: provider:: OpenMessageRecord ;
363
+ use crate :: snapshotter:: OngoingSnapshot ;
363
364
364
365
use super :: super :: runner:: MockAggregatorRunner ;
365
366
use super :: * ;
366
367
367
- use mithril_common:: entities:: ProtocolMessage ;
368
368
use mithril_common:: era:: UnsupportedEraError ;
369
369
use mithril_common:: test_utils:: fake_data;
370
370
use mockall:: predicate;
@@ -642,7 +642,8 @@ mod tests {
642
642
643
643
beacon
644
644
} ,
645
- open_message : OpenMessageRecord :: dummy ( ) ,
645
+ signed_entity_type : SignedEntityType :: dummy ( ) ,
646
+ protocol_message : ProtocolMessage :: default ( ) ,
646
647
} ;
647
648
let mut runtime = init_runtime ( Some ( AggregatorState :: Signing ( state) ) , runner) . await ;
648
649
runtime. cycle ( ) . await . unwrap ( ) ;
@@ -651,7 +652,7 @@ mod tests {
651
652
}
652
653
653
654
#[ tokio:: test]
654
- async fn signing_multisig_is_not_created ( ) {
655
+ async fn signing_certificate_is_not_created ( ) {
655
656
let mut runner = MockAggregatorRunner :: new ( ) ;
656
657
runner
657
658
. expect_get_beacon_from_chain ( )
@@ -663,7 +664,8 @@ mod tests {
663
664
. returning ( |_| Ok ( None ) ) ;
664
665
let state = SigningState {
665
666
current_beacon : fake_data:: beacon ( ) ,
666
- open_message : OpenMessageRecord :: dummy ( ) ,
667
+ signed_entity_type : SignedEntityType :: dummy ( ) ,
668
+ protocol_message : ProtocolMessage :: default ( ) ,
667
669
} ;
668
670
let mut runtime = init_runtime ( Some ( AggregatorState :: Signing ( state) ) , runner) . await ;
669
671
runtime
@@ -674,29 +676,24 @@ mod tests {
674
676
assert_eq ! ( "signing" . to_string( ) , runtime. get_state( ) ) ;
675
677
}
676
678
677
- /* TODO: create a fake certificate to test the certificate creation.
678
679
#[ tokio:: test]
679
- async fn signing_multisig_is_created() {
680
- let (certificate_chain, _) = setup_certificate_chain(5, 1);
681
- let first_certificate = certificate_chain[0].clone();
682
- let multi_signature: ProtocolMultiSignature =
683
- key_decode_hex(&first_certificate.multi_signature as &HexEncodedKey).unwrap();
680
+ async fn signing_certificate_is_created ( ) {
684
681
let mut runner = MockAggregatorRunner :: new ( ) ;
685
682
runner
686
683
. expect_get_beacon_from_chain ( )
687
684
. once ( )
688
685
. returning ( || Ok ( fake_data:: beacon ( ) ) ) ;
689
686
runner
690
687
. expect_create_certificate ( )
691
- .return_once(move |_| Ok(Some(multi_signature )));
688
+ . return_once ( move |_| Ok ( Some ( fake_data :: certificate ( "whatever" . to_string ( ) ) ) ) ) ;
692
689
runner
693
690
. expect_drop_pending_certificate ( )
694
691
. once ( )
695
692
. returning ( || Ok ( Some ( fake_data:: certificate_pending ( ) ) ) ) ;
696
693
runner
697
694
. expect_create_snapshot_archive ( )
698
695
. once ( )
699
- .returning(|_| {
696
+ . returning ( |_, _ | {
700
697
Ok ( OngoingSnapshot :: new (
701
698
Path :: new ( "/tmp/archive.zip" ) . to_path_buf ( ) ,
702
699
1234 ,
@@ -706,25 +703,21 @@ mod tests {
706
703
. expect_upload_snapshot_archive ( )
707
704
. once ( )
708
705
. returning ( |_path| Ok ( vec ! [ "locA" . to_string( ) , "locB" . to_string( ) ] ) ) ;
709
- runner
710
- .expect_create_and_save_certificate()
711
- .once()
712
- .returning(|_, _| Ok(fake_data::certificate("whatever".to_string())));
713
706
runner
714
707
. expect_create_and_save_snapshot ( )
715
708
. once ( )
716
709
. returning ( |_, _, _| Ok ( fake_data:: snapshots ( 1 ) [ 0 ] . clone ( ) ) ) ;
717
710
718
711
let state = SigningState {
719
712
current_beacon : fake_data:: beacon ( ) ,
720
- working_certificate: WorkingCertificate::fake(),
713
+ signed_entity_type : SignedEntityType :: dummy ( ) ,
714
+ protocol_message : ProtocolMessage :: default ( ) ,
721
715
} ;
722
716
let mut runtime = init_runtime ( Some ( AggregatorState :: Signing ( state) ) , runner) . await ;
723
717
runtime. cycle ( ) . await . unwrap ( ) ;
724
718
725
719
assert_eq ! ( "idle" . to_string( ) , runtime. get_state( ) ) ;
726
720
}
727
- */
728
721
729
722
#[ tokio:: test]
730
723
pub async fn critical_error ( ) {
0 commit comments