Use the more descriptive user_index instead of id

This commit is contained in:
Mac L
2024-02-05 16:32:30 +11:00
parent a5e934883a
commit e368397bf5
5 changed files with 57 additions and 39 deletions

View File

@@ -147,7 +147,7 @@ pub enum CandidateError {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct CandidateInfo { pub struct CandidateInfo {
pub id: usize, pub index: usize,
pub node: String, pub node: String,
pub health: Option<BeaconNodeHealth>, pub health: Option<BeaconNodeHealth>,
} }
@@ -156,7 +156,7 @@ pub struct CandidateInfo {
/// for a query. /// for a query.
#[derive(Debug)] #[derive(Debug)]
pub struct CandidateBeaconNode<E> { pub struct CandidateBeaconNode<E> {
pub id: usize, pub index: usize,
pub beacon_node: BeaconNodeHttpClient, pub beacon_node: BeaconNodeHttpClient,
pub health: PLRwLock<Result<BeaconNodeHealth, CandidateError>>, pub health: PLRwLock<Result<BeaconNodeHealth, CandidateError>>,
_phantom: PhantomData<E>, _phantom: PhantomData<E>,
@@ -164,7 +164,7 @@ pub struct CandidateBeaconNode<E> {
impl<E: EthSpec> PartialEq for CandidateBeaconNode<E> { impl<E: EthSpec> PartialEq for CandidateBeaconNode<E> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.id == other.id && self.beacon_node == other.beacon_node self.index == other.index && self.beacon_node == other.beacon_node
} }
} }
@@ -189,9 +189,9 @@ impl<E: EthSpec> PartialOrd for CandidateBeaconNode<E> {
impl<E: EthSpec> CandidateBeaconNode<E> { impl<E: EthSpec> CandidateBeaconNode<E> {
/// Instantiate a new node. /// Instantiate a new node.
pub fn new(beacon_node: BeaconNodeHttpClient, id: usize) -> Self { pub fn new(beacon_node: BeaconNodeHttpClient, index: usize) -> Self {
Self { Self {
id, index,
beacon_node, beacon_node,
health: PLRwLock::new(Err(CandidateError::Uninitialized)), health: PLRwLock::new(Err(CandidateError::Uninitialized)),
_phantom: PhantomData, _phantom: PhantomData,
@@ -239,7 +239,7 @@ impl<E: EthSpec> CandidateBeaconNode<E> {
}; };
let new_health = BeaconNodeHealth::from_status( let new_health = BeaconNodeHealth::from_status(
self.id, self.index,
sync_distance, sync_distance,
head, head,
optimistic_status, optimistic_status,
@@ -408,7 +408,11 @@ impl<T: SlotClock, E: EthSpec> BeaconNodeFallback<T, E> {
match candidate.health() { match candidate.health() {
Ok(health) => { Ok(health) => {
if self.distance_tiers.compute_distance_tier(health.health_tier.sync_distance) == SyncDistanceTier::Synced { if self
.distance_tiers
.compute_distance_tier(health.health_tier.sync_distance)
== SyncDistanceTier::Synced
{
num_synced += 1; num_synced += 1;
} }
num_available += 1; num_available += 1;
@@ -417,7 +421,11 @@ impl<T: SlotClock, E: EthSpec> BeaconNodeFallback<T, E> {
Err(_) => continue, Err(_) => continue,
} }
candidate_info.push(CandidateInfo { id: candidate.id, node: candidate.beacon_node.to_string(), health: health.ok() }); candidate_info.push(CandidateInfo {
index: candidate.index,
node: candidate.beacon_node.to_string(),
health: health.ok(),
});
} }
(candidate_info, num_available, num_synced) (candidate_info, num_available, num_synced)
@@ -680,12 +688,12 @@ mod tests {
let optimistic_status = IsOptimistic::No; let optimistic_status = IsOptimistic::No;
let execution_status = ExecutionEngineHealth::Healthy; let execution_status = ExecutionEngineHealth::Healthy;
fn new_candidate(id: usize) -> CandidateBeaconNode<E> { fn new_candidate(index: usize) -> CandidateBeaconNode<E> {
let beacon_node = BeaconNodeHttpClient::new( let beacon_node = BeaconNodeHttpClient::new(
SensitiveUrl::parse(&format!("http://example_{id}.com")).unwrap(), SensitiveUrl::parse(&format!("http://example_{index}.com")).unwrap(),
Timeouts::set_all(Duration::from_secs(id as u64)), Timeouts::set_all(Duration::from_secs(index as u64)),
); );
CandidateBeaconNode::new(beacon_node, id) CandidateBeaconNode::new(beacon_node, index)
} }
let candidate_1 = new_candidate(1); let candidate_1 = new_candidate(1);
@@ -705,16 +713,16 @@ mod tests {
let small = SyncDistanceTier::Small; let small = SyncDistanceTier::Small;
// Despite `health_1` having a larger sync distance, it is inside the `synced` range which // Despite `health_1` having a larger sync distance, it is inside the `synced` range which
// does not tie-break on sync distance and so will tie-break on `id` instead. // does not tie-break on sync distance and so will tie-break on `user_index` instead.
let health_1 = BeaconNodeHealth { let health_1 = BeaconNodeHealth {
id: 1, user_index: 1,
head, head,
optimistic_status, optimistic_status,
execution_status, execution_status,
health_tier: BeaconNodeHealthTier::new(1, Slot::new(2), synced), health_tier: BeaconNodeHealthTier::new(1, Slot::new(2), synced),
}; };
let health_2 = BeaconNodeHealth { let health_2 = BeaconNodeHealth {
id: 2, user_index: 2,
head, head,
optimistic_status, optimistic_status,
execution_status, execution_status,
@@ -722,16 +730,16 @@ mod tests {
}; };
// `health_3` and `health_4` have the same health tier and sync distance so should // `health_3` and `health_4` have the same health tier and sync distance so should
// tie-break on `id`. // tie-break on `user_index`.
let health_3 = BeaconNodeHealth { let health_3 = BeaconNodeHealth {
id: 3, user_index: 3,
head, head,
optimistic_status, optimistic_status,
execution_status, execution_status,
health_tier: BeaconNodeHealthTier::new(3, Slot::new(9), small), health_tier: BeaconNodeHealthTier::new(3, Slot::new(9), small),
}; };
let health_4 = BeaconNodeHealth { let health_4 = BeaconNodeHealth {
id: 4, user_index: 4,
head, head,
optimistic_status, optimistic_status,
execution_status, execution_status,
@@ -739,16 +747,16 @@ mod tests {
}; };
// `health_5` has a smaller sync distance and is outside the `synced` range so should be // `health_5` has a smaller sync distance and is outside the `synced` range so should be
// sorted first. Note the values of `id`. // sorted first. Note the values of `user_index`.
let health_5 = BeaconNodeHealth { let health_5 = BeaconNodeHealth {
id: 6, user_index: 6,
head, head,
optimistic_status, optimistic_status,
execution_status, execution_status,
health_tier: BeaconNodeHealthTier::new(4, Slot::new(9), small), health_tier: BeaconNodeHealthTier::new(4, Slot::new(9), small),
}; };
let health_6 = BeaconNodeHealth { let health_6 = BeaconNodeHealth {
id: 5, user_index: 5,
head, head,
optimistic_status, optimistic_status,
execution_status, execution_status,

View File

@@ -154,10 +154,10 @@ impl BeaconNodeHealthTier {
/// Beacon Node Health metrics. /// Beacon Node Health metrics.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct BeaconNodeHealth { pub struct BeaconNodeHealth {
// The ID of the Beacon Node. This should correspond with its position in the `--beacon-nodes` // The index of the Beacon Node. This should correspond with its position in the
// list. Note that the ID field is used to tie-break nodes with the same health so that nodes // `--beacon-nodes` list. Note that the `user_index` field is used to tie-break nodes with the
// with a lower ID are preferred. // same health so that nodes with a lower index are preferred.
pub id: usize, pub user_index: usize,
// The slot number of the head. // The slot number of the head.
pub head: Slot, pub head: Slot,
// Whether the node is optimistically synced. // Whether the node is optimistically synced.
@@ -173,8 +173,8 @@ impl Ord for BeaconNodeHealth {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
let ordering = self.health_tier.cmp(&other.health_tier); let ordering = self.health_tier.cmp(&other.health_tier);
if ordering == Ordering::Equal { if ordering == Ordering::Equal {
// Tie-break node health by ID. // Tie-break node health by `user_index`.
self.id.cmp(&other.id) self.user_index.cmp(&other.user_index)
} else { } else {
ordering ordering
} }
@@ -189,7 +189,7 @@ impl PartialOrd for BeaconNodeHealth {
impl BeaconNodeHealth { impl BeaconNodeHealth {
pub fn from_status( pub fn from_status(
id: usize, user_index: usize,
sync_distance: Slot, sync_distance: Slot,
head: Slot, head: Slot,
optimistic_status: IsOptimistic, optimistic_status: IsOptimistic,
@@ -204,7 +204,7 @@ impl BeaconNodeHealth {
); );
Self { Self {
id, user_index,
head, head,
optimistic_status, optimistic_status,
execution_status, execution_status,
@@ -212,8 +212,8 @@ impl BeaconNodeHealth {
} }
} }
pub fn get_id(&self) -> usize { pub fn get_index(&self) -> usize {
self.id self.user_index
} }
pub fn get_health_tier(&self) -> BeaconNodeHealthTier { pub fn get_health_tier(&self) -> BeaconNodeHealthTier {

View File

@@ -441,11 +441,17 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
let mut result: HashMap<(usize, String), Result<BeaconNodeHealth, CandidateError>> = let mut result: HashMap<(usize, String), Result<BeaconNodeHealth, CandidateError>> =
HashMap::new(); HashMap::new();
for node in &*block_filter.beacon_nodes.candidates.read().await { for node in &*block_filter.beacon_nodes.candidates.read().await {
result.insert((node.id, node.beacon_node.to_string()), *node.health.read()); result.insert(
(node.index, node.beacon_node.to_string()),
*node.health.read(),
);
} }
if let Some(proposer_nodes) = &block_filter.proposer_nodes { if let Some(proposer_nodes) = &block_filter.proposer_nodes {
for node in &*proposer_nodes.candidates.read().await { for node in &*proposer_nodes.candidates.read().await {
result.insert((node.id, node.beacon_node.to_string()), *node.health.read()); result.insert(
(node.index, node.beacon_node.to_string()),
*node.health.read(),
);
} }
} }

View File

@@ -339,18 +339,21 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
.collect::<Result<Vec<BeaconNodeHttpClient>, String>>()?; .collect::<Result<Vec<BeaconNodeHttpClient>, String>>()?;
let num_nodes = beacon_nodes.len(); let num_nodes = beacon_nodes.len();
// User order of `beacon_nodes` is preserved, so `index` corresponds to the position of
// the node in `--beacon_nodes`.
let candidates = beacon_nodes let candidates = beacon_nodes
.into_iter() .into_iter()
.enumerate() .enumerate()
.map(|(id, node)| CandidateBeaconNode::new(node, id)) .map(|(index, node)| CandidateBeaconNode::new(node, index))
.collect(); .collect();
let proposer_nodes_num = proposer_nodes.len(); let proposer_nodes_num = proposer_nodes.len();
// User order of `proposer_nodes` is preserved, so `index` corresponds to the position of
// the node in `--proposer_nodes`.
let proposer_candidates = proposer_nodes let proposer_candidates = proposer_nodes
.into_iter() .into_iter()
.enumerate() .enumerate()
.map(|(id, node)| CandidateBeaconNode::new(node, id)) .map(|(index, node)| CandidateBeaconNode::new(node, index))
.collect(); .collect();
// Set the count for beacon node fallbacks excluding the primary beacon node. // Set the count for beacon node fallbacks excluding the primary beacon node.

View File

@@ -39,7 +39,8 @@ async fn notify<T: SlotClock + 'static, E: EthSpec>(
duties_service: &DutiesService<T, E>, duties_service: &DutiesService<T, E>,
log: &Logger, log: &Logger,
) { ) {
let (candidate_info, num_available, num_synced) = duties_service.beacon_nodes.get_notifier_info().await; let (candidate_info, num_available, num_synced) =
duties_service.beacon_nodes.get_notifier_info().await;
let num_total = candidate_info.len(); let num_total = candidate_info.len();
let num_synced_fallback = num_synced.saturating_sub(1); let num_synced_fallback = num_synced.saturating_sub(1);
@@ -89,7 +90,7 @@ async fn notify<T: SlotClock + 'static, E: EthSpec>(
log, log,
"Beacon node info"; "Beacon node info";
"status" => "Connected", "status" => "Connected",
"id" => info.id, "index" => info.index,
"endpoint" => info.node, "endpoint" => info.node,
"head_slot" => %health.head, "head_slot" => %health.head,
"is_optimistic" => ?health.optimistic_status, "is_optimistic" => ?health.optimistic_status,
@@ -101,7 +102,7 @@ async fn notify<T: SlotClock + 'static, E: EthSpec>(
log, log,
"Beacon node info"; "Beacon node info";
"status" => "Disconnected", "status" => "Disconnected",
"id" => info.id, "index" => info.index,
"endpoint" => info.node, "endpoint" => info.node,
); );
} }