@@ -8,8 +8,9 @@ use beacon_node_health::{
8
8
IsOptimistic , SyncDistanceTier ,
9
9
} ;
10
10
use environment:: RuntimeContext ;
11
- use eth2:: BeaconNodeHttpClient ;
11
+ use eth2:: { BeaconNodeHttpClient , Timeouts } ;
12
12
use futures:: future;
13
+ use sensitive_url:: SensitiveUrl ;
13
14
use serde:: { ser:: SerializeStruct , Deserialize , Serialize , Serializer } ;
14
15
use slog:: { debug, error, warn, Logger } ;
15
16
use slot_clock:: SlotClock ;
@@ -461,6 +462,42 @@ impl<T: SlotClock, E: EthSpec> BeaconNodeFallback<T, E> {
461
462
( candidate_info, num_available, num_synced)
462
463
}
463
464
465
+ /// Update the list of candidates with a new list.
466
+ /// Returns `Ok(new_list)` if the update was successful.
467
+ /// Returns `Err(some_err)` if the list is empty.
468
+ pub async fn replace_candidates (
469
+ & self ,
470
+ new_list : Vec < SensitiveUrl > ,
471
+ use_long_timeouts : bool ,
472
+ ) -> Result < Vec < SensitiveUrl > , String > {
473
+ if new_list. is_empty ( ) {
474
+ return Err ( "Beacon Node list cannot be empty" . to_string ( ) ) ;
475
+ }
476
+
477
+ let timeouts: Timeouts = if new_list. len ( ) == 1 || use_long_timeouts {
478
+ Timeouts :: set_all ( Duration :: from_secs ( self . spec . seconds_per_slot ) )
479
+ } else {
480
+ Timeouts :: use_optimized_timeouts ( Duration :: from_secs ( self . spec . seconds_per_slot ) )
481
+ } ;
482
+
483
+ let new_candidates: Vec < CandidateBeaconNode < E > > = new_list
484
+ . clone ( )
485
+ . into_iter ( )
486
+ . enumerate ( )
487
+ . map ( |( index, url) | {
488
+ CandidateBeaconNode :: < E > :: new (
489
+ BeaconNodeHttpClient :: new ( url, timeouts. clone ( ) ) ,
490
+ index,
491
+ )
492
+ } )
493
+ . collect ( ) ;
494
+
495
+ let mut candidates = self . candidates . write ( ) . await ;
496
+ * candidates = new_candidates;
497
+
498
+ Ok ( new_list)
499
+ }
500
+
464
501
/// Loop through ALL candidates in `self.candidates` and update their sync status.
465
502
///
466
503
/// It is possible for a node to return an unsynced status while continuing to serve
0 commit comments