Use Blockstore lowest_slot to start root iterator (#9738)
This commit is contained in:
@ -36,6 +36,7 @@ use solana_transaction_status::{
|
|||||||
};
|
};
|
||||||
use solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY};
|
use solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY};
|
||||||
use std::{
|
use std::{
|
||||||
|
cmp::max,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
net::{SocketAddr, UdpSocket},
|
net::{SocketAddr, UdpSocket},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
@ -380,7 +381,7 @@ impl JsonRpcRequestProcessor {
|
|||||||
}
|
}
|
||||||
Ok(self
|
Ok(self
|
||||||
.blockstore
|
.blockstore
|
||||||
.rooted_slot_iterator(start_slot)
|
.rooted_slot_iterator(max(start_slot, self.blockstore.lowest_slot()))
|
||||||
.map_err(|_| Error::internal_error())?
|
.map_err(|_| Error::internal_error())?
|
||||||
.filter(|&slot| slot <= end_slot)
|
.filter(|&slot| slot <= end_slot)
|
||||||
.collect())
|
.collect())
|
||||||
@ -2657,7 +2658,7 @@ pub mod tests {
|
|||||||
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, roots);
|
assert_eq!(confirmed_blocks, roots[1..].to_vec());
|
||||||
|
|
||||||
let req =
|
let req =
|
||||||
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[2]}}"#);
|
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[2]}}"#);
|
||||||
@ -2673,7 +2674,7 @@ pub mod tests {
|
|||||||
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![0, 1, 3, 4]);
|
assert_eq!(confirmed_blocks, vec![1, 3, 4]);
|
||||||
|
|
||||||
let req =
|
let req =
|
||||||
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[0, 7]}}"#);
|
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[0, 7]}}"#);
|
||||||
@ -2681,7 +2682,7 @@ pub mod tests {
|
|||||||
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![0, 1, 3, 4]);
|
assert_eq!(confirmed_blocks, vec![1, 3, 4]);
|
||||||
|
|
||||||
let req =
|
let req =
|
||||||
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[9, 11]}}"#);
|
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmedBlocks","params":[9, 11]}}"#);
|
||||||
|
@ -1502,7 +1502,7 @@ impl Blockstore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_first_available_block(&self) -> Result<Slot> {
|
pub fn get_first_available_block(&self) -> Result<Slot> {
|
||||||
let mut root_iterator = self.rooted_slot_iterator(0)?;
|
let mut root_iterator = self.rooted_slot_iterator(self.lowest_slot())?;
|
||||||
Ok(root_iterator.next().unwrap_or_default())
|
Ok(root_iterator.next().unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user