Skip to content

Commit

Permalink
cli: Fixes snapshot paths (anza-xyz#1631)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored and samkim-crypto committed Jul 31, 2024
1 parent 21c8191 commit fe49d7b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Release channels have their own copy of this changelog:
* RPC's `simulateTransaction` now returns an extra `replacementBlockhash` field in the response
when the `replaceRecentBlockhash` config param is `true` (#380)
* SDK: `cargo test-sbf` accepts `--tools-version`, just like `build-sbf` (#1359)
* CLI: Can specify `--full-snapshot-archive-path` (#1631)

## [1.18.0]
* Changes
Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ fn main() {
Arg::with_name("snapshots")
.long("snapshots")
.alias("snapshot-archive-path")
.alias("full-snapshot-archive-path")
.value_name("DIR")
.takes_value(true)
.global(true)
Expand Down
18 changes: 16 additions & 2 deletions validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.long("snapshots")
.value_name("DIR")
.takes_value(true)
.help("Use DIR as snapshot location [default: <LEDGER>/snapshots]"),
.help(
"Use DIR as the base location for snapshots. \
A subdirectory named \"snapshots\" will be created. \
[default: --ledger value]",
),
)
.arg(
Arg::with_name(use_snapshot_archives_at_startup::cli::NAME)
Expand All @@ -343,14 +347,24 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.help(use_snapshot_archives_at_startup::cli::HELP)
.long_help(use_snapshot_archives_at_startup::cli::LONG_HELP),
)
.arg(
Arg::with_name("full_snapshot_archive_path")
.long("full-snapshot-archive-path")
.value_name("DIR")
.takes_value(true)
.help(
"Use DIR as full snapshot archives location \
[default: --snapshots value]",
),
)
.arg(
Arg::with_name("incremental_snapshot_archive_path")
.long("incremental-snapshot-archive-path")
.conflicts_with("no-incremental-snapshots")
.value_name("DIR")
.takes_value(true)
.help(
"Use DIR as separate location for incremental snapshot archives \
"Use DIR as incremental snapshot archives location \
[default: --snapshots value]",
),
)
Expand Down
63 changes: 38 additions & 25 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,36 +1589,49 @@ pub fn main() {
let maximum_snapshot_download_abort =
value_t_or_exit!(matches, "maximum_snapshot_download_abort", u64);

let full_snapshot_archives_dir = if matches.is_present("snapshots") {
PathBuf::from(matches.value_of("snapshots").unwrap())
let snapshots_dir = if let Some(snapshots) = matches.value_of("snapshots") {
Path::new(snapshots)
} else {
ledger_path.clone()
&ledger_path
};
let incremental_snapshot_archives_dir =
if matches.is_present("incremental_snapshot_archive_path") {
let incremental_snapshot_archives_dir = PathBuf::from(
matches
.value_of("incremental_snapshot_archive_path")
.unwrap(),
);
fs::create_dir_all(&incremental_snapshot_archives_dir).unwrap_or_else(|err| {
eprintln!(
"Failed to create incremental snapshot archives directory {:?}: {}",
incremental_snapshot_archives_dir.display(),
err
);
exit(1);
});
incremental_snapshot_archives_dir
} else {
full_snapshot_archives_dir.clone()
};
let bank_snapshots_dir = incremental_snapshot_archives_dir.join("snapshot");

let bank_snapshots_dir = snapshots_dir.join("snapshots");
fs::create_dir_all(&bank_snapshots_dir).unwrap_or_else(|err| {
eprintln!(
"Failed to create snapshots directory {:?}: {}",
"Failed to create bank snapshots directory '{}': {err}",
bank_snapshots_dir.display(),
err
);
exit(1);
});

let full_snapshot_archives_dir = PathBuf::from(
if let Some(full_snapshot_archive_path) = matches.value_of("full_snapshot_archive_path") {
Path::new(full_snapshot_archive_path)
} else {
snapshots_dir
},
);
fs::create_dir_all(&full_snapshot_archives_dir).unwrap_or_else(|err| {
eprintln!(
"Failed to create full snapshot archives directory '{}': {err}",
full_snapshot_archives_dir.display(),
);
exit(1);
});

let incremental_snapshot_archives_dir = PathBuf::from(
if let Some(incremental_snapshot_archive_path) =
matches.value_of("incremental_snapshot_archive_path")
{
Path::new(incremental_snapshot_archive_path)
} else {
snapshots_dir
},
);
fs::create_dir_all(&incremental_snapshot_archives_dir).unwrap_or_else(|err| {
eprintln!(
"Failed to create incremental snapshot archives directory '{}': {err}",
incremental_snapshot_archives_dir.display(),
);
exit(1);
});
Expand Down

0 comments on commit fe49d7b

Please sign in to comment.