refactor: add function for deserializing and collecting packets - separate from channel receive (#27548)

This commit is contained in:
apfitzge 2022-09-06 15:54:31 -05:00 committed by GitHub
parent a2df1e95dc
commit a67d56f462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -45,26 +45,36 @@ impl PacketDeserializer {
) -> Result<ReceivePacketResults, RecvTimeoutError> {
let (packet_batches, sigverify_tracer_stats_option) =
self.receive_until(recv_timeout, capacity)?;
Ok(Self::deserialize_and_collect_packets(
&packet_batches,
sigverify_tracer_stats_option,
))
}
/// Deserialize packet batches and collect them into ReceivePacketResults
fn deserialize_and_collect_packets(
packet_batches: &[PacketBatch],
sigverify_tracer_stats_option: Option<SigverifyTracerPacketStats>,
) -> ReceivePacketResults {
let packet_count: usize = packet_batches.iter().map(|x| x.len()).sum();
let mut passed_sigverify_count: usize = 0;
let mut failed_sigverify_count: usize = 0;
let mut deserialized_packets = Vec::with_capacity(packet_count);
for packet_batch in packet_batches {
let packet_indexes = Self::generate_packet_indexes(&packet_batch);
let packet_indexes = Self::generate_packet_indexes(packet_batch);
passed_sigverify_count += packet_indexes.len();
failed_sigverify_count += packet_batch.len().saturating_sub(packet_indexes.len());
deserialized_packets.extend(Self::deserialize_packets(&packet_batch, &packet_indexes));
deserialized_packets.extend(Self::deserialize_packets(packet_batch, &packet_indexes));
}
Ok(ReceivePacketResults {
ReceivePacketResults {
deserialized_packets,
new_tracer_stats_option: sigverify_tracer_stats_option,
passed_sigverify_count: passed_sigverify_count as u64,
failed_sigverify_count: failed_sigverify_count as u64,
})
}
}
/// Receives packet batches from sigverify stage with a timeout, and aggregates tracer packet stats