Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check whether accounts and snapshots are using the same path #1853

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ thiserror = { workspace = true }
tokio = { workspace = true }

[dev-dependencies]
assert_cmd = { workspace = true }
predicates = { workspace = true }
solana-account-decoder = { workspace = true }
solana-inline-spl = { workspace = true }
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
tempfile = { workspace = true }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = { workspace = true }
Expand Down
21 changes: 15 additions & 6 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,21 @@ pub fn main() {
} else {
vec![ledger_path.join("accounts")]
};

let snapshots_dir = if let Some(snapshots) = matches.value_of("snapshots") {
Path::new(snapshots)
} else {
&ledger_path
};
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved

// they have the same subdirectory name, "snapshot". try to catch the directory collision error earlier
for account_path in account_paths.iter() {
if account_path.as_path() == snapshots_dir {
eprintln!("Please provide different values for --accounts and --snapshots");
exit(1);
}
}
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved

let account_paths = create_and_canonicalize_directories(account_paths).unwrap_or_else(|err| {
eprintln!("Unable to access account path: {err}");
exit(1);
Expand Down Expand Up @@ -1589,12 +1604,6 @@ pub fn main() {
let maximum_snapshot_download_abort =
value_t_or_exit!(matches, "maximum_snapshot_download_abort", u64);

let snapshots_dir = if let Some(snapshots) = matches.value_of("snapshots") {
Path::new(snapshots)
} else {
&ledger_path
};

let bank_snapshots_dir = snapshots_dir.join("snapshots");
fs::create_dir_all(&bank_snapshots_dir).unwrap_or_else(|err| {
eprintln!(
Expand Down
36 changes: 36 additions & 0 deletions validator/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use {
assert_cmd::prelude::*,
solana_sdk::signer::keypair::{write_keypair_file, Keypair},
std::process::Command,
tempfile::TempDir,
};

#[test]
fn test_use_the_same_path_for_accounts_and_snapshots() {
let temp_dir = TempDir::new().unwrap();
let temp_dir_path = temp_dir.path();

let id_json_path = temp_dir_path.join("id.json");
let id_json_str = id_json_path.to_str().unwrap();

let keypair = Keypair::new();
write_keypair_file(&keypair, id_json_str).unwrap();

let temp_dir_str = temp_dir_path.to_str().unwrap();

let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.args([
"--identity",
id_json_str,
"--log",
"-",
"--no-voting",
"--accounts",
temp_dir_str,
"--snapshots",
temp_dir_str,
]);
cmd.assert().failure().stderr(predicates::str::contains(
"Please provide different values for --accounts and --snapshots",
));
}