diff --git a/crates/sui-config/src/lib.rs b/crates/sui-config/src/lib.rs index db86df8b39c56..d1e507fba873b 100644 --- a/crates/sui-config/src/lib.rs +++ b/crates/sui-config/src/lib.rs @@ -25,6 +25,7 @@ pub const SUI_NETWORK_CONFIG: &str = "network.yaml"; pub const SUI_FULLNODE_CONFIG: &str = "fullnode.yaml"; pub const SUI_WALLET_CONFIG: &str = "wallet.yaml"; pub const SUI_GATEWAY_CONFIG: &str = "gateway.yaml"; +pub const SUI_GENESIS_FILENAME: &str = "genesis.blob"; pub const SUI_DEV_NET_URL: &str = "https://gateway.devnet.sui.io:443"; pub const AUTHORITIES_DB_NAME: &str = "authorities_db"; diff --git a/crates/sui-config/src/node.rs b/crates/sui-config/src/node.rs index e7a36688e2d52..d9aaceeeec048 100644 --- a/crates/sui-config/src/node.rs +++ b/crates/sui-config/src/node.rs @@ -18,6 +18,7 @@ use sui_types::crypto::{KeyPair, PublicKeyBytes}; #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] pub struct NodeConfig { + #[serde(default = "default_key_pair")] pub key_pair: KeyPair, pub db_path: PathBuf, #[serde(default = "default_grpc_address")] @@ -33,6 +34,10 @@ pub struct NodeConfig { pub genesis: Genesis, } +fn default_key_pair() -> KeyPair { + sui_types::crypto::get_key_pair().1 +} + fn default_grpc_address() -> Multiaddr { use multiaddr::multiaddr; multiaddr!(Ip4([0, 0, 0, 0]), Tcp(8080u16)) diff --git a/crates/sui/src/sui_commands.rs b/crates/sui/src/sui_commands.rs index 2754e371b5c57..ac62530aec2d7 100644 --- a/crates/sui/src/sui_commands.rs +++ b/crates/sui/src/sui_commands.rs @@ -10,8 +10,8 @@ use clap::*; use std::fs; use std::num::NonZeroUsize; use std::path::PathBuf; -use sui_config::genesis_config::GenesisConfig; use sui_config::{builder::ConfigBuilder, NetworkConfig}; +use sui_config::{genesis_config::GenesisConfig, SUI_GENESIS_FILENAME}; use sui_config::{ sui_config_dir, Config, PersistedConfig, SUI_FULLNODE_CONFIG, SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG, @@ -162,6 +162,7 @@ impl SuiCommand { } let network_path = sui_config_dir.join(SUI_NETWORK_CONFIG); + let genesis_path = sui_config_dir.join(SUI_GENESIS_FILENAME); let wallet_path = sui_config_dir.join(SUI_WALLET_CONFIG); let gateway_path = sui_config_dir.join(SUI_GATEWAY_CONFIG); let keystore_path = sui_config_dir.join("wallet.key"); @@ -180,7 +181,7 @@ impl SuiCommand { } let validator_info = genesis_conf.validator_genesis_info.take(); - let network_config = if let Some(validators) = validator_info { + let mut network_config = if let Some(validators) = validator_info { ConfigBuilder::new(sui_config_dir) .initial_accounts_config(genesis_conf) .build_with_validators(validators) @@ -200,9 +201,13 @@ impl SuiCommand { keystore.add_key(address, key.copy())?; } + network_config.genesis.save(&genesis_path)?; + for validator in &mut network_config.validator_configs { + validator.genesis = sui_config::node::Genesis::new_from_file(&genesis_path); + } + info!("Network genesis completed."); - let network_config = network_config.persisted(&network_path); - network_config.save()?; + network_config.save(&network_path)?; info!("Network config file is stored in {:?}.", network_path); keystore.set_path(&keystore_path); @@ -212,17 +217,14 @@ impl SuiCommand { // Use the first address if any let active_address = accounts.get(0).copied(); - let validator_set = network_config.validator_configs()[0] - .committee_config() - .validator_set(); + let validator_set = network_config.validator_set(); GatewayConfig { db_folder_path: gateway_db_folder_path, validator_set: validator_set.to_owned(), ..Default::default() } - .persisted(&gateway_path) - .save()?; + .save(&gateway_path)?; info!("Gateway config file is stored in {:?}.", gateway_path); let wallet_gateway_config = GatewayConfig { @@ -238,8 +240,7 @@ impl SuiCommand { active_address, }; - let wallet_config = wallet_config.persisted(&wallet_path); - wallet_config.save()?; + wallet_config.save(&wallet_path)?; info!("Wallet config file is stored in {:?}.", wallet_path); let fullnode_config = network_config @@ -248,14 +249,12 @@ impl SuiCommand { fullnode_config.save()?; for (i, validator) in network_config - .into_inner() .into_validator_configs() .into_iter() .enumerate() { - let validator_config = validator - .persisted(&sui_config_dir.join(format!("validator-config-{}.yaml", i))); - validator_config.save()?; + let path = sui_config_dir.join(format!("validator-config-{}.yaml", i)); + validator.save(path)?; } Ok(()) diff --git a/crates/sui/src/unit_tests/cli_tests.rs b/crates/sui/src/unit_tests/cli_tests.rs index 2d6bbe9fa0ae4..3470030440b65 100644 --- a/crates/sui/src/unit_tests/cli_tests.rs +++ b/crates/sui/src/unit_tests/cli_tests.rs @@ -17,7 +17,7 @@ use sui::{ use sui_config::genesis_config::{AccountConfig, GenesisConfig, ObjectConfig}; use sui_config::{ Config, NetworkConfig, PersistedConfig, SUI_FULLNODE_CONFIG, SUI_GATEWAY_CONFIG, - SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG, + SUI_GENESIS_FILENAME, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG, }; use sui_core::gateway_types::{GetObjectDataResponse, SuiObject, SuiTransactionEffects}; use sui_json::SuiJsonValue; @@ -75,11 +75,12 @@ async fn test_genesis() -> Result<(), anyhow::Error> { .flat_map(|r| r.map(|file| file.file_name().to_str().unwrap().to_owned())) .collect::>(); - assert_eq!(9, files.len()); + assert_eq!(10, files.len()); assert!(files.contains(&SUI_WALLET_CONFIG.to_string())); assert!(files.contains(&SUI_GATEWAY_CONFIG.to_string())); assert!(files.contains(&SUI_NETWORK_CONFIG.to_string())); assert!(files.contains(&SUI_FULLNODE_CONFIG.to_string())); + assert!(files.contains(&SUI_GENESIS_FILENAME.to_string())); assert!(files.contains(&"wallet.key".to_string()));