Skip to content

Commit

Permalink
[cherry-pick][cli] Cherry pick cli fix (#18469) (#18476)
Browse files Browse the repository at this point in the history
## 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:
  • Loading branch information
stefan-mysten authored Jul 1, 2024
1 parent 0c2a734 commit 63cd80f
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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")]
Expand Down

0 comments on commit 63cd80f

Please sign in to comment.