From 7becc7d27a85ce6102e9cbce8b2c6e89bfaa69b2 Mon Sep 17 00:00:00 2001 From: Steven Czabaniuk Date: Mon, 19 Apr 2021 12:16:45 -0500 Subject: [PATCH] Add some comments on payload resize --- ledger/src/blockstore.rs | 5 +++++ ledger/src/shred.rs | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 90a54ad96acccf..016c6d7f962b9d 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -1416,6 +1416,8 @@ impl Blockstore { // We don't want only a subset of these changes going through. write_batch.put_bytes::( (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); @@ -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 }) diff --git a/ledger/src/shred.rs b/ledger/src/shred.rs index ce63ed7f13447d..57e8b0ba2f3ef9 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -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)?;