Skip to content

Commit

Permalink
Add ability to get the latest incremental snapshot via RPC (solana-la…
Browse files Browse the repository at this point in the history
  • Loading branch information
diman-io authored Mar 21, 2022
1 parent ae76fe2 commit 739e43b
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions rpc/src/rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ use {
tokio_util::codec::{BytesCodec, FramedRead},
};

const FULL_SNAPSHOT_REQUEST_PATH: &str = "/snapshot.tar.bz2";
const INCREMENTAL_SNAPSHOT_REQUEST_PATH: &str = "/incremental-snapshot.tar.bz2";
const LARGEST_ACCOUNTS_CACHE_DURATION: u64 = 60 * 60 * 2;

pub struct JsonRpcService {
Expand Down Expand Up @@ -227,16 +229,37 @@ impl RequestMiddleware for RpcRequestMiddleware {
trace!("request uri: {}", request.uri());

if let Some(ref snapshot_config) = self.snapshot_config {
if request.uri().path() == "/snapshot.tar.bz2" {
if request.uri().path() == FULL_SNAPSHOT_REQUEST_PATH
|| request.uri().path() == INCREMENTAL_SNAPSHOT_REQUEST_PATH
{
// Convenience redirect to the latest snapshot
return if let Some(full_snapshot_archive_info) =
let full_snapshot_archive_info =
snapshot_utils::get_highest_full_snapshot_archive_info(
&snapshot_config.snapshot_archives_dir,
) {
);
let snapshot_archive_info =
if let Some(full_snapshot_archive_info) = full_snapshot_archive_info {
if request.uri().path() == FULL_SNAPSHOT_REQUEST_PATH {
Some(full_snapshot_archive_info.snapshot_archive_info().clone())
} else {
snapshot_utils::get_highest_incremental_snapshot_archive_info(
&snapshot_config.snapshot_archives_dir,
full_snapshot_archive_info.slot(),
)
.map(|incremental_snapshot_archive_info| {
incremental_snapshot_archive_info
.snapshot_archive_info()
.clone()
})
}
} else {
None
};
return if let Some(snapshot_archive_info) = snapshot_archive_info {
RpcRequestMiddleware::redirect(&format!(
"/{}",
full_snapshot_archive_info
.path()
snapshot_archive_info
.path
.file_name()
.unwrap_or_else(|| std::ffi::OsStr::new(""))
.to_str()
Expand Down

0 comments on commit 739e43b

Please sign in to comment.