From ec22c7ca6d04f8480721b2a1e71466d088ab902f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Tomi=C4=87?= Date: Fri, 16 Aug 2024 11:36:19 +0200 Subject: [PATCH] fix(dre): [DRE-241] Prefer existing nodes in subnet when selecting best results (#734) Co-authored-by: sa-github-api <138766536+sa-github-api@users.noreply.github.com> --- rs/decentralization/src/network.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rs/decentralization/src/network.rs b/rs/decentralization/src/network.rs index b3ec8c2f2..3ef06feab 100644 --- a/rs/decentralization/src/network.rs +++ b/rs/decentralization/src/network.rs @@ -3,6 +3,7 @@ use crate::subnets::unhealthy_with_nodes; use crate::SubnetChangeResponse; use actix_web::http::StatusCode; use actix_web::{HttpResponse, ResponseError}; +use ahash::AHashSet; use anyhow::anyhow; use ic_base_types::PrincipalId; use ic_management_types::{MinNakamotoCoefficients, NetworkError, NodeFeature, Status}; @@ -403,6 +404,16 @@ impl DecentralizedSubnet { if best_results.is_empty() { None } else { + // If any of the best_results nodes are already in the subnet, + // we should prefer them. This is because we want to keep the + // same nodes in the subnet if they are already there. + let current_nodes_set: AHashSet<_> = current_nodes.iter().collect(); + for result in best_results { + if current_nodes_set.contains(&result.node) { + return Some(result.clone()); + } + } + // We sort the current nodes by alphabetical order on their // PrincipalIDs to ensure consistency of the seed with the // same machines in the subnet