Add --maximum-local-snapshot-age argument

This commit is contained in:
Michael Vines
2020-11-27 22:38:45 -08:00
committed by mergify[bot]
parent 6048342c57
commit aebf12e28d

View File

@ -640,6 +640,7 @@ fn rpc_bootstrap(
bootstrap_config: RpcBootstrapConfig, bootstrap_config: RpcBootstrapConfig,
no_port_check: bool, no_port_check: bool,
use_progress_bar: bool, use_progress_bar: bool,
maximum_local_snapshot_age: Slot,
) { ) {
if !no_port_check { if !no_port_check {
verify_reachable_ports(&node, cluster_entrypoint, &validator_config); verify_reachable_ports(&node, cluster_entrypoint, &validator_config);
@ -723,6 +724,22 @@ fn rpc_bootstrap(
} }
if let Some(snapshot_hash) = snapshot_hash { if let Some(snapshot_hash) = snapshot_hash {
let mut use_local_snapshot = false;
if let Some(highest_local_snapshot_slot) =
get_highest_snapshot_archive_path(ledger_path)
.map(|(_path, (slot, _hash, _compression))| slot)
{
if highest_local_snapshot_slot > snapshot_hash.0.saturating_sub(maximum_local_snapshot_age) {
info!("Reusing local snapshot at slot {} instead of downloading a newer snapshot for slot {}",
highest_local_snapshot_slot, snapshot_hash.0);
use_local_snapshot = true;
}
}
if use_local_snapshot {
Ok(())
} else {
rpc_client rpc_client
.get_slot_with_commitment(CommitmentConfig::root()) .get_slot_with_commitment(CommitmentConfig::root())
.map_err(|err| format!("Failed to get RPC node slot: {}", err)) .map_err(|err| format!("Failed to get RPC node slot: {}", err))
@ -740,6 +757,7 @@ fn rpc_bootstrap(
gossip_service.join().unwrap(); gossip_service.join().unwrap();
ret ret
}) })
}
} else { } else {
Ok(()) Ok(())
} }
@ -803,6 +821,7 @@ fn create_validator(
rpc_bootstrap_config: RpcBootstrapConfig, rpc_bootstrap_config: RpcBootstrapConfig,
no_port_check: bool, no_port_check: bool,
use_progress_bar: bool, use_progress_bar: bool,
maximum_local_snapshot_age: Slot,
) -> Validator { ) -> Validator {
if validator_config.cuda { if validator_config.cuda {
solana_perf::perf_libs::init_cuda(); solana_perf::perf_libs::init_cuda();
@ -822,6 +841,7 @@ fn create_validator(
rpc_bootstrap_config, rpc_bootstrap_config,
no_port_check, no_port_check,
use_progress_bar, use_progress_bar,
maximum_local_snapshot_age,
); );
} }
@ -1090,6 +1110,16 @@ pub fn main() {
.validator(port_range_validator) .validator(port_range_validator)
.help("Range to use for dynamically assigned ports"), .help("Range to use for dynamically assigned ports"),
) )
.arg(
Arg::with_name("maximum_local_snapshot_age")
.long("maximum-local-snapshot-age")
.value_name("NUMBER_OF_SLOTS")
.takes_value(true)
.default_value("500")
.help("Reuse a local snapshot if it's less than this many \
slots behind the highest snapshot available for \
download from other validators"),
)
.arg( .arg(
Arg::with_name("snapshot_interval_slots") Arg::with_name("snapshot_interval_slots")
.long("snapshot-interval-slots") .long("snapshot-interval-slots")
@ -1549,6 +1579,7 @@ pub fn main() {
.collect(); .collect();
let snapshot_interval_slots = value_t_or_exit!(matches, "snapshot_interval_slots", u64); let snapshot_interval_slots = value_t_or_exit!(matches, "snapshot_interval_slots", u64);
let maximum_local_snapshot_age = value_t_or_exit!(matches, "maximum_local_snapshot_age", u64);
let snapshot_path = ledger_path.join("snapshot"); let snapshot_path = ledger_path.join("snapshot");
fs::create_dir_all(&snapshot_path).unwrap_or_else(|err| { fs::create_dir_all(&snapshot_path).unwrap_or_else(|err| {
eprintln!( eprintln!(
@ -1755,6 +1786,7 @@ pub fn main() {
rpc_bootstrap_config, rpc_bootstrap_config,
no_port_check, no_port_check,
use_progress_bar, use_progress_bar,
maximum_local_snapshot_age,
); );
if let Some(filename) = init_complete_file { if let Some(filename) = init_complete_file {