Add ancestor iterator to lib.rs (#10813)

Co-authored-by: Carl <carl@solana.com>
This commit is contained in:
carllin 2020-06-25 16:39:55 -07:00 committed by GitHub
parent 62b873b054
commit 0fde0d7379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -25,7 +25,7 @@ impl<'a> Iterator for AncestorIterator<'a> {
type Item = Slot; type Item = Slot;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
let current = self.current.clone(); let current = self.current;
current.map(|slot| { current.map(|slot| {
if slot != 0 { if slot != 0 {
self.current = self.blockstore.meta(slot).unwrap().and_then(|slot_meta| { self.current = self.blockstore.meta(slot).unwrap().and_then(|slot_meta| {
@ -101,9 +101,7 @@ mod tests {
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 4, fork_point, fork_hash); fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 4, fork_point, fork_hash);
// Test correctness // Test correctness
assert!(AncestorIterator::new(0, &blockstore) assert!(AncestorIterator::new(0, &blockstore).next().is_none());
.collect::<Vec<Slot>>()
.is_empty());
assert_eq!( assert_eq!(
AncestorIterator::new(4, &blockstore).collect::<Vec<Slot>>(), AncestorIterator::new(4, &blockstore).collect::<Vec<Slot>>(),
vec![1, 0] vec![1, 0]

View File

@ -2,6 +2,7 @@ pub mod bank_forks_utils;
pub mod block_error; pub mod block_error;
#[macro_use] #[macro_use]
pub mod blockstore; pub mod blockstore;
pub mod ancestor_iterator;
pub mod blockstore_db; pub mod blockstore_db;
pub mod blockstore_meta; pub mod blockstore_meta;
pub mod blockstore_processor; pub mod blockstore_processor;