@@ -18,7 +18,7 @@ use beacon_node_fallback::{
18
18
} ;
19
19
pub use cli:: Node ;
20
20
use config:: Config ;
21
- use database:: NetworkDatabase ;
21
+ use database:: { NetworkDatabase , OwnOperatorId } ;
22
22
use duties_tracker:: { duties_tracker:: DutiesTracker , voluntary_exit_tracker:: VoluntaryExitTracker } ;
23
23
use eth:: {
24
24
index_sync:: start_validator_index_syncer, voluntary_exit_processor:: start_exit_processor,
@@ -38,17 +38,15 @@ use sensitive_url::SensitiveUrl;
38
38
use signature_collector:: SignatureCollectorManager ;
39
39
use slashing_protection:: SlashingDatabase ;
40
40
use slot_clock:: { SlotClock , SystemTimeSlotClock } ;
41
- use ssv_types:: OperatorId ;
42
41
use subnet_service:: { SUBNET_COUNT , SubnetId , start_subnet_service} ;
43
42
use task_executor:: TaskExecutor ;
44
43
use tokio:: {
45
44
net:: TcpListener ,
46
- select,
47
- sync:: { mpsc, mpsc:: unbounded_channel, oneshot, oneshot:: Receiver } ,
45
+ sync:: { mpsc, mpsc:: unbounded_channel} ,
48
46
time:: sleep,
49
47
} ;
50
48
use tracing:: { debug, error, info, warn} ;
51
- use types:: { ChainSpec , EthSpec , Hash256 } ;
49
+ use types:: { EthSpec , Hash256 } ;
52
50
use validator_metrics:: set_gauge;
53
51
use validator_services:: {
54
52
attestation_service:: AttestationServiceBuilder ,
@@ -381,7 +379,6 @@ impl Client {
381
379
let voluntary_exit_tracker = Arc :: new ( VoluntaryExitTracker :: new ( ) ) ;
382
380
383
381
// Start syncer
384
- let ( historic_finished_tx, historic_finished_rx) = oneshot:: channel ( ) ;
385
382
let mut syncer = eth:: SsvEventSyncer :: new (
386
383
database. clone ( ) ,
387
384
index_sync_tx,
@@ -390,15 +387,14 @@ impl Client {
390
387
http_urls : config. execution_nodes ,
391
388
ws_url : config. execution_nodes_websocket ,
392
389
network : config. global_config . ssv_network . clone ( ) ,
393
- historic_finished_notify : Some ( historic_finished_tx) ,
394
390
} ,
395
391
)
396
392
. await
397
393
. map_err ( |e| format ! ( "Unable to create syncer: {e}" ) ) ?;
398
394
399
- // Access to the operational status of the sync . This can be passed around to condition
400
- // duties based on the current status of the sync
401
- let _operational_status = syncer. operational_status ( ) ;
395
+ // Access to the sync status. This can be passed around to condition duties based on whether
396
+ // we are synced.
397
+ let is_synced = syncer. is_synced ( ) ;
402
398
403
399
executor. spawn (
404
400
async move {
@@ -409,10 +405,7 @@ impl Client {
409
405
"syncer" ,
410
406
) ;
411
407
412
- // Wait until we have an operator id and historical sync is done
413
- let operator_id = wait_for_operator_id_and_sync ( & database, historic_finished_rx, & spec)
414
- . await
415
- . ok_or ( "Failed waiting for operator id" ) ?;
408
+ let operator_id = OwnOperatorId :: new ( database. watch ( ) ) ;
416
409
417
410
// Network sender/receiver
418
411
let ( network_tx, network_rx) = mpsc:: channel :: < ( SubnetId , Vec < u8 > ) > ( 9001 ) ;
@@ -442,9 +435,10 @@ impl Client {
442
435
processor_senders. clone ( ) ,
443
436
network_tx. clone ( ) ,
444
437
key. clone ( ) ,
445
- operator_id,
438
+ operator_id. clone ( ) ,
446
439
Some ( message_validator. clone ( ) ) ,
447
440
SUBNET_COUNT ,
441
+ is_synced. clone ( ) ,
448
442
) ?)
449
443
} else {
450
444
Arc :: new ( ImpostorMessageSender :: new ( network_tx. clone ( ) , SUBNET_COUNT ) )
@@ -453,7 +447,7 @@ impl Client {
453
447
// Create the signature collector
454
448
let signature_collector = SignatureCollectorManager :: new (
455
449
processor_senders. clone ( ) ,
456
- operator_id,
450
+ operator_id. clone ( ) ,
457
451
config. global_config . ssv_network . ssv_domain_type . clone ( ) ,
458
452
message_sender. clone ( ) ,
459
453
slot_clock. clone ( ) ,
@@ -463,7 +457,7 @@ impl Client {
463
457
// Create the qbft manager
464
458
let qbft_manager = QbftManager :: new (
465
459
processor_senders. clone ( ) ,
466
- operator_id,
460
+ operator_id. clone ( ) ,
467
461
slot_clock. clone ( ) ,
468
462
message_sender,
469
463
config. global_config . ssv_network . ssv_domain_type . clone ( ) ,
@@ -528,6 +522,7 @@ impl Client {
528
522
config. builder_proposals ,
529
523
config. builder_boost_factor ,
530
524
config. prefer_builder_proposals ,
525
+ is_synced. clone ( ) ,
531
526
) ;
532
527
533
528
start_exit_processor (
@@ -566,6 +561,24 @@ impl Client {
566
561
ctx. write ( ) . duties_service = Some ( duties_service. clone ( ) ) ;
567
562
}
568
563
564
+ // Spawn notifier for logging and metrics
565
+ spawn_notifier (
566
+ duties_service. clone ( ) ,
567
+ database. watch ( ) ,
568
+ is_synced. clone ( ) ,
569
+ executor. clone ( ) ,
570
+ & spec,
571
+ ) ;
572
+
573
+ // Wait for sync to complete before starting services
574
+ info ! ( "Waiting for sync to complete before starting services..." ) ;
575
+ is_synced
576
+ . clone ( )
577
+ . wait_for ( |& is_synced| is_synced)
578
+ . await
579
+ . map_err ( |_| "Sync watch channel closed" ) ?;
580
+ info ! ( "Sync complete, starting services..." ) ;
581
+
569
582
let mut block_service_builder = BlockServiceBuilder :: new ( )
570
583
. slot_clock ( slot_clock. clone ( ) )
571
584
. validator_store ( validator_store. clone ( ) )
@@ -644,13 +657,6 @@ impl Client {
644
657
645
658
http_api_shared_state. write ( ) . database_state = Some ( database. watch ( ) ) ;
646
659
647
- spawn_notifier (
648
- duties_service. clone ( ) ,
649
- database. watch ( ) ,
650
- executor. clone ( ) ,
651
- & spec,
652
- ) ;
653
-
654
660
if !config. disable_latency_measurement_service {
655
661
start_latency_service ( executor. clone ( ) , slot_clock. clone ( ) , beacon_nodes. clone ( ) ) ;
656
662
}
@@ -831,33 +837,6 @@ async fn poll_whilst_waiting_for_genesis(
831
837
}
832
838
}
833
839
834
- async fn wait_for_operator_id_and_sync (
835
- database : & Arc < NetworkDatabase > ,
836
- mut sync_notification : Receiver < ( ) > ,
837
- spec : & Arc < ChainSpec > ,
838
- ) -> Option < OperatorId > {
839
- let sleep_duration = Duration :: from_secs ( spec. seconds_per_slot ) ;
840
- let mut state = database. watch ( ) ;
841
- let id = loop {
842
- select ! {
843
- result = state. changed( ) => {
844
- result. ok( ) ?;
845
- if let Some ( id) = state. borrow( ) . get_own_id( ) {
846
- break id;
847
- }
848
- }
849
- _ = sleep( sleep_duration) => info!( "Waiting for operator id" ) ,
850
- }
851
- } ;
852
- info ! ( id = * id, "Operator found on chain" ) ;
853
- loop {
854
- select ! {
855
- result = & mut sync_notification => return result. ok( ) . map( |_| id) ,
856
- _ = sleep( sleep_duration) => info!( "Waiting for historical sync to finish" ) ,
857
- }
858
- }
859
- }
860
-
861
840
pub fn load_pem_certificate < P : AsRef < Path > > ( pem_path : P ) -> Result < Certificate , String > {
862
841
let mut buf = Vec :: new ( ) ;
863
842
File :: open ( & pem_path)
0 commit comments