From 403216c6af54e3694c371736a2adda0b39ff3476 Mon Sep 17 00:00:00 2001 From: Steven Czabaniuk Date: Fri, 23 Dec 2022 01:59:47 -0500 Subject: [PATCH] Adjust ledger-tool bigtable upload starting-slot default value Currently, if starting-slot is unspecified, a value of 0 will be chosen. In the common case where someone is operating on a range much more recent, this will result in a ton of wasted operations. Instead, choose a smarter default value for starting-slot based on what we detect is currently in the blockstore. --- ledger-tool/src/bigtable.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ledger-tool/src/bigtable.rs b/ledger-tool/src/bigtable.rs index fae7fda6d260a7..f99ed35ae46cd6 100644 --- a/ledger-tool/src/bigtable.rs +++ b/ledger-tool/src/bigtable.rs @@ -38,7 +38,7 @@ use { async fn upload( blockstore: Blockstore, - mut starting_slot: Slot, + starting_slot: Option, ending_slot: Option, force_reupload: bool, config: solana_storage_bigtable::LedgerStorageConfig, @@ -53,6 +53,16 @@ async fn upload( }; let blockstore = Arc::new(blockstore); + let starting_slot = if let Some(starting_slot) = starting_slot { + Ok(starting_slot) + } else { + // It is possible that the slot returned below could get purged by + // LedgerCleanupService before upload_confirmed_blocks() get the value. + // However, this is ok as upload_confirmed_blocks() doesn't need this + // exact slot to be in ledger. + blockstore.get_first_available_block() + }; + let mut starting_slot = starting_slot?; let ending_slot = ending_slot.unwrap_or_else(|| blockstore.last_root()); while starting_slot <= ending_slot { @@ -640,7 +650,7 @@ pub fn bigtable_process_command( let future = match (subcommand, sub_matches) { ("upload", Some(arg_matches)) => { - let starting_slot = value_t!(arg_matches, "starting_slot", Slot).unwrap_or(0); + let starting_slot = value_t!(arg_matches, "starting_slot", Slot).ok(); let ending_slot = value_t!(arg_matches, "ending_slot", Slot).ok(); let force_reupload = arg_matches.is_present("force_reupload"); let blockstore = crate::open_blockstore(