Skip to content

Commit

Permalink
feat(CLI): Show protocol version mismatch warning (#5042)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* change back to active network

* Update crates/iota/src/client_commands.rs

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
Alex6323 and thibault-martinez authored Feb 3, 2025
1 parent 7e4873c commit 6332a46
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions crates/iota/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -3050,3 +3054,35 @@ fn parse_emit_option(s: &str) -> Result<HashSet<EmitOption>, 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(())
}

0 comments on commit 6332a46

Please sign in to comment.