Make rpc_bootstrap() aware of local incremental snapshots (#20171)
This commit is contained in:
parent
46263d405e
commit
49e85afdcd
|
@ -503,12 +503,7 @@ fn get_rpc_node(
|
||||||
}
|
}
|
||||||
blacklist_timeout = Instant::now();
|
blacklist_timeout = Instant::now();
|
||||||
|
|
||||||
let mut highest_snapshot_hash: Option<(Slot, Hash)> =
|
let mut highest_snapshot_hash = get_highest_local_snapshot_hash(snapshot_archives_dir);
|
||||||
snapshot_utils::get_highest_full_snapshot_archive_info(snapshot_archives_dir).map(
|
|
||||||
|snapshot_archive_info| {
|
|
||||||
(snapshot_archive_info.slot(), *snapshot_archive_info.hash())
|
|
||||||
},
|
|
||||||
);
|
|
||||||
let eligible_rpc_peers = if snapshot_not_required {
|
let eligible_rpc_peers = if snapshot_not_required {
|
||||||
rpc_peers
|
rpc_peers
|
||||||
} else {
|
} else {
|
||||||
|
@ -893,28 +888,31 @@ fn rpc_bootstrap(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(snapshot_hash) = snapshot_hash {
|
if let Some(snapshot_hash) = snapshot_hash {
|
||||||
let mut use_local_snapshot = false;
|
let use_local_snapshot = match get_highest_local_snapshot_hash(snapshot_archives_dir) {
|
||||||
|
None => {
|
||||||
if let Some(highest_local_snapshot_slot) =
|
info!("Downloading snapshot for slot {} since there is not a local snapshot", snapshot_hash.0);
|
||||||
snapshot_utils::get_highest_full_snapshot_archive_slot(snapshot_archives_dir)
|
false
|
||||||
{
|
|
||||||
if highest_local_snapshot_slot
|
|
||||||
> snapshot_hash.0.saturating_sub(maximum_local_snapshot_age)
|
|
||||||
{
|
|
||||||
info!(
|
|
||||||
"Reusing local snapshot at slot {} instead \
|
|
||||||
of downloading a snapshot for slot {}",
|
|
||||||
highest_local_snapshot_slot, snapshot_hash.0
|
|
||||||
);
|
|
||||||
use_local_snapshot = true;
|
|
||||||
} else {
|
|
||||||
info!(
|
|
||||||
"Local snapshot from slot {} is too old. \
|
|
||||||
Downloading a newer snapshot for slot {}",
|
|
||||||
highest_local_snapshot_slot, snapshot_hash.0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
Some((highest_local_snapshot_slot, _hash)) => {
|
||||||
|
if highest_local_snapshot_slot
|
||||||
|
> snapshot_hash.0.saturating_sub(maximum_local_snapshot_age)
|
||||||
|
{
|
||||||
|
info!(
|
||||||
|
"Reusing local snapshot at slot {} instead \
|
||||||
|
of downloading a snapshot for slot {}",
|
||||||
|
highest_local_snapshot_slot, snapshot_hash.0
|
||||||
|
);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"Local snapshot from slot {} is too old. \
|
||||||
|
Downloading a newer snapshot for slot {}",
|
||||||
|
highest_local_snapshot_slot, snapshot_hash.0
|
||||||
|
);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if use_local_snapshot {
|
if use_local_snapshot {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -3072,3 +3070,29 @@ fn process_account_indexes(matches: &ArgMatches) -> AccountSecondaryIndexes {
|
||||||
indexes: account_indexes,
|
indexes: account_indexes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the Slot and Hash of the local snapshot with the highest slot. Can be either a full
|
||||||
|
/// snapshot or an incremental snapshot.
|
||||||
|
fn get_highest_local_snapshot_hash(
|
||||||
|
snapshot_archives_dir: impl AsRef<Path>,
|
||||||
|
) -> Option<(Slot, Hash)> {
|
||||||
|
if let Some(full_snapshot_info) =
|
||||||
|
snapshot_utils::get_highest_full_snapshot_archive_info(&snapshot_archives_dir)
|
||||||
|
{
|
||||||
|
if let Some(incremental_snapshot_info) =
|
||||||
|
snapshot_utils::get_highest_incremental_snapshot_archive_info(
|
||||||
|
&snapshot_archives_dir,
|
||||||
|
full_snapshot_info.slot(),
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Some((
|
||||||
|
incremental_snapshot_info.slot(),
|
||||||
|
*incremental_snapshot_info.hash(),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Some((full_snapshot_info.slot(), *full_snapshot_info.hash()))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue