Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 130c83b

Browse files
jstarryyihau
authored andcommitted
v1.18 - Add detailed metrics reporting for packet filtering (#1423)
* Add detailed metrics reporting for packet filtering * fix conflicts
1 parent 9a347ce commit 130c83b

File tree

7 files changed

+253
-99
lines changed

7 files changed

+253
-99
lines changed

core/src/banking_stage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ mod latest_unprocessed_votes;
6868
mod leader_slot_timing_metrics;
6969
mod multi_iterator_scanner;
7070
mod packet_deserializer;
71+
mod packet_filter;
7172
mod packet_receiver;
7273
mod read_write_account_set;
7374
#[allow(dead_code)]

core/src/banking_stage/immutable_deserialized_packet.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
solana_cost_model::block_cost_limits::BUILT_IN_INSTRUCTION_COSTS,
2+
super::packet_filter::PacketFilterFailure,
33
solana_perf::packet::Packet,
44
solana_runtime::transaction_priority_details::{
55
GetTransactionPriorityDetails, TransactionPriorityDetails,
@@ -9,7 +9,6 @@ use {
99
hash::Hash,
1010
message::Message,
1111
sanitize::SanitizeError,
12-
saturating_add_assign,
1312
short_vec::decode_shortu16_len,
1413
signature::Signature,
1514
transaction::{
@@ -36,6 +35,8 @@ pub enum DeserializedPacketError {
3635
PrioritizationFailure,
3736
#[error("vote transaction failure")]
3837
VoteTransactionError,
38+
#[error("Packet filter failure: {0}")]
39+
FailedFilter(#[from] PacketFilterFailure),
3940
}
4041

4142
#[derive(Debug, PartialEq, Eq)]
@@ -102,22 +103,6 @@ impl ImmutableDeserializedPacket {
102103
self.priority_details.clone()
103104
}
104105

105-
/// Returns true if the transaction's compute unit limit is at least as
106-
/// large as the sum of the static builtins' costs.
107-
/// This is a simple sanity check so the leader can discard transactions
108-
/// which are statically known to exceed the compute budget, and will
109-
/// result in no useful state-change.
110-
pub fn compute_unit_limit_above_static_builtins(&self) -> bool {
111-
let mut static_builtin_cost_sum: u64 = 0;
112-
for (program_id, _) in self.transaction.get_message().program_instructions_iter() {
113-
if let Some(ix_cost) = BUILT_IN_INSTRUCTION_COSTS.get(program_id) {
114-
saturating_add_assign!(static_builtin_cost_sum, *ix_cost);
115-
}
116-
}
117-
118-
self.compute_unit_limit() >= static_builtin_cost_sum
119-
}
120-
121106
// This function deserializes packets into transactions, computes the blake3 hash of transaction
122107
// messages, and verifies secp256k1 instructions.
123108
pub fn build_sanitized_transaction(
@@ -196,7 +181,11 @@ mod tests {
196181
// 1. compute_unit_limit under static builtins
197182
// 2. compute_unit_limit equal to static builtins
198183
// 3. compute_unit_limit above static builtins
199-
for (cu_limit, expectation) in [(250, false), (300, true), (350, true)] {
184+
for (cu_limit, expectation) in [
185+
(250, Err(PacketFilterFailure::InsufficientComputeLimit)),
186+
(300, Ok(())),
187+
(350, Ok(())),
188+
] {
200189
let keypair = Keypair::new();
201190
let bpf_program_id = Pubkey::new_unique();
202191
let ixs = vec![
@@ -213,7 +202,7 @@ mod tests {
213202
let packet = Packet::from_data(None, tx).unwrap();
214203
let deserialized_packet = ImmutableDeserializedPacket::new(packet).unwrap();
215204
assert_eq!(
216-
deserialized_packet.compute_unit_limit_above_static_builtins(),
205+
deserialized_packet.check_insufficent_compute_unit_limit(),
217206
expectation
218207
);
219208
}

core/src/banking_stage/leader_slot_metrics.rs

Lines changed: 82 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use {
22
super::{
33
leader_slot_timing_metrics::{LeaderExecuteAndCommitTimings, LeaderSlotTimingMetrics},
4+
packet_deserializer::PacketReceiverStats,
45
unprocessed_transaction_storage::InsertPacketBatchSummary,
56
},
67
solana_accounts_db::transaction_error_metrics::*,
@@ -64,6 +65,21 @@ struct LeaderSlotPacketCountMetrics {
6465
// total number of packets TPU received from sigverify that failed signature verification.
6566
newly_failed_sigverify_count: u64,
6667

68+
// total number of packets filtered due to sanitization failures during receiving from sigverify
69+
failed_sanitization_count: u64,
70+
71+
// total number of packets filtered due to prioritization failures during receiving from sigverify
72+
failed_prioritization_count: u64,
73+
74+
// total number of packets filtered due to insufficient compute limits during receiving from sigverify
75+
insufficient_compute_limit_count: u64,
76+
77+
// total number of packets filtered due to excessive precompile signatures during receiving from sigverify
78+
excessive_precompile_count: u64,
79+
80+
// total number of invalid vote packets filtered out during receiving from sigverify
81+
invalid_votes_count: u64,
82+
6783
// total number of dropped packet due to the thread's buffered packets capacity being reached.
6884
exceeded_buffer_limit_dropped_packets_count: u64,
6985

@@ -148,111 +164,124 @@ impl LeaderSlotPacketCountMetrics {
148164
fn report(&self, id: u32, slot: Slot) {
149165
datapoint_info!(
150166
"banking_stage-leader_slot_packet_counts",
151-
("id", id as i64, i64),
152-
("slot", slot as i64, i64),
167+
("id", id, i64),
168+
("slot", slot, i64),
169+
("total_new_valid_packets", self.total_new_valid_packets, i64),
153170
(
154-
"total_new_valid_packets",
155-
self.total_new_valid_packets as i64,
171+
"newly_failed_sigverify_count",
172+
self.newly_failed_sigverify_count,
156173
i64
157174
),
158175
(
159-
"newly_failed_sigverify_count",
160-
self.newly_failed_sigverify_count as i64,
176+
"failed_sanitization_count",
177+
self.failed_sanitization_count,
161178
i64
162179
),
180+
(
181+
"failed_prioritization_count",
182+
self.failed_prioritization_count,
183+
i64
184+
),
185+
(
186+
"insufficient_compute_limit_count",
187+
self.insufficient_compute_limit_count,
188+
i64
189+
),
190+
(
191+
"excessive_precompile_count",
192+
self.excessive_precompile_count,
193+
i64
194+
),
195+
("invalid_votes_count", self.invalid_votes_count, i64),
163196
(
164197
"exceeded_buffer_limit_dropped_packets_count",
165-
self.exceeded_buffer_limit_dropped_packets_count as i64,
198+
self.exceeded_buffer_limit_dropped_packets_count,
166199
i64
167200
),
168201
(
169202
"newly_buffered_packets_count",
170-
self.newly_buffered_packets_count as i64,
203+
self.newly_buffered_packets_count,
171204
i64
172205
),
173206
(
174207
"retryable_packets_filtered_count",
175-
self.retryable_packets_filtered_count as i64,
208+
self.retryable_packets_filtered_count,
176209
i64
177210
),
178211
(
179212
"transactions_attempted_execution_count",
180-
self.transactions_attempted_execution_count as i64,
213+
self.transactions_attempted_execution_count,
181214
i64
182215
),
183216
(
184217
"committed_transactions_count",
185-
self.committed_transactions_count as i64,
218+
self.committed_transactions_count,
186219
i64
187220
),
188221
(
189222
"committed_transactions_with_successful_result_count",
190-
self.committed_transactions_with_successful_result_count as i64,
223+
self.committed_transactions_with_successful_result_count,
191224
i64
192225
),
193226
(
194227
"retryable_errored_transaction_count",
195-
self.retryable_errored_transaction_count as i64,
196-
i64
197-
),
198-
(
199-
"retryable_packets_count",
200-
self.retryable_packets_count as i64,
228+
self.retryable_errored_transaction_count,
201229
i64
202230
),
231+
("retryable_packets_count", self.retryable_packets_count, i64),
203232
(
204233
"nonretryable_errored_transactions_count",
205-
self.nonretryable_errored_transactions_count as i64,
234+
self.nonretryable_errored_transactions_count,
206235
i64
207236
),
208237
(
209238
"executed_transactions_failed_commit_count",
210-
self.executed_transactions_failed_commit_count as i64,
239+
self.executed_transactions_failed_commit_count,
211240
i64
212241
),
213242
(
214243
"account_lock_throttled_transactions_count",
215-
self.account_lock_throttled_transactions_count as i64,
244+
self.account_lock_throttled_transactions_count,
216245
i64
217246
),
218247
(
219248
"account_locks_limit_throttled_transactions_count",
220-
self.account_locks_limit_throttled_transactions_count as i64,
249+
self.account_locks_limit_throttled_transactions_count,
221250
i64
222251
),
223252
(
224253
"cost_model_throttled_transactions_count",
225-
self.cost_model_throttled_transactions_count as i64,
254+
self.cost_model_throttled_transactions_count,
226255
i64
227256
),
228257
(
229258
"failed_forwarded_packets_count",
230-
self.failed_forwarded_packets_count as i64,
259+
self.failed_forwarded_packets_count,
231260
i64
232261
),
233262
(
234263
"successful_forwarded_packets_count",
235-
self.successful_forwarded_packets_count as i64,
264+
self.successful_forwarded_packets_count,
236265
i64
237266
),
238267
(
239268
"packet_batch_forward_failure_count",
240-
self.packet_batch_forward_failure_count as i64,
269+
self.packet_batch_forward_failure_count,
241270
i64
242271
),
243272
(
244273
"cleared_from_buffer_after_forward_count",
245-
self.cleared_from_buffer_after_forward_count as i64,
274+
self.cleared_from_buffer_after_forward_count,
246275
i64
247276
),
248277
(
249278
"forwardable_batches_count",
250-
self.forwardable_batches_count as i64,
279+
self.forwardable_batches_count,
251280
i64
252281
),
253282
(
254283
"end_of_slot_unprocessed_buffer_len",
255-
self.end_of_slot_unprocessed_buffer_len as i64,
284+
self.end_of_slot_unprocessed_buffer_len,
256285
i64
257286
),
258287
);
@@ -559,24 +588,34 @@ impl LeaderSlotMetricsTracker {
559588
}
560589

561590
// Packet inflow/outflow/processing metrics
562-
pub(crate) fn increment_total_new_valid_packets(&mut self, count: u64) {
591+
pub(crate) fn increment_received_packet_counts(&mut self, stats: PacketReceiverStats) {
563592
if let Some(leader_slot_metrics) = &mut self.leader_slot_metrics {
593+
let metrics = &mut leader_slot_metrics.packet_count_metrics;
594+
let PacketReceiverStats {
595+
passed_sigverify_count,
596+
failed_sigverify_count,
597+
invalid_vote_count,
598+
failed_prioritization_count,
599+
failed_sanitization_count,
600+
excessive_precompile_count,
601+
insufficient_compute_limit_count,
602+
} = stats;
603+
604+
saturating_add_assign!(metrics.total_new_valid_packets, passed_sigverify_count);
605+
saturating_add_assign!(metrics.newly_failed_sigverify_count, failed_sigverify_count);
606+
saturating_add_assign!(metrics.invalid_votes_count, invalid_vote_count);
564607
saturating_add_assign!(
565-
leader_slot_metrics
566-
.packet_count_metrics
567-
.total_new_valid_packets,
568-
count
608+
metrics.failed_prioritization_count,
609+
failed_prioritization_count
569610
);
570-
}
571-
}
572-
573-
pub(crate) fn increment_newly_failed_sigverify_count(&mut self, count: u64) {
574-
if let Some(leader_slot_metrics) = &mut self.leader_slot_metrics {
611+
saturating_add_assign!(metrics.failed_sanitization_count, failed_sanitization_count);
575612
saturating_add_assign!(
576-
leader_slot_metrics
577-
.packet_count_metrics
578-
.newly_failed_sigverify_count,
579-
count
613+
metrics.excessive_precompile_count,
614+
excessive_precompile_count
615+
);
616+
saturating_add_assign!(
617+
metrics.insufficient_compute_limit_count,
618+
insufficient_compute_limit_count
580619
);
581620
}
582621
}

0 commit comments

Comments
 (0)