getConfirmedBlocks now has an upper limit on slot range
This commit is contained in:
@ -102,6 +102,7 @@ impl fmt::Display for RpcRequest {
|
|||||||
pub const NUM_LARGEST_ACCOUNTS: usize = 20;
|
pub const NUM_LARGEST_ACCOUNTS: usize = 20;
|
||||||
pub const MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS: usize = 256;
|
pub const MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS: usize = 256;
|
||||||
pub const MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE: u64 = 10_000;
|
pub const MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE: u64 = 10_000;
|
||||||
|
pub const MAX_GET_CONFIRMED_BLOCKS_RANGE: u64 = 500_000;
|
||||||
|
|
||||||
// Validators that are this number of slots behind are considered delinquent
|
// Validators that are this number of slots behind are considered delinquent
|
||||||
pub const DELINQUENT_VALIDATOR_SLOT_DISTANCE: u64 = 128;
|
pub const DELINQUENT_VALIDATOR_SLOT_DISTANCE: u64 = 128;
|
||||||
|
@ -13,7 +13,8 @@ use solana_client::{
|
|||||||
rpc_config::*,
|
rpc_config::*,
|
||||||
rpc_filter::RpcFilterType,
|
rpc_filter::RpcFilterType,
|
||||||
rpc_request::{
|
rpc_request::{
|
||||||
DELINQUENT_VALIDATOR_SLOT_DISTANCE, MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE,
|
DELINQUENT_VALIDATOR_SLOT_DISTANCE, MAX_GET_CONFIRMED_BLOCKS_RANGE,
|
||||||
|
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE,
|
||||||
MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, NUM_LARGEST_ACCOUNTS,
|
MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, NUM_LARGEST_ACCOUNTS,
|
||||||
},
|
},
|
||||||
rpc_response::Response as RpcResponse,
|
rpc_response::Response as RpcResponse,
|
||||||
@ -576,6 +577,12 @@ impl JsonRpcRequestProcessor {
|
|||||||
if end_slot < start_slot {
|
if end_slot < start_slot {
|
||||||
return Ok(vec![]);
|
return Ok(vec![]);
|
||||||
}
|
}
|
||||||
|
if end_slot - start_slot > MAX_GET_CONFIRMED_BLOCKS_RANGE {
|
||||||
|
return Err(Error::invalid_params(format!(
|
||||||
|
"Slot range too large; max {}",
|
||||||
|
MAX_GET_CONFIRMED_BLOCKS_RANGE
|
||||||
|
)));
|
||||||
|
}
|
||||||
Ok(self
|
Ok(self
|
||||||
.blockstore
|
.blockstore
|
||||||
.rooted_slot_iterator(max(start_slot, self.blockstore.lowest_slot()))
|
.rooted_slot_iterator(max(start_slot, self.blockstore.lowest_slot()))
|
||||||
@ -3552,11 +3559,37 @@ pub mod tests {
|
|||||||
assert_eq!(confirmed_blocks, vec![1, 3, 4]);
|
assert_eq!(confirmed_blocks, vec![1, 3, 4]);
|
||||||
|
|
||||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[9,11]}"#;
|
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[9,11]}"#;
|
||||||
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_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||||
assert_eq!(confirmed_blocks, Vec::<Slot>::new());
|
assert_eq!(confirmed_blocks, Vec::<Slot>::new());
|
||||||
|
|
||||||
|
block_commitment_cache
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_largest_confirmed_root(std::u64::MAX);
|
||||||
|
let req = format!(
|
||||||
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[0,{}]}}"#,
|
||||||
|
MAX_GET_CONFIRMED_BLOCKS_RANGE
|
||||||
|
);
|
||||||
|
let res = io.handle_request_sync(&req, meta.clone());
|
||||||
|
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||||
|
.expect("actual response deserialization");
|
||||||
|
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||||
|
assert_eq!(confirmed_blocks, vec![1, 3, 4, 8]);
|
||||||
|
|
||||||
|
let req = format!(
|
||||||
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[0,{}]}}"#,
|
||||||
|
MAX_GET_CONFIRMED_BLOCKS_RANGE + 1
|
||||||
|
);
|
||||||
|
let res = io.handle_request_sync(&req, meta);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
Some(
|
||||||
|
r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Slot range too large; max 500000"},"id":1}"#.to_string(),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -363,8 +363,9 @@ Returns a list of confirmed blocks
|
|||||||
#### Results:
|
#### Results:
|
||||||
|
|
||||||
The result field will be an array of u64 integers listing confirmed blocks
|
The result field will be an array of u64 integers listing confirmed blocks
|
||||||
between start_slot and either end_slot, if provided, or latest confirmed block,
|
between `start_slot` and either `end_slot`, if provided, or latest confirmed block,
|
||||||
inclusive.
|
inclusive. Max range allowed is 500,000 slots.
|
||||||
|
|
||||||
|
|
||||||
#### Example:
|
#### Example:
|
||||||
|
|
||||||
@ -378,7 +379,8 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"m
|
|||||||
|
|
||||||
### getConfirmedSignaturesForAddress
|
### getConfirmedSignaturesForAddress
|
||||||
|
|
||||||
Returns a list of all the confirmed signatures for transactions involving an address, within a specified Slot range. Max range allowed is 10_000 Slots.
|
Returns a list of all the confirmed signatures for transactions involving an
|
||||||
|
address, within a specified Slot range. Max range allowed is 10,000 Slots
|
||||||
|
|
||||||
#### Parameters:
|
#### Parameters:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user