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] Make the number of validators configurable for sui genesis and sui start #20511

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 44 additions & 11 deletions crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ pub enum SuiCommand {
/// Start the network without a fullnode
#[clap(long = "no-full-node")]
no_full_node: bool,
/// Set the number of validators in the network. If a genesis was already generated with a
/// specific number of validators, this will not override it; the user should recreate the
/// genesis with the desired number of validators.
#[clap(long)]
committee_size: Option<usize>,
},
#[clap(name = "network")]
Network {
Expand Down Expand Up @@ -250,6 +255,9 @@ pub enum SuiCommand {
help = "Creates an extra faucet configuration for sui persisted runs."
)]
with_faucet: bool,
/// Set number of validators in the network.
#[clap(long)]
committee_size: Option<usize>,
},
GenesisCeremony(Ceremony),
/// Sui keystore tool.
Expand Down Expand Up @@ -378,6 +386,7 @@ impl SuiCommand {
data_ingestion_dir,
no_full_node,
epoch_duration_ms,
committee_size,
} => {
start(
config_dir.clone(),
Expand All @@ -388,6 +397,7 @@ impl SuiCommand {
fullnode_rpc_port,
data_ingestion_dir,
no_full_node,
committee_size,
)
.await?;

Expand All @@ -401,6 +411,7 @@ impl SuiCommand {
epoch_duration_ms,
benchmark_ips,
with_faucet,
committee_size,
} => {
genesis(
from_config,
Expand All @@ -410,6 +421,7 @@ impl SuiCommand {
epoch_duration_ms,
benchmark_ips,
with_faucet,
committee_size,
)
.await
}
Expand Down Expand Up @@ -612,6 +624,7 @@ async fn start(
fullnode_rpc_port: u16,
mut data_ingestion_dir: Option<PathBuf>,
no_full_node: bool,
committee_size: Option<usize>,
) -> Result<(), anyhow::Error> {
if force_regenesis {
ensure!(
Expand Down Expand Up @@ -656,8 +669,12 @@ async fn start(
// If this is set, then no data will be persisted between runs, and a new genesis will be
// generated each run.
let config_dir = if force_regenesis {
swarm_builder =
swarm_builder.committee_size(NonZeroUsize::new(DEFAULT_NUMBER_OF_AUTHORITIES).unwrap());
let committee_size = match committee_size {
Some(x) => NonZeroUsize::new(x),
None => NonZeroUsize::new(DEFAULT_NUMBER_OF_AUTHORITIES),
}
.ok_or_else(|| anyhow!("Committee size must be at least 1."))?;
swarm_builder = swarm_builder.committee_size(committee_size);
let genesis_config = GenesisConfig::custom_genesis(1, 100);
swarm_builder = swarm_builder.with_genesis_config(genesis_config);
let epoch_duration_ms = epoch_duration_ms.unwrap_or(DEFAULT_EPOCH_DURATION_MS);
Expand All @@ -684,20 +701,29 @@ async fn start(
let network_config = sui_config.join(SUI_NETWORK_CONFIG);

if !network_config.exists() {
genesis(None, None, None, false, epoch_duration_ms, None, false)
.await
.map_err(|_| {
anyhow!(
"Cannot run genesis with non-empty Sui config directory: {}.\n\n\
genesis(
None,
None,
None,
false,
epoch_duration_ms,
None,
false,
committee_size,
)
.await
.map_err(|_| {
anyhow!(
"Cannot run genesis with non-empty Sui config directory: {}.\n\n\
If you are trying to run a local network without persisting the \
data (so a new genesis that is randomly generated and will not be \
saved once the network is shut down), use --force-regenesis flag.\n\
If you are trying to persist the network data and start from a new \
genesis, use sui genesis --help to see how to generate a new \
genesis.",
sui_config.display(),
)
})?;
sui_config.display(),
)
})?;
}

(network_config, sui_config)
Expand Down Expand Up @@ -888,6 +914,7 @@ async fn genesis(
epoch_duration_ms: Option<u64>,
benchmark_ips: Option<Vec<String>>,
with_faucet: bool,
committee_size: Option<usize>,
) -> Result<(), anyhow::Error> {
let sui_config_dir = &match working_dir {
// if a directory is specified, it must exist (it
Expand Down Expand Up @@ -994,14 +1021,20 @@ async fn genesis(
if let Some(epoch_duration_ms) = epoch_duration_ms {
genesis_conf.parameters.epoch_duration_ms = epoch_duration_ms;
}
let committee_size = match committee_size {
Some(x) => NonZeroUsize::new(x),
None => NonZeroUsize::new(DEFAULT_NUMBER_OF_AUTHORITIES),
}
.ok_or_else(|| anyhow!("Committee size must be at least 1."))?;
Comment on lines +1061 to +1065
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let committee_size = match committee_size {
Some(x) => NonZeroUsize::new(x),
None => NonZeroUsize::new(DEFAULT_NUMBER_OF_AUTHORITIES),
}
.ok_or_else(|| anyhow!("Committee size must be at least 1."))?;
let committee_size = match committee_size {
Some(x) => {
if network_config.is_some() { println!("WARNING...") }
NonZeroUsize::new(x),
}
None => NonZeroUsize::new(DEFAULT_NUMBER_OF_AUTHORITIES),
}
.ok_or_else(|| anyhow!("Committee size must be at least 1."))?;

I'm guessing you would see this behavior in the --help given the /// comments? but it also might not hurt to just warn/error. It's debatable though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a good idea to warn, though I think this needs to be done on start command rather than genesis.


let mut network_config = if let Some(validators) = validator_info {
builder
.with_genesis_config(genesis_conf)
.with_validators(validators)
.build()
} else {
builder
.committee_size(NonZeroUsize::new(DEFAULT_NUMBER_OF_AUTHORITIES).unwrap())
.committee_size(committee_size)
.with_genesis_config(genesis_conf)
.build()
};
Expand Down
3 changes: 3 additions & 0 deletions crates/sui/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async fn test_genesis() -> Result<(), anyhow::Error> {
fullnode_rpc_port: 9000,
epoch_duration_ms: None,
no_full_node: false,
committee_size: None,
indexer_feature_args: IndexerArgs::for_testing(),
}
.execute()
Expand All @@ -90,6 +91,7 @@ async fn test_genesis() -> Result<(), anyhow::Error> {
epoch_duration_ms: None,
benchmark_ips: None,
with_faucet: false,
committee_size: None,
}
.execute()
.await?;
Expand Down Expand Up @@ -129,6 +131,7 @@ async fn test_genesis() -> Result<(), anyhow::Error> {
epoch_duration_ms: None,
benchmark_ips: None,
with_faucet: false,
committee_size: None,
}
.execute()
.await;
Expand Down
Loading