Separate blockstore checks for not (yet) rooted and cleaned up (#13814)
This commit is contained in:
parent
0e2578a0b8
commit
4ff0f0949a
|
@ -599,7 +599,25 @@ impl JsonRpcRequestProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_slot_blockstore_status<T>(
|
||||
fn check_blockstore_max_root<T>(
|
||||
&self,
|
||||
result: &std::result::Result<T, BlockstoreError>,
|
||||
slot: Slot,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
if result.is_err() {
|
||||
if let BlockstoreError::SlotNotRooted = result.as_ref().unwrap_err() {
|
||||
if slot > self.blockstore.max_root() {
|
||||
return Err(RpcCustomError::BlockNotAvailable { slot }.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_slot_cleaned_up<T>(
|
||||
&self,
|
||||
result: &std::result::Result<T, BlockstoreError>,
|
||||
slot: Slot,
|
||||
|
@ -618,9 +636,6 @@ impl JsonRpcRequestProcessor {
|
|||
}
|
||||
.into());
|
||||
}
|
||||
if let BlockstoreError::SlotNotRooted = result.as_ref().unwrap_err() {
|
||||
return Err(RpcCustomError::BlockNotAvailable { slot }.into());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -640,6 +655,7 @@ impl JsonRpcRequestProcessor {
|
|||
.highest_confirmed_root()
|
||||
{
|
||||
let result = self.blockstore.get_confirmed_block(slot);
|
||||
self.check_blockstore_max_root(&result, slot)?;
|
||||
if result.is_err() {
|
||||
if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage {
|
||||
return Ok(self
|
||||
|
@ -649,7 +665,7 @@ impl JsonRpcRequestProcessor {
|
|||
.map(|confirmed_block| confirmed_block.encode(encoding)));
|
||||
}
|
||||
}
|
||||
self.check_slot_blockstore_status(&result, slot)?;
|
||||
self.check_slot_cleaned_up(&result, slot)?;
|
||||
Ok(result
|
||||
.ok()
|
||||
.map(|confirmed_block| confirmed_block.encode(encoding)))
|
||||
|
@ -745,6 +761,7 @@ impl JsonRpcRequestProcessor {
|
|||
.highest_confirmed_root()
|
||||
{
|
||||
let result = self.blockstore.get_block_time(slot);
|
||||
self.check_blockstore_max_root(&result, slot)?;
|
||||
if result.is_err() {
|
||||
if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage {
|
||||
return Ok(self
|
||||
|
@ -754,7 +771,7 @@ impl JsonRpcRequestProcessor {
|
|||
.and_then(|confirmed_block| confirmed_block.block_time));
|
||||
}
|
||||
}
|
||||
self.check_slot_blockstore_status(&result, slot)?;
|
||||
self.check_slot_cleaned_up(&result, slot)?;
|
||||
Ok(result.ok().unwrap_or(None))
|
||||
} else {
|
||||
Err(RpcCustomError::BlockNotAvailable { slot }.into())
|
||||
|
|
Loading…
Reference in New Issue