Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Add a warning if the CLI falls behind more than 2 protocol versions #20426

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ impl SuiClientCommands {
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 @@ -981,6 +983,8 @@ impl SuiClientCommands {
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 @@ -2992,3 +2996,27 @@ pub(crate) async fn prerender_clever_errors(
}
}
}

/// Warn the user if the CLI falls behind more than 2 protocol versions.
async fn check_protocol_version_and_warn(client: &SuiClient) -> Result<(), anyhow::Error> {
let protocol_cfg = client.read_api().get_protocol_config(None).await?;
let on_chain_protocol_version = protocol_cfg.protocol_version.as_u64();
let cli_protocol_version = ProtocolVersion::MAX.as_u64();
if (cli_protocol_version + 2) < on_chain_protocol_version {
eprintln!(
"{}",
format!(
"[warning] CLI's protocol version is {cli_protocol_version}, but the active \
network's protocol version is {on_chain_protocol_version}. \
\n Consider installing the latest version of the CLI - \
https://docs.sui.io/guides/developer/getting-started/sui-install \n\n \
If publishing/upgrading returns a dependency verification error, then install the \
latest CLI version."
)
.yellow()
.bold()
);
}

Ok(())
}
Loading