Skip to content

Commit

Permalink
Make get_blocks starting-slots consistent with other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Apr 27, 2022
1 parent 2b52211 commit 73adca1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,10 @@ impl JsonRpcRequestProcessor {
)));
}

let lowest_blockstore_slot = self.blockstore.lowest_slot();
let lowest_blockstore_slot = self
.blockstore
.get_first_available_block()
.unwrap_or_default();
if start_slot < lowest_blockstore_slot {
// If the starting slot is lower than what's available in blockstore assume the entire
// [start_slot..end_slot] can be fetched from BigTable. This range should not ever run
Expand Down Expand Up @@ -1188,7 +1191,10 @@ impl JsonRpcRequestProcessor {
)));
}

let lowest_blockstore_slot = self.blockstore.lowest_slot();
let lowest_blockstore_slot = self
.blockstore
.get_first_available_block()
.unwrap_or_default();

if start_slot < lowest_blockstore_slot {
// If the starting slot is lower than what's available in blockstore assume the entire
Expand Down Expand Up @@ -6677,6 +6683,7 @@ pub mod tests {
#[test]
fn test_get_blocks() {
let rpc = RpcHandler::start();
let _ = rpc.create_test_transactions_and_populate_blockstore();
rpc.add_roots_to_blockstore(vec![0, 1, 3, 4, 8]);
rpc.block_commitment_cache
.write()
Expand All @@ -6685,19 +6692,19 @@ pub mod tests {

let request = create_test_request("getBlocks", Some(json!([0u64])));
let result: Vec<Slot> = parse_success_result(rpc.handle_request_sync(request));
assert_eq!(result, vec![1, 3, 4, 8]);
assert_eq!(result, vec![0, 1, 3, 4, 8]);

let request = create_test_request("getBlocks", Some(json!([2u64])));
let result: Vec<Slot> = parse_success_result(rpc.handle_request_sync(request));
assert_eq!(result, vec![3, 4, 8]);

let request = create_test_request("getBlocks", Some(json!([0u64, 4u64])));
let result: Vec<Slot> = parse_success_result(rpc.handle_request_sync(request));
assert_eq!(result, vec![1, 3, 4]);
assert_eq!(result, vec![0, 1, 3, 4]);

let request = create_test_request("getBlocks", Some(json!([0u64, 7u64])));
let result: Vec<Slot> = parse_success_result(rpc.handle_request_sync(request));
assert_eq!(result, vec![1, 3, 4]);
assert_eq!(result, vec![0, 1, 3, 4]);

let request = create_test_request("getBlocks", Some(json!([9u64, 11u64])));
let result: Vec<Slot> = parse_success_result(rpc.handle_request_sync(request));
Expand All @@ -6713,7 +6720,7 @@ pub mod tests {
Some(json!([0u64, MAX_GET_CONFIRMED_BLOCKS_RANGE])),
);
let result: Vec<Slot> = parse_success_result(rpc.handle_request_sync(request));
assert_eq!(result, vec![1, 3, 4, 8]);
assert_eq!(result, vec![0, 1, 3, 4, 8]);

let request = create_test_request(
"getBlocks",
Expand Down

0 comments on commit 73adca1

Please sign in to comment.