getConfirmedBlocks now has an upper limit on slot range

(cherry picked from commit aef6bf272e)

# Conflicts:
#	core/src/rpc.rs
This commit is contained in:
Michael Vines
2020-07-06 08:37:04 -07:00
parent 82caa50781
commit 01987f8f89
3 changed files with 47 additions and 3 deletions

View File

@ -102,6 +102,7 @@ impl fmt::Display for RpcRequest {
pub const NUM_LARGEST_ACCOUNTS: usize = 20;
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_BLOCKS_RANGE: u64 = 500_000;
impl RpcRequest {
pub(crate) fn build_request_json(self, id: u64, params: Value) -> Value {

View File

@ -17,6 +17,10 @@ use jsonrpc_derive::rpc;
use solana_client::{
rpc_config::*,
rpc_request::{
<<<<<<< HEAD
=======
DELINQUENT_VALIDATOR_SLOT_DISTANCE, MAX_GET_CONFIRMED_BLOCKS_RANGE,
>>>>>>> aef6bf272... getConfirmedBlocks now has an upper limit on slot range
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE,
MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, NUM_LARGEST_ACCOUNTS,
},
@ -546,6 +550,12 @@ impl JsonRpcRequestProcessor {
if end_slot < start_slot {
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
.blockstore
.rooted_slot_iterator(max(start_slot, self.blockstore.lowest_slot()))
@ -3365,13 +3375,44 @@ pub mod tests {
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
assert_eq!(confirmed_blocks, vec![1, 3, 4]);
<<<<<<< HEAD
let req =
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[9, 11]}}"#);
let res = io.handle_request_sync(&req, meta);
=======
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[9,11]}"#;
let res = io.handle_request_sync(&req, meta.clone());
>>>>>>> aef6bf272... getConfirmedBlocks now has an upper limit on slot range
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::<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]

View File

@ -356,8 +356,9 @@ Returns a list of confirmed blocks
#### Results:
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,
inclusive.
between `start_slot` and either `end_slot`, if provided, or latest confirmed block,
inclusive. Max range allowed is 500,000 slots.
#### Example:
@ -371,7 +372,8 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"m
### 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: