From aa2751e61413a0e6decd201a5d1d5086d024599f Mon Sep 17 00:00:00 2001 From: sakridge Date: Thu, 10 Dec 2020 18:20:08 -0800 Subject: [PATCH] Check shred type in is_duplicate (#14050) --- core/src/window_service.rs | 9 ++++++--- ledger/src/blockstore.rs | 32 ++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/core/src/window_service.rs b/core/src/window_service.rs index c0156822e..a56eb7cbc 100644 --- a/core/src/window_service.rs +++ b/core/src/window_service.rs @@ -88,9 +88,12 @@ fn run_check_duplicate( ) -> Result<()> { let check_duplicate = |shred: Shred| -> Result<()> { if !blockstore.has_duplicate_shreds_in_slot(shred.slot()) { - if let Some(existing_shred_payload) = - blockstore.is_shred_duplicate(shred.slot(), shred.index(), &shred.payload) - { + if let Some(existing_shred_payload) = blockstore.is_shred_duplicate( + shred.slot(), + shred.index(), + &shred.payload, + shred.is_data(), + ) { blockstore.store_duplicate_slot( shred.slot(), existing_shred_payload, diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index f46219c26..6999ec0ea 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -2714,10 +2714,20 @@ impl Blockstore { // Returns the existing shred if `new_shred` is not equal to the existing shred at the // given slot and index as this implies the leader generated two different shreds with // the same slot and index - pub fn is_shred_duplicate(&self, slot: u64, index: u32, new_shred: &[u8]) -> Option> { - let res = self - .get_data_shred(slot, index as u64) - .expect("fetch from DuplicateSlots column family failed"); + pub fn is_shred_duplicate( + &self, + slot: u64, + index: u32, + new_shred: &[u8], + is_data: bool, + ) -> Option> { + let res = if is_data { + self.get_data_shred(slot, index as u64) + .expect("fetch from DuplicateSlots column family failed") + } else { + self.get_coding_shred(slot, index as u64) + .expect("fetch from DuplicateSlots column family failed") + }; res.map(|existing_shred| { if existing_shred != new_shred { @@ -7279,11 +7289,21 @@ pub mod tests { // Check if shreds are duplicated assert_eq!( - blockstore.is_shred_duplicate(slot, 0, &duplicate_shred.payload), + blockstore.is_shred_duplicate( + slot, + 0, + &duplicate_shred.payload, + duplicate_shred.is_data() + ), Some(shred.payload.clone()) ); assert!(blockstore - .is_shred_duplicate(slot, 0, &non_duplicate_shred.payload) + .is_shred_duplicate( + slot, + 0, + &non_duplicate_shred.payload, + duplicate_shred.is_data() + ) .is_none()); // Store a duplicate shred