1
- use alloy:: eips:: BlockNumberOrTag ;
2
- use cliquenet:: { Address , AddressableCommittee } ;
3
- use multisig:: { Certificate , Committee , CommitteeId , Keypair , x25519} ;
4
- use sailfish:: types:: { ConsensusTime , Timestamp } ;
5
1
use std:: cmp:: min;
6
2
use std:: collections:: HashMap ;
7
3
use std:: iter:: { once, repeat_with} ;
8
4
use std:: net:: Ipv4Addr ;
9
5
use std:: num:: NonZeroUsize ;
10
6
use std:: sync:: Arc ;
11
- use timeboost:: builder:: CertifierConfig ;
7
+
8
+ use alloy:: eips:: BlockNumberOrTag ;
9
+ use cliquenet:: { Address , AddressableCommittee } ;
10
+ use multisig:: { Certificate , Committee , CommitteeId , Keypair , x25519} ;
11
+ use sailfish:: types:: { ConsensusTime , RoundNumber , Timestamp } ;
12
+ use timeboost:: builder:: Certifier ;
12
13
use timeboost:: config:: { CERTIFIER_PORT_OFFSET , ChainConfig , DECRYPTER_PORT_OFFSET , ParentChain } ;
13
14
use timeboost:: crypto:: prelude:: DkgDecKey ;
14
15
use timeboost:: sequencer:: { Output , SequencerConfig } ;
@@ -285,7 +286,7 @@ async fn run_handover(
285
286
}
286
287
287
288
/// Create sequencer configs.
288
- fn mk_configs (
289
+ async fn mk_configs (
289
290
id : CommitteeId ,
290
291
prev : & [ ( DecryptionKeyCell , SequencerConfig , CertifierConfig ) ] ,
291
292
keep : usize ,
@@ -313,30 +314,30 @@ fn mk_configs(
313
314
. chain ( repeat_with ( DkgDecKey :: generate) . take ( add. get ( ) ) )
314
315
. collect :: < Vec < _ > > ( ) ;
315
316
316
- let sf_addrs = prev
317
+ let mut sf_addrs = prev
317
318
. iter ( )
318
319
. take ( keep)
319
320
. map ( |c| c. 1 . sailfish_address ( ) . clone ( ) )
320
- . chain (
321
- repeat_with ( || {
322
- loop {
323
- if let Some ( port) = portpicker:: pick_unused_port ( ) {
324
- break Address :: from ( ( Ipv4Addr :: LOCALHOST , port) ) ;
325
- }
326
- }
327
- } )
328
- . take ( add. get ( ) ) ,
329
- )
330
321
. collect :: < Vec < _ > > ( ) ;
331
322
323
+ sf_addrs. extend (
324
+ alloc_ports ( add. get ( ) as u16 )
325
+ . await
326
+ . unwrap ( )
327
+ . into_iter ( )
328
+ . map ( |p| Address :: from ( ( Ipv4Addr :: LOCALHOST , p) ) ) ,
329
+ ) ;
330
+
332
331
let de_addrs = sf_addrs
333
332
. iter ( )
334
- . map ( |addr| Address :: from ( ( Ipv4Addr :: LOCALHOST , addr. port ( ) + CERTIFIER_PORT_OFFSET ) ) )
333
+ . cloned ( )
334
+ . map ( |addr| addr. with_offset ( DECRYPTER_PORT_OFFSET ) )
335
335
. collect :: < Vec < _ > > ( ) ;
336
336
337
337
let cert_addrs = sf_addrs
338
338
. iter ( )
339
- . map ( |addr| Address :: from ( ( Ipv4Addr :: LOCALHOST , addr. port ( ) + DECRYPTER_PORT_OFFSET ) ) )
339
+ . cloned ( )
340
+ . map ( |addr| addr. with_offset ( CERTIFIER_PORT_OFFSET ) )
340
341
. collect :: < Vec < _ > > ( ) ;
341
342
342
343
let committee = Committee :: new (
@@ -482,28 +483,30 @@ impl TestConfig {
482
483
self
483
484
}
484
485
485
- fn build ( self ) -> Vec < ( DecryptionKeyCell , SequencerConfig , CertifierConfig ) > {
486
+ async fn build ( self ) -> Vec < ( DecryptionKeyCell , SequencerConfig , CertifierConfig ) > {
486
487
mk_configs (
487
488
self . committee_id ,
488
489
& self . prev_configs ,
489
490
self . keep ,
490
491
self . add ,
491
492
self . set_prev ,
492
493
)
494
+ . await
493
495
}
494
496
}
495
497
496
498
#[ tokio:: test]
497
499
async fn handover_0_to_5 ( ) {
498
500
init_logging ( ) ;
499
501
500
- let c1 = TestConfig :: new ( 0 ) . build ( ) ;
502
+ let c1 = TestConfig :: new ( 0 ) . build ( ) . await ;
501
503
let c2 = TestConfig :: new ( 1 )
502
504
. with_prev_configs ( & c1)
503
505
. keep_nodes ( 0 )
504
506
. add_nodes ( NonZeroUsize :: new ( 5 ) . unwrap ( ) )
505
507
. set_previous_committee ( true )
506
- . build ( ) ;
508
+ . build ( )
509
+ . await ;
507
510
508
511
run_handover ( c1, c2) . await ;
509
512
}
@@ -512,13 +515,14 @@ async fn handover_0_to_5() {
512
515
async fn handover_1_to_4 ( ) {
513
516
init_logging ( ) ;
514
517
515
- let c1 = TestConfig :: new ( 0 ) . build ( ) ;
518
+ let c1 = TestConfig :: new ( 0 ) . build ( ) . await ;
516
519
let c2 = TestConfig :: new ( 1 )
517
520
. with_prev_configs ( & c1)
518
521
. keep_nodes ( 1 )
519
522
. add_nodes ( NonZeroUsize :: new ( 4 ) . unwrap ( ) )
520
523
. set_previous_committee ( true )
521
- . build ( ) ;
524
+ . build ( )
525
+ . await ;
522
526
523
527
run_handover ( c1, c2) . await ;
524
528
}
@@ -527,13 +531,14 @@ async fn handover_1_to_4() {
527
531
async fn handover_2_to_3 ( ) {
528
532
init_logging ( ) ;
529
533
530
- let c1 = TestConfig :: new ( 0 ) . build ( ) ;
534
+ let c1 = TestConfig :: new ( 0 ) . build ( ) . await ;
531
535
let c2 = TestConfig :: new ( 1 )
532
536
. with_prev_configs ( & c1)
533
537
. keep_nodes ( 2 )
534
538
. add_nodes ( NonZeroUsize :: new ( 3 ) . unwrap ( ) )
535
539
. set_previous_committee ( true )
536
- . build ( ) ;
540
+ . build ( )
541
+ . await ;
537
542
538
543
run_handover ( c1, c2) . await ;
539
544
}
@@ -542,39 +547,42 @@ async fn handover_2_to_3() {
542
547
async fn handover_3_to_2 ( ) {
543
548
init_logging ( ) ;
544
549
545
- let c1 = TestConfig :: new ( 0 ) . build ( ) ;
550
+ let c1 = TestConfig :: new ( 0 ) . build ( ) . await ;
546
551
let c2 = TestConfig :: new ( 1 )
547
552
. with_prev_configs ( & c1)
548
553
. keep_nodes ( 3 )
549
554
. add_nodes ( NonZeroUsize :: new ( 2 ) . unwrap ( ) )
550
555
. set_previous_committee ( true )
551
- . build ( ) ;
556
+ . build ( )
557
+ . await ;
552
558
run_handover ( c1, c2) . await ;
553
559
}
554
560
555
561
#[ tokio:: test]
556
562
async fn handover_4_to_1 ( ) {
557
563
init_logging ( ) ;
558
564
559
- let c1 = TestConfig :: new ( 0 ) . build ( ) ;
565
+ let c1 = TestConfig :: new ( 0 ) . build ( ) . await ;
560
566
let c2 = TestConfig :: new ( 1 )
561
567
. with_prev_configs ( & c1)
562
568
. keep_nodes ( 4 )
563
569
. add_nodes ( NonZeroUsize :: new ( 1 ) . unwrap ( ) )
564
570
. set_previous_committee ( true )
565
- . build ( ) ;
571
+ . build ( )
572
+ . await ;
566
573
run_handover ( c1, c2) . await ;
567
574
}
568
575
569
576
#[ tokio:: test]
570
577
async fn handover_3_to_5 ( ) {
571
578
init_logging ( ) ;
572
- let c1 = TestConfig :: new ( 0 ) . build ( ) ;
579
+ let c1 = TestConfig :: new ( 0 ) . build ( ) . await ;
573
580
let c2 = TestConfig :: new ( 1 )
574
581
. with_prev_configs ( & c1)
575
582
. keep_nodes ( 3 )
576
583
. add_nodes ( NonZeroUsize :: new ( 5 ) . unwrap ( ) )
577
584
. set_previous_committee ( true )
578
- . build ( ) ;
585
+ . build ( )
586
+ . await ;
579
587
run_handover ( c1, c2) . await ;
580
588
}
0 commit comments