Skip to content

Commit

Permalink
sui: generate a fullnode config when 'sui genesis' is run (MystenLabs…
Browse files Browse the repository at this point in the history
…#2238)

* sui: generate a fullnode config when 'sui genesis' is run

This teaches `sui genesis` to also generate a fullnode.conf file which
can be used to run a fullnode which will connect to a local network
started with `sui start`. E.g.

    $ sui genesis
    $ sui start
    $ sui-node --config-path ~/.sui/sui_config/fullnode.conf
  • Loading branch information
bmwill authored May 25, 2022
1 parent 75ec016 commit a164505
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
24 changes: 24 additions & 0 deletions crates/sui-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,29 @@ impl NetworkConfig {
pub fn generate(config_dir: &Path, quorum_size: usize) -> Self {
Self::generate_with_rng(config_dir, quorum_size, OsRng)
}

/// Generate a fullnode config based on this `NetworkConfig`. This is useful if you want to run
/// a fullnode and have it connect to a network defined by this `NetworkConfig`.
pub fn generate_fullnode_config(&self) -> NodeConfig {
let key_pair = get_key_pair_from_rng(&mut OsRng).1;
let validator_config = &self.validator_configs[0];

let mut db_path = validator_config.db_path.clone();
db_path.pop();

NodeConfig {
key_pair,
db_path: db_path.join("fullnode"),
network_address: new_network_address(),
metrics_address: new_network_address(),
json_rpc_address: validator_config.json_rpc_address,

consensus_config: None,
committee_config: validator_config.committee_config.clone(),

genesis: validator_config.genesis.clone(),
}
}
}

fn new_network_address() -> Multiaddr {
Expand All @@ -226,6 +249,7 @@ fn new_network_address() -> Multiaddr {
const SUI_DIR: &str = ".sui";
const SUI_CONFIG_DIR: &str = "sui_config";
pub const SUI_NETWORK_CONFIG: &str = "network.conf";
pub const SUI_FULLNODE_CONFIG: &str = "fullnode.conf";
pub const SUI_WALLET_CONFIG: &str = "wallet.conf";
pub const SUI_GATEWAY_CONFIG: &str = "gateway.conf";
pub const SUI_DEV_NET_URL: &str = "https://gateway.devnet.sui.io:443";
Expand Down
7 changes: 6 additions & 1 deletion crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use clap::*;
use std::fs;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use sui_config::GenesisConfig;
use sui_config::{builder::ConfigBuilder, NetworkConfig};
use sui_config::{GenesisConfig, SUI_FULLNODE_CONFIG};
use sui_types::base_types::decode_bytes_hex;
use sui_types::base_types::SuiAddress;
use tracing::info;
Expand Down Expand Up @@ -242,6 +242,11 @@ impl SuiCommand {
wallet_config.save()?;
info!("Wallet config file is stored in {:?}.", wallet_path);

let fullnode_config = network_config
.generate_fullnode_config()
.persisted(&sui_config_dir.join(SUI_FULLNODE_CONFIG));
fullnode_config.save()?;

for (i, validator) in network_config
.into_inner()
.into_validator_configs()
Expand Down
5 changes: 3 additions & 2 deletions crates/sui/src/unit_tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use sui::{
sui_commands::SuiCommand,
wallet_commands::{WalletCommandResult, WalletCommands, WalletContext},
};
use sui_config::{AccountConfig, GenesisConfig, NetworkConfig, ObjectConfig};
use sui_config::{AccountConfig, GenesisConfig, NetworkConfig, ObjectConfig, SUI_FULLNODE_CONFIG};
use sui_core::gateway_types::{GetObjectInfoResponse, SuiObject, SuiTransactionEffects};
use sui_json::SuiJsonValue;
use sui_types::{
Expand Down Expand Up @@ -74,10 +74,11 @@ async fn test_genesis() -> Result<(), anyhow::Error> {
.flat_map(|r| r.map(|file| file.file_name().to_str().unwrap().to_owned()))
.collect::<Vec<_>>();

assert_eq!(8, files.len());
assert_eq!(9, 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(&"wallet.key".to_string()));

Expand Down

0 comments on commit a164505

Please sign in to comment.