Skip to content

Commit

Permalink
Different error if block status is not yet available (solana-labs#20407)
Browse files Browse the repository at this point in the history
* Different error if block is not available

* Add slot to error message

* Make and use helper function

* Check finalized path as well

Co-authored-by: Tyera Eulberg <tyera@solana.com>
  • Loading branch information
sakridge and Tyera Eulberg authored Oct 27, 2021
1 parent 036d7fc commit 700e42d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions client/src/rpc_custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub const JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: i64 = -32010;
pub const JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: i64 = -32011;
pub const JSON_RPC_SCAN_ERROR: i64 = -32012;
pub const JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: i64 = -32013;
pub const JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: i64 = -32014;

#[derive(Error, Debug)]
pub enum RpcCustomError {
Expand Down Expand Up @@ -54,6 +55,8 @@ pub enum RpcCustomError {
ScanError { message: String },
#[error("TransactionSignatureLenMismatch")]
TransactionSignatureLenMismatch,
#[error("BlockStatusNotAvailableYet")]
BlockStatusNotAvailableYet { slot: Slot },
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -161,6 +164,11 @@ impl From<RpcCustomError> for Error {
message: "Transaction signature length mismatch".to_string(),
data: None,
},
RpcCustomError::BlockStatusNotAvailableYet { slot } => Self {
code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET),
message: format!("Block status not yet available for slot {}", slot),
data: None,
},
}
}
}
21 changes: 15 additions & 6 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,18 @@ impl JsonRpcRequestProcessor {
Ok(())
}

fn check_status_is_complete(&self, slot: Slot) -> Result<()> {
if slot
> self
.max_complete_transaction_status_slot
.load(Ordering::SeqCst)
{
Err(RpcCustomError::BlockStatusNotAvailableYet { slot }.into())
} else {
Ok(())
}
}

pub async fn get_block(
&self,
slot: Slot,
Expand All @@ -985,6 +997,7 @@ impl JsonRpcRequestProcessor {
.unwrap()
.highest_confirmed_root()
{
self.check_status_is_complete(slot)?;
let result = self.blockstore.get_rooted_block(slot, true);
self.check_blockstore_root(&result, slot)?;
let configure_block = |confirmed_block: ConfirmedBlock| {
Expand All @@ -1009,12 +1022,8 @@ impl JsonRpcRequestProcessor {
} else if commitment.is_confirmed() {
// Check if block is confirmed
let confirmed_bank = self.bank(Some(CommitmentConfig::confirmed()));
if confirmed_bank.status_cache_ancestors().contains(&slot)
&& slot
<= self
.max_complete_transaction_status_slot
.load(Ordering::SeqCst)
{
if confirmed_bank.status_cache_ancestors().contains(&slot) {
self.check_status_is_complete(slot)?;
let result = self.blockstore.get_complete_block(slot, true);
return Ok(result.ok().map(|mut confirmed_block| {
if confirmed_block.block_time.is_none()
Expand Down

0 comments on commit 700e42d

Please sign in to comment.