* Add custom error for tx-history queries when node does not support (#17494)
(cherry picked from commit 6abe089740
)
# Conflicts:
# core/src/rpc.rs
* Fix conflicts
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
@ -16,6 +16,7 @@ pub const JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: i64 = -32007;
|
|||||||
pub const JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: i64 = -32008;
|
pub const JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: i64 = -32008;
|
||||||
pub const JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: i64 = -32009;
|
pub const JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: i64 = -32009;
|
||||||
pub const JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: i64 = -32010;
|
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 enum RpcCustomError {
|
pub enum RpcCustomError {
|
||||||
BlockCleanedUp {
|
BlockCleanedUp {
|
||||||
@ -44,6 +45,7 @@ pub enum RpcCustomError {
|
|||||||
KeyExcludedFromSecondaryIndex {
|
KeyExcludedFromSecondaryIndex {
|
||||||
index_key: String,
|
index_key: String,
|
||||||
},
|
},
|
||||||
|
TransactionHistoryNotAvailable,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@ -132,6 +134,13 @@ impl From<RpcCustomError> for Error {
|
|||||||
),
|
),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
|
RpcCustomError::TransactionHistoryNotAvailable => Self {
|
||||||
|
code: ErrorCode::ServerError(
|
||||||
|
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE,
|
||||||
|
),
|
||||||
|
message: "Transaction history is not available from this node".to_string(),
|
||||||
|
data: None,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -960,6 +960,8 @@ impl JsonRpcRequestProcessor {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Err(RpcCustomError::TransactionHistoryNotAvailable.into());
|
||||||
}
|
}
|
||||||
Err(RpcCustomError::BlockNotAvailable { slot }.into())
|
Err(RpcCustomError::BlockNotAvailable { slot }.into())
|
||||||
}
|
}
|
||||||
@ -1180,6 +1182,10 @@ impl JsonRpcRequestProcessor {
|
|||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
let bank = self.bank(Some(CommitmentConfig::processed()));
|
let bank = self.bank(Some(CommitmentConfig::processed()));
|
||||||
|
|
||||||
|
if search_transaction_history && !self.config.enable_rpc_transaction_history {
|
||||||
|
return Err(RpcCustomError::TransactionHistoryNotAvailable.into());
|
||||||
|
}
|
||||||
|
|
||||||
for signature in signatures {
|
for signature in signatures {
|
||||||
let status = if let Some(status) = self.get_transaction_status(signature, &bank) {
|
let status = if let Some(status) = self.get_transaction_status(signature, &bank) {
|
||||||
Some(status)
|
Some(status)
|
||||||
@ -1315,6 +1321,8 @@ impl JsonRpcRequestProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Err(RpcCustomError::TransactionHistoryNotAvailable.into());
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@ -1417,7 +1425,7 @@ impl JsonRpcRequestProcessor {
|
|||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
} else {
|
} else {
|
||||||
Ok(vec![])
|
Err(RpcCustomError::TransactionHistoryNotAvailable.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5187,7 +5195,7 @@ pub mod tests {
|
|||||||
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let RpcHandler {
|
let RpcHandler {
|
||||||
io,
|
io,
|
||||||
meta,
|
mut meta,
|
||||||
blockhash,
|
blockhash,
|
||||||
alice,
|
alice,
|
||||||
confirmed_block_signatures,
|
confirmed_block_signatures,
|
||||||
@ -5226,7 +5234,7 @@ pub mod tests {
|
|||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatuses","params":[["{}"]]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatuses","params":[["{}"]]}}"#,
|
||||||
confirmed_block_signatures[1]
|
confirmed_block_signatures[1]
|
||||||
);
|
);
|
||||||
let res = io.handle_request_sync(&req, meta);
|
let res = io.handle_request_sync(&req, meta.clone());
|
||||||
let expected_res: transaction::Result<()> = Err(TransactionError::InstructionError(
|
let expected_res: transaction::Result<()> = Err(TransactionError::InstructionError(
|
||||||
0,
|
0,
|
||||||
InstructionError::Custom(1),
|
InstructionError::Custom(1),
|
||||||
@ -5236,6 +5244,20 @@ pub mod tests {
|
|||||||
serde_json::from_value(json["result"]["value"][0].clone())
|
serde_json::from_value(json["result"]["value"][0].clone())
|
||||||
.expect("actual response deserialization");
|
.expect("actual response deserialization");
|
||||||
assert_eq!(expected_res, result.as_ref().unwrap().status);
|
assert_eq!(expected_res, result.as_ref().unwrap().status);
|
||||||
|
|
||||||
|
// disable rpc-tx-history, but attempt historical query
|
||||||
|
meta.config.enable_rpc_transaction_history = false;
|
||||||
|
let req = format!(
|
||||||
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatuses","params":[["{}"], {{"searchTransactionHistory": true}}]}}"#,
|
||||||
|
confirmed_block_signatures[1]
|
||||||
|
);
|
||||||
|
let res = io.handle_request_sync(&req, meta);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
Some(
|
||||||
|
r#"{"jsonrpc":"2.0","error":{"code":-32011,"message":"Transaction history is not available from this node"},"id":1}"#.to_string(),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -5812,7 +5834,7 @@ pub mod tests {
|
|||||||
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let RpcHandler {
|
let RpcHandler {
|
||||||
io,
|
io,
|
||||||
meta,
|
mut meta,
|
||||||
confirmed_block_signatures,
|
confirmed_block_signatures,
|
||||||
blockhash,
|
blockhash,
|
||||||
..
|
..
|
||||||
@ -5864,7 +5886,7 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlock","params":[0,"binary"]}"#;
|
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlock","params":[0,"binary"]}"#;
|
||||||
let res = io.handle_request_sync(&req, meta);
|
let res = io.handle_request_sync(&req, meta.clone());
|
||||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||||
.expect("actual response deserialization");
|
.expect("actual response deserialization");
|
||||||
let confirmed_block: Option<EncodedConfirmedBlock> =
|
let confirmed_block: Option<EncodedConfirmedBlock> =
|
||||||
@ -5905,6 +5927,17 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disable rpc-tx-history
|
||||||
|
meta.config.enable_rpc_transaction_history = false;
|
||||||
|
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlock","params":[0]}"#;
|
||||||
|
let res = io.handle_request_sync(&req, meta);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
Some(
|
||||||
|
r#"{"jsonrpc":"2.0","error":{"code":-32011,"message":"Transaction history is not available from this node"},"id":1}"#.to_string(),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Reference in New Issue
Block a user