From 54cd31e9e29185878e03593e2c932833f0c97e79 Mon Sep 17 00:00:00 2001 From: steviez Date: Thu, 30 Jun 2022 14:45:10 -0500 Subject: [PATCH] Reduce repeated discard_shreds checks (#26329) --- ledger/src/blockstore.rs | 15 +++++++++++++++ ledger/src/shred.rs | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 285193df1..64c4a5568 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -5890,6 +5890,21 @@ pub mod tests { } } + #[test] + fn test_verify_shred_slots() { + // verify_shred_slots(slot, parent, root) + assert!(verify_shred_slots(0, 0, 0)); + assert!(verify_shred_slots(2, 1, 0)); + assert!(verify_shred_slots(2, 1, 1)); + assert!(!verify_shred_slots(2, 3, 0)); + assert!(!verify_shred_slots(2, 2, 0)); + assert!(!verify_shred_slots(2, 3, 3)); + assert!(!verify_shred_slots(2, 2, 2)); + assert!(!verify_shred_slots(2, 1, 3)); + assert!(!verify_shred_slots(2, 3, 4)); + assert!(!verify_shred_slots(2, 2, 3)); + } + #[test] fn test_should_insert_data_shred() { solana_logger::setup(); diff --git a/ledger/src/shred.rs b/ledger/src/shred.rs index 446f8d5d4..656f324fb 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -707,7 +707,7 @@ pub fn should_discard_shred( }; let slot = match layout::get_slot(shred) { Some(slot) => { - if slot <= root || !slot_bounds.contains(&slot) { + if !slot_bounds.contains(&slot) { stats.slot_out_of_range += 1; return true; } @@ -735,6 +735,10 @@ pub fn should_discard_shred( stats.index_out_of_bounds += 1; return true; } + if slot <= root { + stats.slot_out_of_range += 1; + return true; + } false } ShredType::Data => { @@ -749,10 +753,6 @@ pub fn should_discard_shred( return true; } }; - if parent_offset == 0 && slot != 0 { - stats.bad_parent_offset += 1; - return true; - } let parent = match slot.checked_sub(Slot::from(parent_offset)) { Some(parent) => parent, None => {