Simplify logic around MAX_ORPHAN_REPAIR_RESPONSES constant (#25032)

This commit is contained in:
steviez 2022-05-17 19:45:45 -06:00 committed by GitHub
parent 456e6711f0
commit b27125815a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -45,7 +45,7 @@ use {
type SlotHash = (Slot, Hash); type SlotHash = (Slot, Hash);
/// the number of slots to respond with when responding to `Orphan` requests /// the number of slots to respond with when responding to `Orphan` requests
pub const MAX_ORPHAN_REPAIR_RESPONSES: usize = 10; pub const MAX_ORPHAN_REPAIR_RESPONSES: usize = 11;
// Number of slots to cache their respective repair peers and sampling weights. // Number of slots to cache their respective repair peers and sampling weights.
pub(crate) const REPAIR_PEERS_CACHE_CAPACITY: usize = 128; pub(crate) const REPAIR_PEERS_CACHE_CAPACITY: usize = 128;
// Limit cache entries ttl in order to avoid re-using outdated data. // Limit cache entries ttl in order to avoid re-using outdated data.
@ -81,7 +81,7 @@ impl RequestResponse for ShredRepairType {
type Response = Shred; type Response = Shred;
fn num_expected_responses(&self) -> u32 { fn num_expected_responses(&self) -> u32 {
match self { match self {
ShredRepairType::Orphan(_) => (MAX_ORPHAN_REPAIR_RESPONSES + 1) as u32, // run_orphan uses <= MAX_ORPHAN_REPAIR_RESPONSES ShredRepairType::Orphan(_) => (MAX_ORPHAN_REPAIR_RESPONSES) as u32,
ShredRepairType::HighestShred(_, _) => 1, ShredRepairType::HighestShred(_, _) => 1,
ShredRepairType::Shred(_, _) => 1, ShredRepairType::Shred(_, _) => 1,
} }
@ -684,7 +684,8 @@ impl ServeRepair {
max_responses: usize, max_responses: usize,
nonce: Nonce, nonce: Nonce,
) -> Option<PacketBatch> { ) -> Option<PacketBatch> {
let mut res = PacketBatch::new_unpinned_with_recycler(recycler.clone(), 64, "run_orphan"); let mut res =
PacketBatch::new_unpinned_with_recycler(recycler.clone(), max_responses, "run_orphan");
if let Some(blockstore) = blockstore { if let Some(blockstore) = blockstore {
// Try to find the next "n" parent slots of the input slot // Try to find the next "n" parent slots of the input slot
while let Ok(Some(meta)) = blockstore.meta(slot) { while let Ok(Some(meta)) = blockstore.meta(slot) {
@ -703,7 +704,7 @@ impl ServeRepair {
} else { } else {
break; break;
} }
if meta.parent_slot.is_some() && res.packets.len() <= max_responses { if meta.parent_slot.is_some() && res.packets.len() < max_responses {
slot = meta.parent_slot.unwrap(); slot = meta.parent_slot.unwrap();
} else { } else {
break; break;