From f814268ca759f6694d6258379347d27dfcfd775b Mon Sep 17 00:00:00 2001 From: Nathan Hawkins Date: Tue, 30 Mar 2021 20:12:22 +0000 Subject: [PATCH] Make tests pass --- ledger/src/blockstore.rs | 17 +++++++++++------ ledger/src/shred.rs | 1 - 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 422c9a734e3d26..90a54ad96acccf 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -1447,9 +1447,9 @@ impl Blockstore { pub fn get_data_shred(&self, slot: Slot, index: u64) -> Result>> { use crate::shred::SHRED_PAYLOAD_SIZE; self.data_shred_cf.get_bytes((slot, index)).map(|data| { - data.and_then(|mut d| { + data.map(|mut d| { d.resize(cmp::max(d.len(), SHRED_PAYLOAD_SIZE), 0); - Some(d) + d }) }) } @@ -2829,9 +2829,14 @@ impl Blockstore { .expect("fetch from DuplicateSlots column family failed") }; - let new_shred = Shred::new_from_serialized_shred(new_shred_raw.to_vec()).unwrap(); + let mut payload = new_shred_raw.to_vec(); + payload.resize( + std::cmp::max(new_shred_raw.len(), crate::shred::SHRED_PAYLOAD_SIZE), + 0, + ); + let new_shred = Shred::new_from_serialized_shred(payload).unwrap(); res.map(|existing_shred| { - if existing_shred != new_shred.payload[..new_shred.data_header.size as usize] { + if existing_shred != new_shred.payload { Some(existing_shred) } else { None @@ -7505,7 +7510,7 @@ pub mod tests { .get_data_shred(s.slot(), s.index() as u64) .unwrap() .unwrap(), - buf[..s.data_header.size as usize] + buf ); } @@ -7736,7 +7741,7 @@ pub mod tests { &duplicate_shred.payload, duplicate_shred.is_data() ), - Some(shred.payload[..shred.data_header.size as usize].to_vec()) + Some(shred.payload.to_vec()) ); assert!(blockstore .is_shred_duplicate( diff --git a/ledger/src/shred.rs b/ledger/src/shred.rs index c43d2ac56205fb..ce63ed7f13447d 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -398,7 +398,6 @@ impl Shred { &data_header, ) .expect("Failed to write data header into shred buffer"); - assert!(data_header.size as usize >= start); } else if common_header.shred_type == ShredType(CODING_SHRED) { Self::serialize_obj_into( &mut start,