Make RootedSlotsIterator for traversing slots on the root fork (#4361)

This commit is contained in:
carllin
2019-05-20 23:09:00 -07:00
committed by GitHub
parent ead15d294e
commit 1a77486f8e
3 changed files with 135 additions and 2 deletions

View File

@@ -32,9 +32,11 @@ use std::sync::mpsc::{sync_channel, Receiver, SyncSender, TrySendError};
use std::sync::{Arc, RwLock};
pub use self::meta::*;
pub use self::rooted_slot_iterator::*;
mod db;
mod meta;
mod rooted_slot_iterator;
macro_rules! db_imports {
{ $mod:ident, $db:ident, $db_path:expr } => {
@@ -74,6 +76,7 @@ pub enum BlocktreeError {
RocksDb(rocksdb::Error),
#[cfg(feature = "kvstore")]
KvsDb(kvstore::Error),
SlotNotRooted,
}
// ledger window
@@ -182,6 +185,10 @@ impl Blocktree {
self.orphans_cf.get(slot)
}
pub fn rooted_slot_iterator<'a>(&'a self, slot: u64) -> Result<RootedSlotIterator<'a>> {
RootedSlotIterator::new(slot, self)
}
pub fn slot_meta_iterator(&self, slot: u64) -> Result<impl Iterator<Item = (u64, SlotMeta)>> {
let meta_iter = self.db.iter::<cf::SlotMeta>(Some(slot))?;
Ok(meta_iter.map(|(slot, slot_meta_bytes)| {