* 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>
(cherry picked from commit 700e42d556
)
Co-authored-by: sakridge <sakridge@gmail.com>
This commit is contained in:
@ -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 {
|
||||
@ -54,6 +55,8 @@ pub enum RpcCustomError {
|
||||
ScanError { message: String },
|
||||
#[error("TransactionSignatureLenMismatch")]
|
||||
TransactionSignatureLenMismatch,
|
||||
#[error("BlockStatusNotAvailableYet")]
|
||||
BlockStatusNotAvailableYet { slot: Slot },
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -941,6 +941,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,
|
||||
@ -964,6 +976,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| {
|
||||
@ -988,12 +1001,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()
|
||||
|
Reference in New Issue
Block a user