diff --git a/ledger/src/blocktree.rs b/ledger/src/blocktree.rs index e4774d26edded4..ef11af46fdb850 100644 --- a/ledger/src/blocktree.rs +++ b/ledger/src/blocktree.rs @@ -865,7 +865,7 @@ impl Blocktree { fn should_insert_coding_shred( shred: &Shred, - coding_index: &CodingIndex, + coding_index: &ShredIndex, last_root: &RwLock, ) -> bool { let slot = shred.slot(); @@ -907,7 +907,7 @@ impl Blocktree { fn should_insert_data_shred( shred: &Shred, slot_meta: &SlotMeta, - data_index: &DataIndex, + data_index: &ShredIndex, last_root: &RwLock, ) -> bool { let shred_index = u64::from(shred.index()); @@ -965,7 +965,7 @@ impl Blocktree { fn insert_data_shred( &self, slot_meta: &mut SlotMeta, - data_index: &mut DataIndex, + data_index: &mut ShredIndex, shred: &Shred, write_batch: &mut WriteBatch, ) -> Result<()> { @@ -5117,7 +5117,7 @@ pub mod tests { } // Test the data index doesn't have anything extra - let num_data_in_index = index.data().num_data(); + let num_data_in_index = index.data().num_shreds(); assert_eq!(num_data_in_index, num_data); // Test the set of coding shreds in the index and in the coding column @@ -5130,7 +5130,7 @@ pub mod tests { } // Test the data index doesn't have anything extra - let num_coding_in_index = index.coding().num_coding(); + let num_coding_in_index = index.coding().num_shreds(); assert_eq!(num_coding_in_index, num_coding); } } diff --git a/ledger/src/blocktree_meta.rs b/ledger/src/blocktree_meta.rs index 8105b0d4ddde92..00c93d248e6532 100644 --- a/ledger/src/blocktree_meta.rs +++ b/ledger/src/blocktree_meta.rs @@ -37,20 +37,13 @@ pub struct SlotMeta { /// Index recording presence/absence of shreds pub struct Index { pub slot: Slot, - data: DataIndex, - coding: CodingIndex, + data: ShredIndex, + coding: ShredIndex, } #[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] -pub struct DataIndex { - /// Map representing presence/absence of data shreds - index: BTreeSet, -} - -#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] -/// Erasure coding information -pub struct CodingIndex { - /// Map from set index, to hashmap from shred index to presence bool +pub struct ShredIndex { + /// Map representing presence/absence of shreds index: BTreeSet, } @@ -78,56 +71,28 @@ impl Index { pub(crate) fn new(slot: Slot) -> Self { Index { slot, - data: DataIndex::default(), - coding: CodingIndex::default(), + data: ShredIndex::default(), + coding: ShredIndex::default(), } } - pub fn data(&self) -> &DataIndex { + pub fn data(&self) -> &ShredIndex { &self.data } - pub fn coding(&self) -> &CodingIndex { + pub fn coding(&self) -> &ShredIndex { &self.coding } - pub fn data_mut(&mut self) -> &mut DataIndex { + pub fn data_mut(&mut self) -> &mut ShredIndex { &mut self.data } - pub fn coding_mut(&mut self) -> &mut CodingIndex { + pub fn coding_mut(&mut self) -> &mut ShredIndex { &mut self.coding } } -impl CodingIndex { - pub fn num_coding(&self) -> usize { - self.index.len() - } - - pub fn present_in_bounds(&self, bounds: impl RangeBounds) -> usize { - self.index.range(bounds).count() - } - - pub fn is_present(&self, index: u64) -> bool { - self.index.contains(&index) - } - - pub fn set_present(&mut self, index: u64, presence: bool) { - if presence { - self.index.insert(index); - } else { - self.index.remove(&index); - } - } - - pub fn set_many_present(&mut self, presence: impl IntoIterator) { - for (idx, present) in presence.into_iter() { - self.set_present(idx, present); - } - } -} - -impl DataIndex { - pub fn num_data(&self) -> usize { +impl ShredIndex { + pub fn num_shreds(&self) -> usize { self.index.len() }