2018-06-07 13:51:29 -07:00
|
|
|
//! The `sigverify` module provides digital signature verification functions.
|
|
|
|
//! By default, signatures are verified in parallel using all available CPU
|
2019-09-26 13:36:51 -07:00
|
|
|
//! cores. When perf-libs are available signature verification is offloaded
|
|
|
|
//! to the GPU.
|
2018-06-07 13:51:29 -07:00
|
|
|
//!
|
|
|
|
|
2019-11-06 10:52:30 -08:00
|
|
|
pub use solana_perf::sigverify::{
|
2021-12-11 06:44:15 -08:00
|
|
|
count_packets_in_batches, ed25519_verify_cpu, ed25519_verify_disabled, init, TxOffset,
|
2019-11-06 10:52:30 -08:00
|
|
|
};
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
2022-05-24 14:01:41 -07:00
|
|
|
crate::{
|
2023-01-25 04:54:38 -08:00
|
|
|
banking_trace::{BankingPacketBatch, BankingPacketSender},
|
2022-05-24 14:01:41 -07:00
|
|
|
sigverify_stage::{SigVerifier, SigVerifyServiceError},
|
|
|
|
},
|
2021-12-11 06:44:15 -08:00
|
|
|
solana_perf::{cuda_runtime::PinnedVec, packet::PacketBatch, recycler::Recycler, sigverify},
|
2022-06-08 22:25:37 -07:00
|
|
|
solana_sdk::{packet::Packet, saturating_add_assign},
|
2021-12-03 09:00:31 -08:00
|
|
|
};
|
2018-03-26 21:07:11 -07:00
|
|
|
|
2023-10-06 21:15:38 -07:00
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, AbiExample)]
|
2022-06-08 22:25:37 -07:00
|
|
|
pub struct SigverifyTracerPacketStats {
|
2022-05-24 14:01:41 -07:00
|
|
|
pub total_removed_before_sigverify_stage: usize,
|
|
|
|
pub total_tracer_packets_received_in_sigverify_stage: usize,
|
|
|
|
pub total_tracer_packets_deduped: usize,
|
|
|
|
pub total_excess_tracer_packets: usize,
|
|
|
|
pub total_tracker_packets_passed_sigverify: usize,
|
|
|
|
}
|
|
|
|
|
2022-06-08 22:25:37 -07:00
|
|
|
impl SigverifyTracerPacketStats {
|
|
|
|
pub fn is_default(&self) -> bool {
|
|
|
|
*self == SigverifyTracerPacketStats::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn aggregate(&mut self, other: &SigverifyTracerPacketStats) {
|
|
|
|
saturating_add_assign!(
|
|
|
|
self.total_removed_before_sigverify_stage,
|
|
|
|
other.total_removed_before_sigverify_stage
|
|
|
|
);
|
|
|
|
saturating_add_assign!(
|
|
|
|
self.total_tracer_packets_received_in_sigverify_stage,
|
|
|
|
other.total_tracer_packets_received_in_sigverify_stage
|
|
|
|
);
|
|
|
|
saturating_add_assign!(
|
|
|
|
self.total_tracer_packets_deduped,
|
|
|
|
other.total_tracer_packets_deduped
|
|
|
|
);
|
|
|
|
saturating_add_assign!(
|
|
|
|
self.total_excess_tracer_packets,
|
|
|
|
other.total_excess_tracer_packets
|
|
|
|
);
|
|
|
|
saturating_add_assign!(
|
|
|
|
self.total_tracker_packets_passed_sigverify,
|
|
|
|
other.total_tracker_packets_passed_sigverify
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-28 16:07:51 -07:00
|
|
|
pub struct TransactionSigVerifier {
|
2023-01-25 04:54:38 -08:00
|
|
|
packet_sender: BankingPacketSender,
|
2022-06-08 22:25:37 -07:00
|
|
|
tracer_packet_stats: SigverifyTracerPacketStats,
|
2019-10-28 16:07:51 -07:00
|
|
|
recycler: Recycler<TxOffset>,
|
|
|
|
recycler_out: Recycler<PinnedVec<u8>>,
|
2021-10-07 02:38:23 -07:00
|
|
|
reject_non_vote: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TransactionSigVerifier {
|
2023-01-25 04:54:38 -08:00
|
|
|
pub fn new_reject_non_vote(packet_sender: BankingPacketSender) -> Self {
|
2022-05-24 14:01:41 -07:00
|
|
|
let mut new_self = Self::new(packet_sender);
|
|
|
|
new_self.reject_non_vote = true;
|
|
|
|
new_self
|
2021-10-07 02:38:23 -07:00
|
|
|
}
|
2019-10-28 16:07:51 -07:00
|
|
|
|
2023-01-25 04:54:38 -08:00
|
|
|
pub fn new(packet_sender: BankingPacketSender) -> Self {
|
2019-10-28 16:07:51 -07:00
|
|
|
init();
|
|
|
|
Self {
|
2022-05-24 14:01:41 -07:00
|
|
|
packet_sender,
|
2022-06-08 22:25:37 -07:00
|
|
|
tracer_packet_stats: SigverifyTracerPacketStats::default(),
|
2021-04-07 08:15:38 -07:00
|
|
|
recycler: Recycler::warmed(50, 4096),
|
|
|
|
recycler_out: Recycler::warmed(50, 4096),
|
2021-10-07 02:38:23 -07:00
|
|
|
reject_non_vote: false,
|
2019-10-28 16:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SigVerifier for TransactionSigVerifier {
|
2022-05-24 14:01:41 -07:00
|
|
|
type SendType = BankingPacketBatch;
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn process_received_packet(
|
|
|
|
&mut self,
|
|
|
|
packet: &mut Packet,
|
|
|
|
removed_before_sigverify_stage: bool,
|
|
|
|
is_dup: bool,
|
|
|
|
) {
|
2022-05-30 16:41:54 -07:00
|
|
|
sigverify::check_for_tracer_packet(packet);
|
2022-12-06 03:54:49 -08:00
|
|
|
if packet.meta().is_tracer_packet() {
|
2022-05-24 14:01:41 -07:00
|
|
|
if removed_before_sigverify_stage {
|
|
|
|
self.tracer_packet_stats
|
|
|
|
.total_removed_before_sigverify_stage += 1;
|
|
|
|
} else {
|
|
|
|
self.tracer_packet_stats
|
|
|
|
.total_tracer_packets_received_in_sigverify_stage += 1;
|
|
|
|
if is_dup {
|
|
|
|
self.tracer_packet_stats.total_tracer_packets_deduped += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn process_excess_packet(&mut self, packet: &Packet) {
|
2022-12-06 03:54:49 -08:00
|
|
|
if packet.meta().is_tracer_packet() {
|
2022-05-24 14:01:41 -07:00
|
|
|
self.tracer_packet_stats.total_excess_tracer_packets += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn process_passed_sigverify_packet(&mut self, packet: &Packet) {
|
2022-12-06 03:54:49 -08:00
|
|
|
if packet.meta().is_tracer_packet() {
|
2022-05-24 14:01:41 -07:00
|
|
|
self.tracer_packet_stats
|
|
|
|
.total_tracker_packets_passed_sigverify += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn send_packets(
|
|
|
|
&mut self,
|
|
|
|
packet_batches: Vec<PacketBatch>,
|
|
|
|
) -> Result<(), SigVerifyServiceError<Self::SendType>> {
|
2022-07-11 04:33:15 -07:00
|
|
|
let tracer_packet_stats_to_send = std::mem::take(&mut self.tracer_packet_stats);
|
2023-01-25 04:54:38 -08:00
|
|
|
self.packet_sender.send(BankingPacketBatch::new((
|
|
|
|
packet_batches,
|
|
|
|
Some(tracer_packet_stats_to_send),
|
|
|
|
)))?;
|
2022-05-24 14:01:41 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-01-24 05:35:47 -08:00
|
|
|
fn verify_batches(
|
|
|
|
&self,
|
|
|
|
mut batches: Vec<PacketBatch>,
|
|
|
|
valid_packets: usize,
|
|
|
|
) -> Vec<PacketBatch> {
|
2021-10-07 02:38:23 -07:00
|
|
|
sigverify::ed25519_verify(
|
2021-12-11 06:44:15 -08:00
|
|
|
&mut batches,
|
2021-10-07 02:38:23 -07:00
|
|
|
&self.recycler,
|
|
|
|
&self.recycler_out,
|
|
|
|
self.reject_non_vote,
|
2022-01-24 05:35:47 -08:00
|
|
|
valid_packets,
|
2021-10-07 02:38:23 -07:00
|
|
|
);
|
2021-12-11 06:44:15 -08:00
|
|
|
batches
|
2019-10-28 16:07:51 -07:00
|
|
|
}
|
|
|
|
}
|