From 6332a4625fce702039598da997d8671a377761c6 Mon Sep 17 00:00:00 2001 From: /alex/ Date: Mon, 3 Feb 2025 21:55:31 +0100 Subject: [PATCH] feat(CLI): Show protocol version mismatch warning (#5042) * add CLI out-of-date warning * warn immediatedly if CLI is out-of-sync * rename * distinguish version mismatch * improve message * fix * Apply suggestions Co-authored-by: Thibault Martinez * change back to active network * Update crates/iota/src/client_commands.rs --------- Co-authored-by: Thibault Martinez --- crates/iota/src/client_commands.rs | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/iota/src/client_commands.rs b/crates/iota/src/client_commands.rs index b1054466a60..5c1a73c56d6 100644 --- a/crates/iota/src/client_commands.rs +++ b/crates/iota/src/client_commands.rs @@ -893,6 +893,8 @@ impl IotaClientCommands { let client = context.get_client().await?; let chain_id = client.read_api().get_chain_identifier().await.ok(); + check_protocol_version_and_warn(&client).await?; + let package_path = package_path .canonicalize() @@ -1001,6 +1003,8 @@ impl IotaClientCommands { let client = context.get_client().await?; let chain_id = client.read_api().get_chain_identifier().await.ok(); + check_protocol_version_and_warn(&client).await?; + let package_path = package_path .canonicalize() @@ -3050,3 +3054,35 @@ fn parse_emit_option(s: &str) -> Result, String> { Ok(options) } + +/// Warn the user if the CLI does not match the version of current on-chain +/// protocol. +async fn check_protocol_version_and_warn(client: &IotaClient) -> Result<(), anyhow::Error> { + let on_chain_protocol_version = client + .read_api() + .get_protocol_config(None) + .await? + .protocol_version + .as_u64(); + let cli_protocol_version = ProtocolVersion::MAX.as_u64(); + + if cli_protocol_version != on_chain_protocol_version { + let warning_msg = format!( + "[warning] The CLI's protocol version is {cli_protocol_version}, but the active \ + network's protocol version is {on_chain_protocol_version}." + ); + let help_msg = if cli_protocol_version < on_chain_protocol_version { + "Consider installing the latest version of the CLI - \ + https://docs.iota.org/references/cli \n\n \ + If publishing/upgrading returns a dependency verification error, then install the \ + latest CLI version." + } else { + "Consider waiting for the network to have upgraded to the same version, \ + or using a previous version of the CLI for this operation." + }; + + eprintln!("{}", format!("{warning_msg}\n{help_msg}").yellow().bold()) + } + + Ok(()) +}