Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion tools/config/src/config_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
};
use anyhow::{bail, Context, Result};
use clap::Parser;
use dialoguer::Select;
use libra_types::{
core_types::network_playlist::NetworkPlaylist,
exports::{AccountAddress, AuthenticationKey, NamedChain},
Expand Down Expand Up @@ -211,8 +212,17 @@ impl ConfigCli {
Some(ConfigSub::FullnodeInit { home_path }) => {
download_genesis(home_path.to_owned()).await?;
println!("downloaded genesis block");
let sync_options = vec!["Fast Sync (default)", "Archive (full history)"];
let selection = Select::new()
.with_prompt("choose fullnode sync mode")
.default(0)
.items(&sync_options)
.interact()?;

let p = init_fullnode_yaml(home_path.to_owned(), true).await?;
let archive_mode = selection != 0;

// You can now use `archive_mode` to configure the fullnode accordingly.
let p = init_fullnode_yaml(home_path.to_owned(), true, archive_mode).await?;

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

Expand Down
79 changes: 69 additions & 10 deletions tools/config/src/make_yaml_public_fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ struct GithubContent {
pub async fn init_fullnode_yaml(
home_dir: Option<PathBuf>,
overwrite_peers: bool,
archive_mode: bool,
) -> anyhow::Result<PathBuf> {
let waypoint = get_genesis_waypoint(home_dir.clone()).await?;

let yaml = make_fullnode_yaml(home_dir.clone(), waypoint)?;
let yaml = match archive_mode {
true => make_fullnode_archive_yaml(home_dir.clone(), waypoint)?,
false => make_fullnode_fast_sync_yaml(home_dir.clone(), waypoint)?,
};

let home = home_dir.unwrap_or_else(global_config_dir);
let p = home.join(FN_FILENAME);
Expand Down Expand Up @@ -85,8 +89,51 @@ pub async fn fetch_seed_addresses(
Ok(seeds)
}

/// A fullnode config which does a fast sync to the chain
/// as opposed to the default fullnode config for archive nodes.
pub fn make_fullnode_fast_sync_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();

// Create the YAML template with necessary configurations
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: DownloadLatestStates
continuous_syncing_mode: ApplyTransactionOutputs

full_node_networks:
- network_id: 'public'
listen_address: '/ip4/0.0.0.0/tcp/6182'
max_outbound_connections: 10


api:
enabled: true
address: '0.0.0.0:8080'
"
);
Ok(template)
}

/// Create a fullnode yaml to bootstrap node
pub fn make_fullnode_yaml(home_dir: Option<PathBuf>, waypoint: Waypoint) -> anyhow::Result<String> {
pub fn make_fullnode_archive_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();

Expand All @@ -106,10 +153,19 @@ state_sync:
state_sync_driver:
bootstrapping_mode: ExecuteOrApplyFromGenesis
continuous_syncing_mode: ApplyTransactionOutputs
storage:
storage_pruner_config:
ledger_pruner_config:
enable: false
state_merkle_pruner_config:
enable: false
epoch_snapshot_pruner_config:
enable: false

full_node_networks:
- network_id: 'public'
listen_address: '/ip4/0.0.0.0/tcp/6182'
max_outbound_connections: 10

api:
enabled: true
Expand Down Expand Up @@ -146,9 +202,19 @@ state_sync:
bootstrapping_mode: ApplyTransactionOutputsFromGenesis
continuous_syncing_mode: ApplyTransactionOutputs

storage:
storage_pruner_config:
ledger_pruner_config:
enable: false
state_merkle_pruner_config:
enable: false
epoch_snapshot_pruner_config:
enable: false

full_node_networks:
- network_id: 'public'
listen_address: '/ip4/0.0.0.0/tcp/6182'
max_outbound_connections: 10
identity:
type: 'from_file'
path: {path}/validator-full-node-identity.yaml
Expand Down Expand Up @@ -180,21 +246,14 @@ mempool:
Ok(template)
}

// #[tokio::test]
// async fn get_peers() {
// let _seed = fetch_seed_addresses(None).await.unwrap();

// TODO: test
// }

#[tokio::test]
async fn get_yaml() {
use std::str::FromStr;
let p = diem_temppath::TempPath::new().path().to_owned();

let seeds = fetch_seed_addresses(None).await.unwrap();

let y = make_fullnode_yaml(
let y = make_fullnode_archive_yaml(
Some(p.clone()),
Waypoint::from_str("0:95023f4d6a7e24cac3e52cad29697184db260214210b57aef3f1031ad4d8c02c")
.unwrap(),
Expand Down
14 changes: 14 additions & 0 deletions tools/config/src/make_yaml_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ validator_network:
type: 'from_file'
path: {path}/validator-identity.yaml

state_sync:
state_sync_driver:
bootstrapping_mode: ExecuteOrApplyFromGenesis
continuous_syncing_mode: ApplyTransactionOutputs

storage:
storage_pruner_config:
ledger_pruner_config:
enable: false
state_merkle_pruner_config:
enable: false
epoch_snapshot_pruner_config:
enable: false

full_node_networks:
- network_id:
private: 'vfn'
Expand Down
Loading