diff --git a/core/src/rpc.rs b/core/src/rpc.rs index c7de1c404a..8a635439ef 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -578,7 +578,7 @@ impl JsonRpcRequestProcessor { self.check_slot_cleaned_up(&result, slot)?; Ok(result.ok()) } else { - Ok(None) + Err(RpcCustomError::BlockNotAvailable { slot }.into()) } } @@ -650,7 +650,7 @@ impl JsonRpcRequestProcessor { self.check_slot_cleaned_up(&result, slot)?; Ok(result.ok().unwrap_or(None)) } else { - Ok(None) + Err(RpcCustomError::BlockNotAvailable { slot }.into()) } } @@ -4496,7 +4496,7 @@ pub mod tests { slot ); let res = io.handle_request_sync(&req, meta); - let expected = r#"{"jsonrpc":"2.0","result":null,"id":1}"#; + let expected = r#"{"jsonrpc":"2.0","error":{"code":-32004,"message":"Block not available for slot 12345"},"id":1}"#; let expected: Response = serde_json::from_str(&expected).expect("expected response deserialization"); let result: Response = serde_json::from_str(&res.expect("actual response")) diff --git a/core/src/rpc_error.rs b/core/src/rpc_error.rs index a1ed091aad..6eea764fa4 100644 --- a/core/src/rpc_error.rs +++ b/core/src/rpc_error.rs @@ -5,6 +5,7 @@ const JSON_RPC_SERVER_ERROR_0: i64 = -32000; const JSON_RPC_SERVER_ERROR_1: i64 = -32001; const JSON_RPC_SERVER_ERROR_2: i64 = -32002; const JSON_RPC_SERVER_ERROR_3: i64 = -32003; +const JSON_RPC_SERVER_ERROR_4: i64 = -32004; pub enum RpcCustomError { NonexistentClusterRoot { @@ -19,6 +20,9 @@ pub enum RpcCustomError { message: String, }, SendTransactionIsNotSigned, + BlockNotAvailable { + slot: Slot, + }, } impl From for Error { @@ -56,6 +60,11 @@ impl From for Error { message: "Transaction is not signed".to_string(), data: None, }, + RpcCustomError::BlockNotAvailable { slot } => Self { + code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_4), + message: format!("Block not available for slot {}", slot,), + data: None, + }, } } } diff --git a/docs/src/apps/jsonrpc-api.md b/docs/src/apps/jsonrpc-api.md index 8b491e6881..5c2d35a627 100644 --- a/docs/src/apps/jsonrpc-api.md +++ b/docs/src/apps/jsonrpc-api.md @@ -241,7 +241,7 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "m ### getBlockTime -Returns the estimated production time of a block. +Returns the estimated production time of a confirmed block. Each validator reports their UTC time to the ledger on a regular interval by intermittently adding a timestamp to a Vote for a particular block. A requested @@ -259,8 +259,8 @@ query a node that is built from genesis and retains the entire ledger. #### Results: -- `` - block has not yet been produced -- `` - estimated production time, as Unix timestamp (seconds since the Unix epoch) +* `` - estimated production time, as Unix timestamp (seconds since the Unix epoch) +* `` - timestamp is not available for this block #### Example: