Skip to content

Commit

Permalink
Add some comments on payload resize
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Czabaniuk committed Apr 23, 2021
1 parent f814268 commit 7becc7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,8 @@ impl Blockstore {
// We don't want only a subset of these changes going through.
write_batch.put_bytes::<cf::ShredData>(
(slot, index),
// Payload will be padded out to SHRED_PAYLOAD_SIZE
// But only need to store the bytes within data_header.size
&shred.payload[..shred.data_header.size as usize],
)?;
data_index.set_present(index, true);
Expand Down Expand Up @@ -1448,6 +1450,9 @@ impl Blockstore {
use crate::shred::SHRED_PAYLOAD_SIZE;
self.data_shred_cf.get_bytes((slot, index)).map(|data| {
data.map(|mut d| {
// Only data_header.size bytes stored in the blockstore so
// pad the payload out to SHRED_PAYLOAD_SIZE so that the
// erasure recovery works properly.
d.resize(cmp::max(d.len(), SHRED_PAYLOAD_SIZE), 0);
d
})
Expand Down
3 changes: 1 addition & 2 deletions ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,10 @@ impl Shred {
Self::deserialize_obj(&mut start, SIZE_OF_COMMON_SHRED_HEADER, &payload)?;

let slot = common_header.slot;
let expected_data_size = SHRED_PAYLOAD_SIZE;
// Shreds should be padded out to SHRED_PAYLOAD_SIZE
// so that erasure generation/recovery works correctly
// But only the data_header.size is stored in blockstore.
payload.resize(expected_data_size, 0);
payload.resize(SHRED_PAYLOAD_SIZE, 0);
let shred = if common_header.shred_type == ShredType(CODING_SHRED) {
let coding_header: CodingShredHeader =
Self::deserialize_obj(&mut start, SIZE_OF_CODING_SHRED_HEADER, &payload)?;
Expand Down

0 comments on commit 7becc7d

Please sign in to comment.