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 2 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
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
43 changes: 29 additions & 14 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,24 @@ pub fn main() {
&ledger_path
};

let snapshots_dir = fs::canonicalize(snapshots_dir).unwrap_or_else(|err| {
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
eprintln!(
"Failed to canonicalize snapshots path '{}': {err}",
snapshots_dir.display(),
);
exit(1);
});
if account_paths
.iter()
.any(|account_path| account_path == &snapshots_dir)
{
eprintln!(
"Failed: The --accounts and --snapshots paths must be unique since they \
both create 'snapshots' subdirectories, otherwise there may be collisions",
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
);
exit(1);
}

let bank_snapshots_dir = snapshots_dir.join("snapshots");
fs::create_dir_all(&bank_snapshots_dir).unwrap_or_else(|err| {
eprintln!(
Expand All @@ -1604,13 +1622,12 @@ pub fn main() {
exit(1);
});

let full_snapshot_archives_dir = PathBuf::from(
let full_snapshot_archives_dir =
if let Some(full_snapshot_archive_path) = matches.value_of("full_snapshot_archive_path") {
Path::new(full_snapshot_archive_path)
PathBuf::from(full_snapshot_archive_path)
} else {
snapshots_dir
},
);
snapshots_dir.clone()
};
fs::create_dir_all(&full_snapshot_archives_dir).unwrap_or_else(|err| {
eprintln!(
"Failed to create full snapshot archives directory '{}': {err}",
Expand All @@ -1619,15 +1636,13 @@ pub fn main() {
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
},
);
let incremental_snapshot_archives_dir = if let Some(incremental_snapshot_archive_path) =
matches.value_of("incremental_snapshot_archive_path")
{
PathBuf::from(incremental_snapshot_archive_path)
} else {
snapshots_dir.clone()
};
fs::create_dir_all(&incremental_snapshot_archives_dir).unwrap_or_else(|err| {
eprintln!(
"Failed to create incremental snapshot archives directory '{}': {err}",
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(
"The --accounts and --snapshots paths must be unique",
));
}