Skip to content

Commit

Permalink
[tools] VFN config builder (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com>
  • Loading branch information
2 people authored and hemulin committed Nov 14, 2023
1 parent f1c6043 commit b7ddfe3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 22 deletions.
21 changes: 16 additions & 5 deletions tools/config/src/config_cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::fullnode_config::{download_genesis, init_fullnode_yaml};
use crate::host::initialize_validator_configs;
use crate::make_yaml_public_fullnode::{download_genesis, init_fullnode_yaml};
use crate::validator_config::initialize_validator_configs;
use crate::{legacy_config, make_profile};
use anyhow::{Context, Result};
use clap::Parser;
Expand Down Expand Up @@ -88,7 +88,7 @@ enum ConfigSub {
/// Generate validators' config file
ValidatorInit {
/// check the files generated
#[clap(short, long, default_value = "false")]
#[clap(short, long)]
check: bool,
},

Expand All @@ -97,6 +97,9 @@ enum ConfigSub {
/// path to libra config and data files defaults to $HOME/.libra
#[clap(long)]
home_path: Option<PathBuf>,
/// private VFN (only for validators)
#[clap(short, long)]
vfn: bool,
},
}

Expand Down Expand Up @@ -238,11 +241,19 @@ impl ConfigCli {
println!("Validators' config initialized.");
Ok(())
}
Some(ConfigSub::FullnodeInit { home_path }) => {
Some(ConfigSub::FullnodeInit { home_path, vfn }) => {
download_genesis(home_path.to_owned()).await?;
println!("downloaded genesis block");

let p = init_fullnode_yaml(home_path.to_owned()).await?;
let p = if *vfn {
// no need for seed peers, will be identified
// to validator node
init_fullnode_yaml(home_path.to_owned(), true, true).await?
} else {
// we want seed peers, and will not have an identity
init_fullnode_yaml(home_path.to_owned(), true, false).await?
};

println!("config created at {}", p.display());

ol_progress::OLProgress::complete("fullnode configs initialized");
Expand Down
6 changes: 3 additions & 3 deletions tools/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod config_cli;
pub mod fullnode_config;
pub mod host;
pub mod legacy_config;
pub mod make_profile;
pub mod node_yaml;
pub mod make_yaml_public_fullnode;
pub mod make_yaml_validator;
pub mod validator_config;
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ use std::{
};

/// fetch seed peers and make a yaml file from template
pub async fn init_fullnode_yaml(home_dir: Option<PathBuf>) -> anyhow::Result<PathBuf> {
pub async fn init_fullnode_yaml(
home_dir: Option<PathBuf>,
overwrite_peers: bool,
vfn: bool,
) -> anyhow::Result<PathBuf> {
let waypoint = get_genesis_waypoint(home_dir.clone()).await?;

let yaml = make_fullnode_yaml(home_dir.clone(), waypoint)?;
let yaml = if vfn {
make_private_vfn_yaml(home_dir.clone(), waypoint)?
} else {
make_fullnode_yaml(home_dir.clone(), waypoint)?
};

let filename = if vfn { "vfn.yaml" } else { "fullnode.yaml" };

let home = home_dir.unwrap_or_else(global_config_dir);
let p = home.join("fullnode.yaml");
let p = home.join(filename);
std::fs::write(&p, yaml)?;

let peers = fetch_seed_addresses(None).await?;

add_peers_to_yaml(&p, peers)?;
if overwrite_peers {
let peers = fetch_seed_addresses(None).await?;
add_peers_to_yaml(&p, peers)?;
}

Ok(p)
}
Expand Down Expand Up @@ -75,7 +86,7 @@ execution:
state_sync:
state_sync_driver:
bootstrapping_mode: DownloadLatestStates
continuous_syncing_mode: ExecuteTransactionsOrApplyOutputs
continuous_syncing_mode: ApplyTransactionOutputs
full_node_networks:
- network_id: 'public'
Expand All @@ -89,6 +100,53 @@ api:
Ok(template)
}

/// Create a VFN file to for validators to seed the public network
pub fn make_private_vfn_yaml(
home_dir: Option<PathBuf>,
waypoint: Waypoint,
) -> anyhow::Result<String> {
let home_dir = home_dir.unwrap_or_else(global_config_dir);
let path = home_dir.display().to_string();

let template = format!(
"
base:
role: 'full_node'
data_dir: '{path}/data'
waypoint:
from_config: '{waypoint}'
execution:
genesis_file_location: '{path}/genesis/genesis.blob'
state_sync:
state_sync_driver:
bootstrapping_mode: ApplyTransactionOutputsFromGenesis
continuous_syncing_mode: ApplyTransactionOutputs
full_node_networks:
- network_id: 'public'
listen_address: '/ip4/0.0.0.0/tcp/6182'
identity:
type: 'from_file'
path: {path}/validator-full-node-identity.yaml
- network_id:
private: 'vfn'
# mutual_authentication: true
listen_address: '/ip4/0.0.0.0/tcp/6181'
identity:
type: 'from_file'
path: {path}/validator-full-node-identity.yaml
api:
enabled: false
address: '0.0.0.0:8080'
"
);
Ok(template)
}

/// download genesis blob
pub async fn download_genesis(home_dir: Option<PathBuf>) -> anyhow::Result<()> {
let bytes = reqwest::get(
Expand Down Expand Up @@ -177,5 +235,4 @@ async fn persist_genesis() {
.unwrap()
.unwrap();
assert!(l.file_name().to_str().unwrap().contains("genesis.blob"));
// dbg!(&l);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ validator_network:
full_node_networks:
- network_id:
private: 'vfn'
#mutual_authentication: true
listen_address: '/ip4/0.0.0.0/tcp/6181'
identity:
type: 'from_file'
path: {path}/validator-full-node-identity.yaml
api:
enabled: true
address: '0.0.0.0:8080'
address: '127.0.0.1:8080'
"
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::node_yaml;
use crate::make_yaml_validator;
use anyhow::{bail, Context};
use dialoguer::{Confirm, Input};
use diem_genesis::config::HostAndPort;
Expand Down Expand Up @@ -28,7 +28,7 @@ pub fn initialize_validator(
.set_config_files()?;
OLProgress::complete("saved validator registration files locally");

node_yaml::save_validator_yaml(home_path.clone())?;
make_yaml_validator::save_validator_yaml(home_path.clone())?;
OLProgress::complete("saved validator node yaml file locally");

// TODO: nice to have
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis/src/testnet_setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{genesis_builder, parse_json, supply::SupplySettings};
use diem_genesis::config::{HostAndPort, ValidatorConfiguration};
use libra_config::host;
use libra_config::validator_config;
use libra_types::{exports::NamedChain, legacy_types::fixtures::TestPersona};
use std::{fs, net::Ipv4Addr, path::PathBuf, thread, time};

Expand Down Expand Up @@ -33,7 +33,7 @@ pub fn setup(
let my_host: HostAndPort = format_host_str
.parse()
.expect("could not parse IP address for host");
host::initialize_validator(
validator_config::initialize_validator(
Some(data_path.clone()),
Some(&me.to_string()),
my_host,
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis/src/wizard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use diem_github_client::Client;
use libra_types::legacy_types::app_cfg::AppCfg;
use libra_wallet::keys::VALIDATOR_FILE;

use libra_config::host::initialize_validator_configs;
use libra_config::validator_config::initialize_validator_configs;

pub const DEFAULT_GIT_BRANCH: &str = "main";
pub const GITHUB_TOKEN_FILENAME: &str = "github_token.txt";
Expand Down

0 comments on commit b7ddfe3

Please sign in to comment.