Skip to content

Commit

Permalink
Add legacy deserialization blockstore test
Browse files Browse the repository at this point in the history
  • Loading branch information
cpubot committed Jan 23, 2025
1 parent a183635 commit 0ce665a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5364,7 +5364,7 @@ pub mod tests {
shred::{max_ticks_per_n_shreds, ShredFlags, LEGACY_SHRED_DATA_CAPACITY},
},
assert_matches::assert_matches,
bincode::serialize,
bincode::{serialize, Options},
crossbeam_channel::unbounded,
rand::{seq::SliceRandom, thread_rng},
solana_account_decoder::parse_token::UiTokenAmount,
Expand Down Expand Up @@ -5832,6 +5832,28 @@ pub mod tests {
test_insert_data_shreds_slots(true);
}

#[test]
fn test_index_fallback_deserialize() {
use rand::Rng;
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
let slot = rand::thread_rng().gen_range(0..100);
let bincode = bincode::DefaultOptions::new()
.reject_trailing_bytes()
.with_fixint_encoding();

let mut index_v1 = IndexV1::new(slot);
index_v1.data_mut().insert(10);

blockstore
.index_cf
.put_bytes(slot, &bincode.serialize(&index_v1).unwrap())
.unwrap();

let index_v2 = blockstore.index_cf.get(slot).unwrap().unwrap();
assert!(index_v2.data().contains(10))
}

/*
#[test]
pub fn test_iteration_order() {
Expand Down
27 changes: 27 additions & 0 deletions ledger/src/blockstore_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ mod serde_compat {
pub type Index = IndexV2;
pub type ShredIndex = ShredIndexV2;
pub type IndexFallback = IndexV1;
pub type ShredIndexFallback = ShredIndexV1;

#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
/// Index recording presence/absence of shreds
Expand Down Expand Up @@ -277,6 +278,32 @@ impl Index {
}
}

#[cfg(test)]
#[allow(unused)]
impl IndexFallback {
pub(crate) fn new(slot: Slot) -> Self {
Self {
slot,
data: ShredIndexFallback::default(),
coding: ShredIndexFallback::default(),
}
}

pub fn data(&self) -> &ShredIndexFallback {
&self.data
}
pub fn coding(&self) -> &ShredIndexFallback {
&self.coding
}

pub(crate) fn data_mut(&mut self) -> &mut ShredIndexFallback {
&mut self.data
}
pub(crate) fn coding_mut(&mut self) -> &mut ShredIndexFallback {
&mut self.coding
}
}

/// Superseded by [`ShredIndexV2`].
///
/// TODO: Remove this once new [`ShredIndexV2`] is fully rolled out
Expand Down

0 comments on commit 0ce665a

Please sign in to comment.