Skip to content

Commit

Permalink
feat(cli): Added ability to specify --boot-nodes option to the init…
Browse files Browse the repository at this point in the history
… command (#4453)

Tested three scenarios:

1) No boot nodes specified
2) One boot node specified
3) Multiple boot nodes specified.

    With no boot nodes specified:
    ```
    sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearcore (add-boot-nodes)> ./target/debug/neard init --chain-id betanet --download-genesis
    Jun 30 17:06:22.216  INFO neard: Version: 1.2.0, Build: 0d2d66e-modified, Latest Protocol: 45
    Jun 30 17:06:22.219  INFO near: Downloading genesis file from: https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/betanet/genesis.json ...
    Jun 30 17:06:59.992  INFO near: Saved the genesis file to: /home/sandi/.near/genesis.json ...
    Jun 30 17:07:13.464  INFO near: Generated for betanet network node key and genesis file in /home/sandi/.near
    sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearcore (add-boot-nodes)> cat /home/sandi/.near/config.json
            ...
      "network": {
        "addr": "0.0.0.0:24567",
        "external_address": "",
        "boot_nodes": "",
        "max_num_peers": 40,
        "minimum_outbound_peers": 5,
        "ideal_connections_lo": 30,
        "ideal_connections_hi": 35,
        "peer_recent_time_window": {
          "secs": 600,
          "nanos": 0
        },
        "safe_set_size": 20,
        "archival_peer_connections_lower_bound": 10,
        "handshake_timeout": {
          "secs": 20,
          "nanos": 0
        },
        "reconnect_delay": {
          "secs": 60,
          "nanos": 0
        },
        "skip_sync_wait": false,
        "ban_window": {
          "secs": 10800,
          "nanos": 0
        },
        "blacklist": [],
        "ttl_account_id_router": {
          "secs": 3600,
          "nanos": 0
        },
        "peer_stats_period": {
          "secs": 5,
          "nanos": 0
        }
      },
            ...
    ```
    
    With one boot nodes specified:
    ```
    sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearcore (add-boot-nodes) [2]> ./target/debug/neard init --chain-id betanet --download-genesis --boot-nodes ed25519:[email protected]:24567
    Jun 30 17:09:04.550  INFO neard: Version: 1.2.0, Build: 0d2d66e-modified, Latest Protocol: 45
    Jun 30 17:09:04.552  INFO near: Downloading genesis file from: https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/betanet/genesis.json ...
    Jun 30 17:10:18.975  INFO near: Saved the genesis file to: /home/sandi/.near/genesis.json ...
    Jun 30 17:10:31.853  INFO near: Generated for betanet network node key and genesis file in /home/sandi/.near
    sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearcore (add-boot-nodes)> cat /home/sandi/.near/config.json
    {
            ...
      "network": {
        "addr": "0.0.0.0:24567",
        "external_address": "",
        "boot_nodes": "ed25519:[email protected]:24567",
        "max_num_peers": 40,
        "minimum_outbound_peers": 5,
        "ideal_connections_lo": 30,
        "ideal_connections_hi": 35,
        "peer_recent_time_window": {
          "secs": 600,
          "nanos": 0
        },
        "safe_set_size": 20,
        "archival_peer_connections_lower_bound": 10,
        "handshake_timeout": {
          "secs": 20,
          "nanos": 0
        },
        "reconnect_delay": {
          "secs": 60,
          "nanos": 0
        },
        "skip_sync_wait": false,
        "ban_window": {
          "secs": 10800,
          "nanos": 0
        },
        "blacklist": [],
        "ttl_account_id_router": {
          "secs": 3600,
          "nanos": 0
        },
        "peer_stats_period": {
          "secs": 5,
          "nanos": 0
        }
      },
            ...
    ```
    
    With multiple boot nodes specified:
    
    ```
    sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearcore (add-boot-nodes)> rm -rf ~/.near/
    sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearcore (add-boot-nodes)> ./target/debug/neard init --chain-id betanet --download-genesis --boot-nodes ed25519:[email protected]:24567,ed25519:[email protected]:24567,ed25519:[email protected]:24567,ed25519:[email protected]:24567
    Jun 30 17:12:16.514  INFO neard: Version: 1.2.0, Build: 0d2d66e-modified, Latest Protocol: 45
    Jun 30 17:12:16.517  INFO near: Downloading genesis file from: https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/betanet/genesis.json ...
    Jun 30 17:13:46.960  INFO near: Saved the genesis file to: /home/sandi/.near/genesis.json ...
    Jun 30 17:14:01.344  INFO near: Generated for betanet network node key and genesis file in /home/sandi/.near
    sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearcore (add-boot-nodes)> cat /home/sandi/.near/config.json
            ...
      "network": {
        "addr": "0.0.0.0:24567",
        "external_address": "",
        "boot_nodes": "ed25519:[email protected]:24567,ed25519:[email protected]:24567,ed25519:[email protected]:24567,ed25519:[email protected]:24567",
        "max_num_peers": 40,
        "minimum_outbound_peers": 5,
        "ideal_connections_lo": 30,
        "ideal_connections_hi": 35,
        "peer_recent_time_window": {
          "secs": 600,
          "nanos": 0
        },
        "safe_set_size": 20,
        "archival_peer_connections_lower_bound": 10,
        "handshake_timeout": {
          "secs": 20,
          "nanos": 0
        },
        "reconnect_delay": {
          "secs": 60,
          "nanos": 0
        },
        "skip_sync_wait": false,
        "ban_window": {
          "secs": 10800,
          "nanos": 0
        },
        "blacklist": [],
        "ttl_account_id_router": {
          "secs": 3600,
          "nanos": 0
        },
        "peer_stats_period": {
          "secs": 5,
          "nanos": 0
        }
      },
            ...
    ```
  • Loading branch information
chefsale authored Jul 5, 2021
1 parent 168d487 commit 7fe6819
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chain/indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub struct InitConfigArgs {
pub download_config: bool,
/// Specify a custom download URL for the config file.
pub download_config_url: Option<String>,
/// Specify the boot nodes to bootstrap the network
pub boot_nodes: Option<String>,
/// Specify a custom max_gas_burnt_view limit.
pub max_gas_burnt_view: Option<Gas>,
}
Expand Down Expand Up @@ -144,6 +146,7 @@ pub fn indexer_init_configs(dir: &std::path::PathBuf, params: InitConfigArgs) {
params.download_genesis_url.as_deref(),
params.download_config,
params.download_config_url.as_deref(),
params.boot_nodes.as_deref(),
params.max_gas_burnt_view,
)
}
5 changes: 5 additions & 0 deletions nearcore/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ pub fn init_configs(
download_genesis_url: Option<&str>,
should_download_config: bool,
download_config_url: Option<&str>,
boot_nodes: Option<&str>,
max_gas_burnt_view: Option<Gas>,
) {
fs::create_dir_all(dir).expect("Failed to create directory");
Expand All @@ -818,6 +819,10 @@ pub fn init_configs(
config = Config::from_file(&dir.join(CONFIG_FILENAME));
}

if let Some(nodes) = boot_nodes {
config.network.boot_nodes = nodes.to_string();
}

if max_gas_burnt_view.is_some() {
config.max_gas_burnt_view = max_gas_burnt_view;
}
Expand Down
5 changes: 5 additions & 0 deletions neard/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub(super) struct InitCmd {
/// Genesis file to use when initializing testnet (including downloading).
#[clap(long)]
genesis: Option<String>,
/// Initialize boots nodes in <node_key>@<ip_addr> format seperated by commas
/// to bootstrap the network and store them in config.json
#[clap(long)]
boot_nodes: Option<String>,
/// Number of shards to initialize the chain with.
#[clap(long, default_value = "1")]
num_shards: NumShards,
Expand Down Expand Up @@ -157,6 +161,7 @@ impl InitCmd {
self.download_genesis_url.as_deref(),
self.download_config,
self.download_config_url.as_deref(),
self.boot_nodes.as_deref(),
self.max_gas_burnt_view,
);
}
Expand Down
3 changes: 3 additions & 0 deletions tools/indexer/example/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub(crate) struct InitConfigArgs {
/// Specify a custom download URL for the config file.
#[clap(long)]
pub download_config_url: Option<String>,
/// Specify the boot nodes to bootstrap the network
pub boot_nodes: Option<String>,
/// Specify a custom max_gas_burnt_view limit.
#[clap(long)]
pub max_gas_burnt_view: Option<Gas>,
Expand Down Expand Up @@ -84,6 +86,7 @@ impl From<InitConfigArgs> for near_indexer::InitConfigArgs {
download_genesis_url: config_args.download_genesis_url,
download_config: config_args.download_config,
download_config_url: config_args.download_config_url,
boot_nodes: config_args.boot_nodes,
max_gas_burnt_view: config_args.max_gas_burnt_view,
}
}
Expand Down

0 comments on commit 7fe6819

Please sign in to comment.