Skip to content

Commit

Permalink
remove SigVerifier::process_excess_packet,process_passed_sigverify_pa…
Browse files Browse the repository at this point in the history
…cket
  • Loading branch information
apfitzge committed Dec 12, 2024
1 parent dade2a7 commit 240f07d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
9 changes: 2 additions & 7 deletions core/src/sigverify_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
solana_measure::measure::Measure,
solana_perf::{
deduper::{self, Deduper},
packet::{Packet, PacketBatch},
packet::PacketBatch,
sigverify::{
count_discarded_packets, count_packets_in_batches, count_valid_packets, shrink_batches,
},
Expand Down Expand Up @@ -57,7 +57,6 @@ pub struct SigVerifyStage {
pub trait SigVerifier {
type SendType: std::fmt::Debug;
fn verify_batches(&self, batches: Vec<PacketBatch>, valid_packets: usize) -> Vec<PacketBatch>;
fn process_passed_sigverify_packet(&mut self, _packet: &Packet) {}
fn send_packets(&mut self, packet_batches: Vec<PacketBatch>) -> Result<(), Self::SendType>;
}

Expand Down Expand Up @@ -328,11 +327,7 @@ impl SigVerifyStage {

let mut verify_time = Measure::start("sigverify_batch_time");
let mut batches = verifier.verify_batches(batches, num_packets_to_verify);
let num_valid_packets = count_valid_packets(
&batches,
#[inline(always)]
|valid_packet| verifier.process_passed_sigverify_packet(valid_packet),
);
let num_valid_packets = count_valid_packets(&batches);
verify_time.stop();

// Post-shrink packet batches if many packets are discarded from sigverify
Expand Down
2 changes: 1 addition & 1 deletion perf/benches/shrink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ fn bench_shrink_count_packets(bencher: &mut Bencher) {
});

bencher.iter(|| {
let _ = sigverify::count_valid_packets(&batches, |_| ());
let _ = sigverify::count_valid_packets(&batches);
});
}
28 changes: 7 additions & 21 deletions perf/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,10 @@ pub fn count_packets_in_batches(batches: &[PacketBatch]) -> usize {
batches.iter().map(|batch| batch.len()).sum()
}

pub fn count_valid_packets(
batches: &[PacketBatch],
mut process_valid_packet: impl FnMut(&Packet),
) -> usize {
pub fn count_valid_packets(batches: &[PacketBatch]) -> usize {
batches
.iter()
.map(|batch| {
batch
.iter()
.filter(|p| {
let should_keep = !p.meta().discard();
if should_keep {
process_valid_packet(p);
}
should_keep
})
.count()
})
.map(|batch| batch.iter().filter(|p| !p.meta().discard()).count())
.sum()
}

Expand Down Expand Up @@ -1462,7 +1448,7 @@ mod tests {
});
start.sort_by(|a, b| a.data(..).cmp(&b.data(..)));

let packet_count = count_valid_packets(&batches, |_| ());
let packet_count = count_valid_packets(&batches);
shrink_batches(&mut batches);

//make sure all the non discarded packets are the same
Expand All @@ -1473,7 +1459,7 @@ mod tests {
.for_each(|p| end.push(p.clone()))
});
end.sort_by(|a, b| a.data(..).cmp(&b.data(..)));
let packet_count2 = count_valid_packets(&batches, |_| ());
let packet_count2 = count_valid_packets(&batches);
assert_eq!(packet_count, packet_count2);
assert_eq!(start, end);
}
Expand Down Expand Up @@ -1637,13 +1623,13 @@ mod tests {
PACKETS_PER_BATCH,
);
assert_eq!(batches.len(), BATCH_COUNT);
assert_eq!(count_valid_packets(&batches, |_| ()), PACKET_COUNT);
assert_eq!(count_valid_packets(&batches), PACKET_COUNT);
batches.iter_mut().enumerate().for_each(|(i, b)| {
b.iter_mut()
.enumerate()
.for_each(|(j, p)| p.meta_mut().set_discard(set_discard(i, j)))
});
assert_eq!(count_valid_packets(&batches, |_| ()), *expect_valid_packets);
assert_eq!(count_valid_packets(&batches), *expect_valid_packets);
debug!("show valid packets for case {}", i);
batches.iter_mut().enumerate().for_each(|(i, b)| {
b.iter_mut().enumerate().for_each(|(j, p)| {
Expand All @@ -1657,7 +1643,7 @@ mod tests {
let shrunken_batch_count = batches.len();
debug!("shrunk batch test {} count: {}", i, shrunken_batch_count);
assert_eq!(shrunken_batch_count, *expect_batch_count);
assert_eq!(count_valid_packets(&batches, |_| ()), *expect_valid_packets);
assert_eq!(count_valid_packets(&batches), *expect_valid_packets);
}
}
}

0 comments on commit 240f07d

Please sign in to comment.