From 63cd80f780decfa1e90eccf6bcf64d2b7c5232fe Mon Sep 17 00:00:00 2001 From: stefan-mysten <135084671+stefan-mysten@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:31:35 -0700 Subject: [PATCH] [cherry-pick][cli] Cherry pick cli fix (#18469) (#18476) ## Description Cherry pick #18469 into release branch v1.28 Prior to #18204, `sui start` accepted a network config file when using `--network.config`, and `sui-test-validator` accepted a config directory when using the `--config-dir`, so we need to support both. That PR introduces a bug as in it accepts only directories. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: --- crates/sui/src/sui_commands.rs | 38 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/crates/sui/src/sui_commands.rs b/crates/sui/src/sui_commands.rs index 757d10631fc1b..54ac58f4f4009 100644 --- a/crates/sui/src/sui_commands.rs +++ b/crates/sui/src/sui_commands.rs @@ -601,21 +601,31 @@ async fn start( let epoch_duration_ms = epoch_duration_ms.unwrap_or(DEFAULT_EPOCH_DURATION_MS); swarm_builder = swarm_builder.with_epoch_duration_ms(epoch_duration_ms); } else { - // load from config dir that was passed, or generate a new genesis if there is no config - // dir passed and there is no config_dir in the default location - // and if a dir exists, then use that one - if let Some(config) = config.clone() { - swarm_builder = swarm_builder.dir(config); - } else if config.is_none() && !sui_config_dir()?.join(SUI_NETWORK_CONFIG).exists() { + if config.is_none() && !sui_config_dir()?.join(SUI_NETWORK_CONFIG).exists() { genesis(None, None, None, false, epoch_duration_ms, None, false).await?; - swarm_builder = swarm_builder.dir(sui_config_dir()?); - } else { - swarm_builder = swarm_builder.dir(sui_config_dir()?); } + // Load the config of the Sui authority. - let network_config_path = config - .clone() - .unwrap_or(sui_config_dir()?.join(SUI_NETWORK_CONFIG)); + // To keep compatibility with sui-test-validator where the user can pass a config + // directory, this checks if the config is a file or a directory + let network_config_path = if let Some(ref config) = config { + if config.is_dir() { + config.join(SUI_NETWORK_CONFIG) + } else if config.is_file() + && config + .extension() + .is_some_and(|ext| (ext == "yml" || ext == "yaml")) + { + config.clone() + } else { + config.join(SUI_NETWORK_CONFIG) + } + } else { + config + .clone() + .unwrap_or(sui_config_dir()?) + .join(SUI_NETWORK_CONFIG) + }; let network_config: NetworkConfig = PersistedConfig::read(&network_config_path).map_err(|err| { err.context(format!( @@ -624,7 +634,9 @@ async fn start( )) })?; - swarm_builder = swarm_builder.with_network_config(network_config); + swarm_builder = swarm_builder + .dir(sui_config_dir()?) + .with_network_config(network_config); } #[cfg(feature = "indexer")]