diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index d5485ed5c..aefe623b7 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -1108,10 +1108,9 @@ impl Blockstore { } fn erasure_mismatch(shred1: &Shred, shred2: &Shred) -> bool { - // TODO should also compare first-coding-index once position field is - // populated across cluster. shred1.coding_header.num_coding_shreds != shred2.coding_header.num_coding_shreds || shred1.coding_header.num_data_shreds != shred2.coding_header.num_data_shreds + || shred1.first_coding_index() != shred2.first_coding_index() } #[allow(clippy::too_many_arguments)] @@ -6094,7 +6093,7 @@ pub mod tests { ); coding_shred.common_header.fec_set_index = std::u32::MAX - 1; coding_shred.coding_header.num_data_shreds = 2; - coding_shred.coding_header.num_coding_shreds = 3; + coding_shred.coding_header.num_coding_shreds = 4; coding_shred.coding_header.position = 1; coding_shred.common_header.index = std::u32::MAX - 1; assert!(!Blockstore::should_insert_coding_shred( diff --git a/ledger/src/blockstore_meta.rs b/ledger/src/blockstore_meta.rs index c6ebc6bcd..7544c7b24 100644 --- a/ledger/src/blockstore_meta.rs +++ b/ledger/src/blockstore_meta.rs @@ -257,10 +257,6 @@ impl ErasureMeta { None => return false, }; other.__unused_size = self.__unused_size; - // Ignore first_coding_index field for now to be backward compatible. - // TODO remove this once cluster is upgraded to always populate - // first_coding_index field. - other.first_coding_index = self.first_coding_index; self == &other } @@ -275,16 +271,7 @@ impl ErasureMeta { pub(crate) fn coding_shreds_indices(&self) -> Range { let num_coding = self.config.num_coding() as u64; - // first_coding_index == 0 may imply that the field is not populated. - // self.set_index to be backward compatible. - // TODO remove this once cluster is upgraded to always populate - // first_coding_index field. - let first_coding_index = if self.first_coding_index == 0 { - self.set_index - } else { - self.first_coding_index - }; - first_coding_index..first_coding_index + num_coding + self.first_coding_index..self.first_coding_index + num_coding } pub(crate) fn status(&self, index: &Index) -> ErasureMetaStatus { diff --git a/ledger/src/shred.rs b/ledger/src/shred.rs index 3e7b276ea..a82fd6392 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -504,9 +504,10 @@ impl Shred { pub(crate) fn first_coding_index(&self) -> Option { match self.shred_type() { ShredType::Data => None, - // TODO should be: self.index() - self.coding_header.position - // once position field is populated. - ShredType::Code => Some(self.fec_set_index()), + ShredType::Code => { + let position = u32::from(self.coding_header.position); + self.index().checked_sub(position) + } } } @@ -536,25 +537,25 @@ impl Shred { // Returns the block index within the erasure coding set. fn erasure_block_index(&self) -> Option { - let index = self.index().checked_sub(self.fec_set_index())?; - let index = usize::try_from(index).ok()?; match self.shred_type() { - ShredType::Data => Some(index), + ShredType::Data => { + let index = self.index().checked_sub(self.fec_set_index())?; + usize::try_from(index).ok() + } ShredType::Code => { - // TODO should use first_coding_index once position field is - // populated. // Assert that the last shred index in the erasure set does not // overshoot u32. self.fec_set_index().checked_add(u32::from( - self.coding_header - .num_data_shreds - .max(self.coding_header.num_coding_shreds) - .checked_sub(1)?, + self.coding_header.num_data_shreds.checked_sub(1)?, + ))?; + self.first_coding_index()?.checked_add(u32::from( + self.coding_header.num_coding_shreds.checked_sub(1)?, ))?; let num_data_shreds = usize::from(self.coding_header.num_data_shreds); let num_coding_shreds = usize::from(self.coding_header.num_coding_shreds); + let position = usize::from(self.coding_header.position); let fec_set_size = num_data_shreds.checked_add(num_coding_shreds)?; - let index = index.checked_add(num_data_shreds)?; + let index = position.checked_add(num_data_shreds)?; (index < fec_set_size).then(|| index) } }