Allow a solana-validator to join a cluster established by solana-test-validator (backport #18394) (#18399)

* Report 404 instead of 502 when a snapshot file is not found

This provides the client with more useful information about why their
request failed

(cherry picked from commit 40d696fcbc)

* As a last resort try to download an uncompressed snapshot

`solana-test-validator` creates uncompressed snapshots and it can be
useful to attach another validator to a `solana-test-validator` cluster
from time to time

(cherry picked from commit e36247d187)

Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
mergify[bot]
2021-07-03 00:27:42 +00:00
committed by GitHub
parent eb683dd402
commit 88462e67b5
2 changed files with 14 additions and 7 deletions

View File

@ -258,6 +258,7 @@ pub fn download_snapshot<'a, 'b>(
ArchiveFormat::TarZstd,
ArchiveFormat::TarGzip,
ArchiveFormat::TarBzip2,
ArchiveFormat::Tar, // `solana-test-validator` creates uncompressed snapshots
] {
let desired_snapshot_package = snapshot_utils::get_snapshot_archive_path(
snapshot_output_dir.to_path_buf(),
@ -269,7 +270,7 @@ pub fn download_snapshot<'a, 'b>(
return Ok(());
}
if download_file(
match download_file(
&format!(
"http://{}/{}",
rpc_addr,
@ -282,11 +283,13 @@ pub fn download_snapshot<'a, 'b>(
&desired_snapshot_package,
use_progress_bar,
progress_notify_callback,
)
.is_ok()
{
return Ok(());
) {
Ok(()) => return Ok(()),
Err(err) => info!("{}", err),
}
}
Err("Snapshot couldn't be downloaded".to_string())
Err(format!(
"Failed to download a snapshot for slot {} from {}",
desired_snapshot_hash.0, rpc_addr
))
}

View File

@ -165,7 +165,11 @@ impl RpcRequestMiddleware {
should_validate_hosts: true,
response: Box::pin(async {
match Self::open_no_follow(filename).await {
Err(_) => Ok(Self::internal_server_error()),
Err(err) => Ok(if err.kind() == std::io::ErrorKind::NotFound {
Self::not_found()
} else {
Self::internal_server_error()
}),
Ok(file) => {
let stream =
FramedRead::new(file, BytesCodec::new()).map_ok(|b| b.freeze());