Skip to content

Commit

Permalink
simplifies ServeRepair::run_orphan (#30908)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri authored Mar 27, 2023
1 parent 301a944 commit 49b8ea7
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions core/src/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,40 +1277,29 @@ impl ServeRepair {
recycler: &PacketBatchRecycler,
from_addr: &SocketAddr,
blockstore: &Blockstore,
mut slot: Slot,
slot: Slot,
max_responses: usize,
nonce: Nonce,
) -> Option<PacketBatch> {
let mut res =
PacketBatch::new_unpinned_with_recycler(recycler.clone(), max_responses, "run_orphan");
// Try to find the next "n" parent slots of the input slot
while let Ok(Some(meta)) = blockstore.meta(slot) {
if meta.received == 0 {
break;
}
let packet = repair_response::repair_response_packet(
let packets = std::iter::successors(blockstore.meta(slot).ok()?, |meta| {
blockstore.meta(meta.parent_slot?).ok()?
})
.map_while(|meta| {
repair_response::repair_response_packet(
blockstore,
slot,
meta.received - 1,
meta.slot,
meta.received.checked_sub(1u64)?,
from_addr,
nonce,
);
if let Some(packet) = packet {
res.push(packet);
} else {
break;
}

if meta.parent_slot.is_some() && res.len() < max_responses {
slot = meta.parent_slot.unwrap();
} else {
break;
}
}
if res.is_empty() {
return None;
)
});
for packet in packets.take(max_responses) {
res.push(packet);
}
Some(res)
(!res.is_empty()).then_some(res)
}

fn run_ancestor_hashes(
Expand Down

0 comments on commit 49b8ea7

Please sign in to comment.