Reduce repeated discard_shreds checks (#26329)

This commit is contained in:
steviez 2022-06-30 14:45:10 -05:00 committed by GitHub
parent d964774fde
commit 54cd31e9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -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();

View File

@ -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 => {