Skip to content

Commit

Permalink
Make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
utsl42 authored and Steven Czabaniuk committed Apr 23, 2021
1 parent e37d33b commit f814268
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 11 additions & 6 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,9 @@ impl Blockstore {
pub fn get_data_shred(&self, slot: Slot, index: u64) -> Result<Option<Vec<u8>>> {
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
})
})
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f814268

Please sign in to comment.