Skip to content

Commit

Permalink
Handle already discarded packets in discard_excess_packets (#22594)
Browse files Browse the repository at this point in the history
(cherry picked from commit 38b02bb)
  • Loading branch information
sakridge committed Jan 21, 2022
1 parent edf1954 commit 354975d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/src/sigverify_stage.rs
Expand Up @@ -194,6 +194,7 @@ impl SigVerifyStage {
.iter_mut()
.rev()
.flat_map(|batch| batch.packets.iter_mut().rev())
.filter(|packet| !packet.meta.discard())
.map(|packet| (packet.meta.addr, packet))
.into_group_map();
// Allocate max_packets evenly across addresses.
Expand Down Expand Up @@ -369,12 +370,15 @@ mod tests {
solana_logger::setup();
let mut batch = PacketBatch::default();
batch.packets.resize(10, Packet::default());
batch.packets[3].meta.addr = [1u16; 8];
batch.packets[3].meta.addr = std::net::IpAddr::from([1u16; 8]);
batch.packets[3].meta.set_discard(true);
batch.packets[4].meta.addr = std::net::IpAddr::from([2u16; 8]);
let mut batches = vec![batch];
let max = 3;
SigVerifyStage::discard_excess_packets(&mut batches, max);
assert_eq!(count_non_discard(&batches), max);
assert!(!batches[0].packets[0].meta.discard);
assert!(!batches[0].packets[3].meta.discard);
assert!(!batches[0].packets[0].meta.discard());
assert!(batches[0].packets[3].meta.discard());
assert!(!batches[0].packets[4].meta.discard());
}
}

0 comments on commit 354975d

Please sign in to comment.