Skip to content

Commit

Permalink
Remove Option<_> from Blockstore::get_rooted_block_time() return type (
Browse files Browse the repository at this point in the history
…solana-labs#33955)

Instead of returning Result<Option<UnixTimestamp>>, return
Result<UnixTimestamp> and map None to an error. This makes the return
type similar to that of Blockstore::get_rooted_block().
  • Loading branch information
steviez authored Nov 6, 2023
1 parent 6624a09 commit ee29647
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,14 +1967,18 @@ impl Blockstore {
self.blocktime_cf.get(slot)
}

pub fn get_rooted_block_time(&self, slot: Slot) -> Result<Option<UnixTimestamp>> {
pub fn get_rooted_block_time(&self, slot: Slot) -> Result<UnixTimestamp> {
datapoint_info!(
"blockstore-rpc-api",
("method", "get_rooted_block_time", String)
);
let _lock = self.check_lowest_cleanup_slot(slot)?;

if self.is_root(slot) {
return self.blocktime_cf.get(slot);
return self
.blocktime_cf
.get(slot)?
.ok_or(BlockstoreError::SlotUnavailable);
}
Err(BlockstoreError::SlotNotRooted)
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ impl JsonRpcRequestProcessor {
{
let result = self.blockstore.get_rooted_block_time(slot);
self.check_blockstore_root(&result, slot)?;
if result.is_err() || matches!(result, Ok(None)) {
if result.is_err() {
if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage {
let bigtable_result = bigtable_ledger_storage.get_confirmed_block(slot).await;
self.check_bigtable_result(&bigtable_result)?;
Expand All @@ -1333,7 +1333,7 @@ impl JsonRpcRequestProcessor {
}
}
self.check_slot_cleaned_up(&result, slot)?;
Ok(result.ok().unwrap_or(None))
Ok(result.ok())
} else {
let r_bank_forks = self.bank_forks.read().unwrap();
if let Some(bank) = r_bank_forks.get(slot) {
Expand Down

0 comments on commit ee29647

Please sign in to comment.