Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions core/src/packet_deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,23 @@ impl PacketDeserializer {
packet_count_upperbound: usize,
) -> Result<(Vec<PacketBatch>, Option<SigverifyTracerPacketStats>), RecvTimeoutError> {
let start = Instant::now();
let (mut packet_batches, mut aggregated_tracer_packet_stats_option) =

let (mut packet_batches_received_so_far, mut aggregated_tracer_packet_stats_option) =
self.packet_batch_receiver.recv_timeout(recv_timeout)?;
let mut num_packets_received = packet_batches_received_so_far
.iter()
.map(|batch| batch.len())
.sum::<usize>();

let mut num_packets_received: usize = packet_batches.iter().map(|batch| batch.len()).sum();
while let Ok((packet_batch, tracer_packet_stats_option)) =
while let Ok((packet_batches, tracer_packet_stats_option)) =
self.packet_batch_receiver.try_recv()
{
trace!("got more packet batches in packet deserializer");
let (packets_received, packet_count_overflowed) = num_packets_received
.overflowing_add(packet_batch.iter().map(|batch| batch.len()).sum());
packet_batches.extend(packet_batch);
num_packets_received += packet_batches
.iter()
.map(|batch| batch.len())
.sum::<usize>();
packet_batches_received_so_far.extend(packet_batches);

if let Some(tracer_packet_stats) = &tracer_packet_stats_option {
if let Some(aggregated_tracer_packet_stats) =
Expand All @@ -106,16 +112,15 @@ impl PacketDeserializer {
}
}

if start.elapsed() >= recv_timeout
|| packet_count_overflowed
|| packets_received >= packet_count_upperbound
{
if start.elapsed() >= recv_timeout || num_packets_received >= packet_count_upperbound {
break;
}
num_packets_received = packets_received;
}

Ok((packet_batches, aggregated_tracer_packet_stats_option))
Ok((
packet_batches_received_so_far,
aggregated_tracer_packet_stats_option,
))
}

fn generate_packet_indexes(packet_batch: &PacketBatch) -> Vec<usize> {
Expand Down