mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Allow the --beacon-nodes list to be updated at runtime (#6551)
Adds a new `/lighthouse` API call to the VC which allows the list of beacon nodes to be updated dynamically at runtime. An entirely new beacon node list is provided to the VC so it effectively adds, removes or reorders nodes to match the new list. This can then be used in Siren, which will enable a "drag to reorder" system along with adding and removing beacon nodes while the VC is on. This will make it unnecessary to reboot the VC when users want to simply add or remove a BN from the list.
This commit is contained in:
@@ -13,6 +13,7 @@ clap = { workspace = true }
|
||||
eth2 = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
sensitive_url = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
slot_clock = { workspace = true }
|
||||
strum = { workspace = true }
|
||||
|
||||
@@ -8,8 +8,9 @@ use beacon_node_health::{
|
||||
IsOptimistic, SyncDistanceTier,
|
||||
};
|
||||
use clap::ValueEnum;
|
||||
use eth2::BeaconNodeHttpClient;
|
||||
use eth2::{BeaconNodeHttpClient, Timeouts};
|
||||
use futures::future;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use slot_clock::SlotClock;
|
||||
use std::cmp::Ordering;
|
||||
@@ -455,6 +456,39 @@ impl<T: SlotClock> BeaconNodeFallback<T> {
|
||||
(candidate_info, num_available, num_synced)
|
||||
}
|
||||
|
||||
/// Update the list of candidates with a new list.
|
||||
/// Returns `Ok(new_list)` if the update was successful.
|
||||
/// Returns `Err(some_err)` if the list is empty.
|
||||
pub async fn update_candidates_list(
|
||||
&self,
|
||||
new_list: Vec<SensitiveUrl>,
|
||||
use_long_timeouts: bool,
|
||||
) -> Result<Vec<SensitiveUrl>, String> {
|
||||
if new_list.is_empty() {
|
||||
return Err("list cannot be empty".to_string());
|
||||
}
|
||||
|
||||
let timeouts: Timeouts = if new_list.len() == 1 || use_long_timeouts {
|
||||
Timeouts::set_all(Duration::from_secs(self.spec.seconds_per_slot))
|
||||
} else {
|
||||
Timeouts::use_optimized_timeouts(Duration::from_secs(self.spec.seconds_per_slot))
|
||||
};
|
||||
|
||||
let new_candidates: Vec<CandidateBeaconNode> = new_list
|
||||
.clone()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, url)| {
|
||||
CandidateBeaconNode::new(BeaconNodeHttpClient::new(url, timeouts.clone()), index)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut candidates = self.candidates.write().await;
|
||||
*candidates = new_candidates;
|
||||
|
||||
Ok(new_list)
|
||||
}
|
||||
|
||||
/// Loop through ALL candidates in `self.candidates` and update their sync status.
|
||||
///
|
||||
/// It is possible for a node to return an unsynced status while continuing to serve
|
||||
|
||||
Reference in New Issue
Block a user