Skip to content

Commit

Permalink
Merge branch 'main' into release-2024-06-05_23-01
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-tomic authored Jun 6, 2024
2 parents da1341c + 79be1d9 commit 5640efc
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 4 deletions.
56 changes: 55 additions & 1 deletion rs/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ pub enum Commands {
/// Manage nodes
Nodes(nodes::Cmd),

/// Manage API boundary nodes
ApiBoundaryNodes(api_boundary_nodes::Cmd),

/// Vote on our proposals
Vote {
/// Override default accepted proposers
Expand Down Expand Up @@ -245,7 +248,7 @@ pub mod subnet {
#[clap(long, num_args(1..))]
include: Vec<PrincipalId>,

/// Motivation for resing the subnet
/// Motivation for resizing the subnet
#[clap(short, long, aliases = ["summary"])]
motivation: Option<String>,
},
Expand Down Expand Up @@ -455,6 +458,57 @@ pub mod nodes {
}
}

pub mod api_boundary_nodes {
use super::*;

#[derive(Parser, Clone)]
pub struct Cmd {
#[clap(subcommand)]
pub subcommand: Commands,
}

#[derive(Subcommand, Clone)]
pub enum Commands {
/// Update specified set of nodes to the provided version.
/// The provided "version" must be already elected.
/// The "nodes" list must contain the node IDs where the version should be rolled out.
Update {
/// Node IDs where to rollout the version
#[clap(long, num_args(1..), required = true)]
nodes: Vec<PrincipalId>,

#[clap(long, required = true)]
version: String,

/// Motivation for creating the subnet
#[clap(short, long, aliases = ["summary"], required = true)]
motivation: Option<String>,
},

/// Turn a set of unassigned nodes into API BNs
Add {
/// Node IDs to turn into API BNs
#[clap(long, num_args(1..), required = true)]
nodes: Vec<PrincipalId>,

/// guestOS version
#[clap(long, required = true)]
version: String,

/// Motivation for creating the subnet
#[clap(short, long, aliases = ["summary"], required = true)]
motivation: Option<String>,
},

/// Decommission a set of API BNs and turn them again in unassigned nodes
Remove {
/// Node IDs to turn into API BNs
#[clap(long, num_args(1..), required = true)]
nodes: Vec<PrincipalId>,
},
}
}

pub mod proposals {
use clap::ValueEnum;
use ic_nns_governance::pb::v1::{ProposalStatus as ProposalStatusUpstream, Topic as TopicUpstream};
Expand Down
30 changes: 27 additions & 3 deletions rs/cli/src/ic_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ must be identical, and must match the SHA256 from the payload of the NNS proposa
}
}

pub async fn update_unassigned_nodes(&self, nns_subned_id: &String, network: &Network, simulate: bool) -> Result<(), Error> {
pub async fn update_unassigned_nodes(&self, nns_subnet_id: &String, network: &Network, simulate: bool) -> Result<(), Error> {
let local_registry_path = local_registry_path(network);
let local_registry = LocalRegistry::new(local_registry_path, Duration::from_secs(10))
.map_err(|e| anyhow::anyhow!("Error in creating local registry instance: {:?}", e))?;
Expand All @@ -638,9 +638,9 @@ must be identical, and must match the SHA256 from the payload of the NNS proposa

let subnets = local_registry.get_family_entries::<SubnetRecord>()?;

let nns = match subnets.get_key_value(nns_subned_id) {
let nns = match subnets.get_key_value(nns_subnet_id) {
Some((_, value)) => value,
None => return Err(anyhow::anyhow!("Couldn't find nns subnet with id '{}'", nns_subned_id)),
None => return Err(anyhow::anyhow!("Couldn't find nns subnet with id '{}'", nns_subnet_id)),
};

let registry_state = RegistryState::new(network, true).await;
Expand Down Expand Up @@ -877,6 +877,17 @@ pub enum ProposeCommand {
node_ids: Vec<PrincipalId>,
replica_version: String,
},
AddApiBoundaryNodes {
nodes: Vec<PrincipalId>,
version: String,
},
RemoveApiBoundaryNodes {
nodes: Vec<PrincipalId>,
},
DeployGuestosToSomeApiBoundaryNodes {
nodes: Vec<PrincipalId>,
version: String,
},
}

impl ProposeCommand {
Expand Down Expand Up @@ -948,6 +959,19 @@ impl ProposeCommand {
Self::DeployGuestosToAllUnassignedNodes { replica_version } => {
vec!["--replica-version-id".to_string(), replica_version.clone()]
}
Self::AddApiBoundaryNodes { nodes, version } => [
vec!["--nodes".to_string()],
nodes.iter().map(|n| n.to_string()).collect::<Vec<_>>(),
vec!["--version".to_string(), version.to_string()],
]
.concat(),
Self::RemoveApiBoundaryNodes { nodes } => [vec!["--nodes".to_string()], nodes.iter().map(|n| n.to_string()).collect::<Vec<_>>()].concat(),
Self::DeployGuestosToSomeApiBoundaryNodes { nodes, version } => [
vec!["--nodes".to_string()],
nodes.iter().map(|n| n.to_string()).collect::<Vec<_>>(),
vec!["--version".to_string(), version.to_string()],
]
.concat(),
}
}
}
Expand Down
55 changes: 55 additions & 0 deletions rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ async fn async_main() -> Result<(), anyhow::Error> {
}
}
}

cli::Commands::Nodes(nodes) => match &nodes.subcommand {
cli::nodes::Commands::Remove {
extra_nodes_filter,
Expand Down Expand Up @@ -354,6 +355,60 @@ async fn async_main() -> Result<(), anyhow::Error> {
}
},

cli::Commands::ApiBoundaryNodes(api_boundary_nodes) => match &api_boundary_nodes.subcommand {
cli::api_boundary_nodes::Commands::Update { nodes, version, motivation } => {
runner_instance
.ic_admin
.propose_run(
ic_admin::ProposeCommand::DeployGuestosToSomeApiBoundaryNodes {
nodes: nodes.to_vec(),
version: version.to_string(),
},
ic_admin::ProposeOptions {
title: Some(format!("Update {} API boundary node(s) to {version}", nodes.clone().len())),
summary: Some(format!("Update {} API boundary node(s) to {version}", nodes.clone().len())),
motivation: motivation.clone(),
},
simulate,
)
.await?;
Ok(())
}
cli::api_boundary_nodes::Commands::Add { nodes, version, motivation } => {
runner_instance
.ic_admin
.propose_run(
ic_admin::ProposeCommand::AddApiBoundaryNodes {
nodes: nodes.to_vec(),
version: version.to_string(),
},
ic_admin::ProposeOptions {
title: Some(format!("Add {} API boundary node(s)", nodes.clone().len())),
summary: Some(format!("Add {} API boundary node(s)", nodes.clone().len())),
motivation: motivation.clone(),
},
simulate,
)
.await?;
Ok(())
}
cli::api_boundary_nodes::Commands::Remove { nodes } => {
runner_instance
.ic_admin
.propose_run(
ic_admin::ProposeCommand::RemoveApiBoundaryNodes { nodes: nodes.to_vec() },
ic_admin::ProposeOptions {
title: Some(format!("Remove {} API boundary node(s)", nodes.clone().len())),
summary: Some(format!("Remove {} API boundary node(s)", nodes.clone().len())),
motivation: None,
},
simulate,
)
.await?;
Ok(())
}
},

cli::Commands::Vote {
accepted_neurons,
accepted_topics,
Expand Down

0 comments on commit 5640efc

Please sign in to comment.