Skip to content

Commit

Permalink
feat(dre,network): add "network --ensure-operator-nodes-unassigned"
Browse files Browse the repository at this point in the history
This should give us a chance to further improve network topology and decentralization.
  • Loading branch information
sasa-tomic committed Nov 13, 2024
1 parent e018947 commit 70fde31
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 158 deletions.
30 changes: 27 additions & 3 deletions rs/cli/src/commands/network.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Args;
use log::info;

use super::{AuthRequirement, ExecutableCommand};

Expand All @@ -15,6 +16,12 @@ pub struct Network {
#[clap(long)]
pub ensure_operator_nodes_assigned: bool,

/// Ensure that at least one node of each node operator is
/// not assigned to any subnet. Node will only be unassigned from a subnet if
/// this does not worsen the decentralization of the target subnet.
#[clap(long)]
pub ensure_operator_nodes_unassigned: bool,

/// Skip provided subnets.
#[clap(long, num_args(1..))]
pub skip_subnets: Vec<String>,
Expand All @@ -31,16 +38,18 @@ impl ExecutableCommand for Network {
let mut errors = vec![];
let network_heal = self.heal || std::env::args().any(|arg| arg == "heal");
if network_heal {
info!("Healing the network by replacing unhealthy nodes and optimizing decentralization in subnets that have unhealthy nodes");
let proposals = runner.network_heal(ctx.forum_post_link(), &self.skip_subnets).await?;
for proposal in proposals {
if let Err(e) = ic_admin.propose_run(proposal.cmd, proposal.opts).await {
errors.push(e);
}
}
} else {
log::info!("No network healing requested: ");
info!("No network healing requested");
}
if self.ensure_operator_nodes_assigned {
info!("Ensuring some operator nodes are assigned, for every node operator");
let proposals = runner
.network_ensure_operator_nodes_assigned(ctx.forum_post_link(), &self.skip_subnets)
.await?;
Expand All @@ -49,6 +58,21 @@ impl ExecutableCommand for Network {
errors.push(e);
}
}
} else {
info!("No network ensure operator nodes assigned requested");
}
if self.ensure_operator_nodes_unassigned {
info!("Ensuring some operator nodes are unassigned, for every node operator");
let proposals = runner
.network_ensure_operator_nodes_unassigned(ctx.forum_post_link(), &self.skip_subnets)
.await?;
for proposal in proposals {
if let Err(e) = ic_admin.propose_run(proposal.cmd, proposal.opts).await {
errors.push(e);
}
}
} else {
info!("No network ensure operator nodes unassigned requested");
}
match errors.is_empty() {
true => Ok(()),
Expand All @@ -59,10 +83,10 @@ impl ExecutableCommand for Network {
fn validate(&self, _args: &crate::commands::Args, cmd: &mut clap::Command) {
// At least one of the two options must be provided
let network_heal = self.heal || std::env::args().any(|arg| arg == "heal");
if !network_heal && !self.ensure_operator_nodes_assigned {
if !network_heal && !self.ensure_operator_nodes_assigned && !self.ensure_operator_nodes_unassigned {
cmd.error(
clap::error::ErrorKind::MissingRequiredArgument,
"At least one of '--heal' or '--ensure-operator-nodes-assigned' must be specified.",
"At least one of '--heal' or '--ensure-operator-nodes-assigned' or '--ensure-operator-nodes-unassigned' must be specified.",
)
.exit()
}
Expand Down
Loading

0 comments on commit 70fde31

Please sign in to comment.