diff --git a/crates/sui/src/client_commands.rs b/crates/sui/src/client_commands.rs index 87c21a8125d99..5aaee93d5b920 100644 --- a/crates/sui/src/client_commands.rs +++ b/crates/sui/src/client_commands.rs @@ -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() @@ -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() @@ -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(()) +}