Skip to content

Commit d320f41

Browse files
0o-de-lallyRupert LentoAlgernon O'CrescendoBasil MacPianissimoCaty Heron
authored andcommitted
[config] fullnode pruning options (#432)
Co-authored-by: Rupert Lento <rupert_lento@github.com> Co-authored-by: Algernon O'Crescendo <algernon_o'crescendo@github.com> Co-authored-by: Basil MacPianissimo <basil_macpianissimo@github.com> Co-authored-by: Caty Heron <caty_heron@github.com> Co-authored-by: Gabi McAndante <gabi_mcandante@github.com>
1 parent d15efe3 commit d320f41

3 files changed

Lines changed: 94 additions & 11 deletions

File tree

tools/config/src/config_cli.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
};
88
use anyhow::{bail, Context, Result};
99
use clap::Parser;
10+
use dialoguer::Select;
1011
use libra_types::{
1112
core_types::network_playlist::NetworkPlaylist,
1213
exports::{AccountAddress, AuthenticationKey, NamedChain},
@@ -211,8 +212,17 @@ impl ConfigCli {
211212
Some(ConfigSub::FullnodeInit { home_path }) => {
212213
download_genesis(home_path.to_owned()).await?;
213214
println!("downloaded genesis block");
215+
let sync_options = vec!["Fast Sync (default)", "Archive (full history)"];
216+
let selection = Select::new()
217+
.with_prompt("choose fullnode sync mode")
218+
.default(0)
219+
.items(&sync_options)
220+
.interact()?;
214221

215-
let p = init_fullnode_yaml(home_path.to_owned(), true).await?;
222+
let archive_mode = selection != 0;
223+
224+
// You can now use `archive_mode` to configure the fullnode accordingly.
225+
let p = init_fullnode_yaml(home_path.to_owned(), true, archive_mode).await?;
216226

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

tools/config/src/make_yaml_public_fullnode.rs

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ struct GithubContent {
3131
pub async fn init_fullnode_yaml(
3232
home_dir: Option<PathBuf>,
3333
overwrite_peers: bool,
34+
archive_mode: bool,
3435
) -> anyhow::Result<PathBuf> {
3536
let waypoint = get_genesis_waypoint(home_dir.clone()).await?;
3637

37-
let yaml = make_fullnode_yaml(home_dir.clone(), waypoint)?;
38+
let yaml = match archive_mode {
39+
true => make_fullnode_archive_yaml(home_dir.clone(), waypoint)?,
40+
false => make_fullnode_fast_sync_yaml(home_dir.clone(), waypoint)?,
41+
};
3842

3943
let home = home_dir.unwrap_or_else(global_config_dir);
4044
let p = home.join(FN_FILENAME);
@@ -85,8 +89,51 @@ pub async fn fetch_seed_addresses(
8589
Ok(seeds)
8690
}
8791

92+
/// A fullnode config which does a fast sync to the chain
93+
/// as opposed to the default fullnode config for archive nodes.
94+
pub fn make_fullnode_fast_sync_yaml(
95+
home_dir: Option<PathBuf>,
96+
waypoint: Waypoint,
97+
) -> anyhow::Result<String> {
98+
let home_dir = home_dir.unwrap_or_else(global_config_dir);
99+
let path = home_dir.display().to_string();
100+
101+
// Create the YAML template with necessary configurations
102+
let template = format!(
103+
"
104+
base:
105+
role: 'full_node'
106+
data_dir: '{path}/data'
107+
waypoint:
108+
from_config: '{waypoint}'
109+
110+
execution:
111+
genesis_file_location: '{path}/genesis/genesis.blob'
112+
113+
state_sync:
114+
state_sync_driver:
115+
bootstrapping_mode: DownloadLatestStates
116+
continuous_syncing_mode: ApplyTransactionOutputs
117+
118+
full_node_networks:
119+
- network_id: 'public'
120+
listen_address: '/ip4/0.0.0.0/tcp/6182'
121+
max_outbound_connections: 10
122+
123+
124+
api:
125+
enabled: true
126+
address: '0.0.0.0:8080'
127+
"
128+
);
129+
Ok(template)
130+
}
131+
88132
/// Create a fullnode yaml to bootstrap node
89-
pub fn make_fullnode_yaml(home_dir: Option<PathBuf>, waypoint: Waypoint) -> anyhow::Result<String> {
133+
pub fn make_fullnode_archive_yaml(
134+
home_dir: Option<PathBuf>,
135+
waypoint: Waypoint,
136+
) -> anyhow::Result<String> {
90137
let home_dir = home_dir.unwrap_or_else(global_config_dir);
91138
let path = home_dir.display().to_string();
92139

@@ -106,10 +153,19 @@ state_sync:
106153
state_sync_driver:
107154
bootstrapping_mode: ExecuteOrApplyFromGenesis
108155
continuous_syncing_mode: ApplyTransactionOutputs
156+
storage:
157+
storage_pruner_config:
158+
ledger_pruner_config:
159+
enable: false
160+
state_merkle_pruner_config:
161+
enable: false
162+
epoch_snapshot_pruner_config:
163+
enable: false
109164
110165
full_node_networks:
111166
- network_id: 'public'
112167
listen_address: '/ip4/0.0.0.0/tcp/6182'
168+
max_outbound_connections: 10
113169
114170
api:
115171
enabled: true
@@ -146,9 +202,19 @@ state_sync:
146202
bootstrapping_mode: ApplyTransactionOutputsFromGenesis
147203
continuous_syncing_mode: ApplyTransactionOutputs
148204
205+
storage:
206+
storage_pruner_config:
207+
ledger_pruner_config:
208+
enable: false
209+
state_merkle_pruner_config:
210+
enable: false
211+
epoch_snapshot_pruner_config:
212+
enable: false
213+
149214
full_node_networks:
150215
- network_id: 'public'
151216
listen_address: '/ip4/0.0.0.0/tcp/6182'
217+
max_outbound_connections: 10
152218
identity:
153219
type: 'from_file'
154220
path: {path}/validator-full-node-identity.yaml
@@ -180,21 +246,14 @@ mempool:
180246
Ok(template)
181247
}
182248

183-
// #[tokio::test]
184-
// async fn get_peers() {
185-
// let _seed = fetch_seed_addresses(None).await.unwrap();
186-
187-
// TODO: test
188-
// }
189-
190249
#[tokio::test]
191250
async fn get_yaml() {
192251
use std::str::FromStr;
193252
let p = diem_temppath::TempPath::new().path().to_owned();
194253

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

197-
let y = make_fullnode_yaml(
256+
let y = make_fullnode_archive_yaml(
198257
Some(p.clone()),
199258
Waypoint::from_str("0:95023f4d6a7e24cac3e52cad29697184db260214210b57aef3f1031ad4d8c02c")
200259
.unwrap(),

tools/config/src/make_yaml_validator.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ validator_network:
4747
type: 'from_file'
4848
path: {path}/validator-identity.yaml
4949
50+
state_sync:
51+
state_sync_driver:
52+
bootstrapping_mode: ExecuteOrApplyFromGenesis
53+
continuous_syncing_mode: ApplyTransactionOutputs
54+
55+
storage:
56+
storage_pruner_config:
57+
ledger_pruner_config:
58+
enable: false
59+
state_merkle_pruner_config:
60+
enable: false
61+
epoch_snapshot_pruner_config:
62+
enable: false
63+
5064
full_node_networks:
5165
- network_id:
5266
private: 'vfn'

0 commit comments

Comments
 (0)