Skip to content

Commit 42a2c29

Browse files
Different error if block status is not yet available (solana-labs#20407) (solana-labs#21029)
* 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 <[email protected]> (cherry picked from commit 700e42d) Co-authored-by: sakridge <[email protected]>
1 parent a1f1264 commit 42a2c29

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

client/src/rpc_custom_error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub const JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: i64 = -32010;
1919
pub const JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: i64 = -32011;
2020
pub const JSON_RPC_SCAN_ERROR: i64 = -32012;
2121
pub const JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: i64 = -32013;
22+
pub const JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: i64 = -32014;
2223

2324
#[derive(Error, Debug)]
2425
pub enum RpcCustomError {
@@ -54,6 +55,8 @@ pub enum RpcCustomError {
5455
ScanError { message: String },
5556
#[error("TransactionSignatureLenMismatch")]
5657
TransactionSignatureLenMismatch,
58+
#[error("BlockStatusNotAvailableYet")]
59+
BlockStatusNotAvailableYet { slot: Slot },
5760
}
5861

5962
#[derive(Debug, Serialize, Deserialize)]
@@ -161,6 +164,11 @@ impl From<RpcCustomError> for Error {
161164
message: "Transaction signature length mismatch".to_string(),
162165
data: None,
163166
},
167+
RpcCustomError::BlockStatusNotAvailableYet { slot } => Self {
168+
code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET),
169+
message: format!("Block status not yet available for slot {}", slot),
170+
data: None,
171+
},
164172
}
165173
}
166174
}

rpc/src/rpc.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,18 @@ impl JsonRpcRequestProcessor {
941941
Ok(())
942942
}
943943

944+
fn check_status_is_complete(&self, slot: Slot) -> Result<()> {
945+
if slot
946+
> self
947+
.max_complete_transaction_status_slot
948+
.load(Ordering::SeqCst)
949+
{
950+
Err(RpcCustomError::BlockStatusNotAvailableYet { slot }.into())
951+
} else {
952+
Ok(())
953+
}
954+
}
955+
944956
pub async fn get_block(
945957
&self,
946958
slot: Slot,
@@ -964,6 +976,7 @@ impl JsonRpcRequestProcessor {
964976
.unwrap()
965977
.highest_confirmed_root()
966978
{
979+
self.check_status_is_complete(slot)?;
967980
let result = self.blockstore.get_rooted_block(slot, true);
968981
self.check_blockstore_root(&result, slot)?;
969982
let configure_block = |confirmed_block: ConfirmedBlock| {
@@ -988,12 +1001,8 @@ impl JsonRpcRequestProcessor {
9881001
} else if commitment.is_confirmed() {
9891002
// Check if block is confirmed
9901003
let confirmed_bank = self.bank(Some(CommitmentConfig::confirmed()));
991-
if confirmed_bank.status_cache_ancestors().contains(&slot)
992-
&& slot
993-
<= self
994-
.max_complete_transaction_status_slot
995-
.load(Ordering::SeqCst)
996-
{
1004+
if confirmed_bank.status_cache_ancestors().contains(&slot) {
1005+
self.check_status_is_complete(slot)?;
9971006
let result = self.blockstore.get_complete_block(slot, true);
9981007
return Ok(result.ok().map(|mut confirmed_block| {
9991008
if confirmed_block.block_time.is_none()

0 commit comments

Comments
 (0)