From 30aebf8c0fbb0ec85c9cff5a1379f7064caa0496 Mon Sep 17 00:00:00 2001 From: Tao Zhu Date: Mon, 19 Dec 2022 17:50:15 -0600 Subject: [PATCH 1/5] Add metrics for min/max priority fee per slot, and counters for fee/non-fee txs --- runtime/src/prioritization_fee.rs | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/runtime/src/prioritization_fee.rs b/runtime/src/prioritization_fee.rs index 3c225090278989..dcbca2930e5d9a 100644 --- a/runtime/src/prioritization_fee.rs +++ b/runtime/src/prioritization_fee.rs @@ -13,9 +13,21 @@ struct PrioritizationFeeMetrics { // fee for this slot. relevant_writable_accounts_count: u64, + // Count of transactions that have non-zero prioritization fee. + prioritized_transactions_count: u64, + + // Count of transactions that have no prioritization fee. + non_prioritized_transactions_count: u64, + // Total prioritization fees included in this slot. total_prioritization_fee: u64, + // The minimum prioritization fee in this slot. + min_prioritization_fee: Option, + + // The maximum prioritization fee in this slot. + max_prioritization_fee: u64, + // Accumulated time spent on tracking prioritization fee for each slot. total_update_elapsed_us: u64, } @@ -29,6 +41,22 @@ impl PrioritizationFeeMetrics { saturating_add_assign!(self.total_update_elapsed_us, val); } + fn update_prioritization_fee(&mut self, fee: u64) { + if fee == 0 { + saturating_add_assign!(self.non_prioritized_transactions_count, 1); + } else { + saturating_add_assign!(self.prioritized_transactions_count, 1); + } + + if fee > self.max_prioritization_fee { + self.max_prioritization_fee = fee; + } + + if self.min_prioritization_fee.is_none() || fee < self.min_prioritization_fee.unwrap() { + self.min_prioritization_fee = Some(fee); + } + } + fn report(&self, slot: Slot) { datapoint_info!( "block_prioritization_fee", @@ -43,11 +71,31 @@ impl PrioritizationFeeMetrics { self.relevant_writable_accounts_count as i64, i64 ), + ( + "prioritized_transactions_count", + self.prioritized_transactions_count as i64, + i64 + ), + ( + "non_prioritized_transactions_count", + self.non_prioritized_transactions_count as i64, + i64 + ), ( "total_prioritization_fee", self.total_prioritization_fee as i64, i64 ), + ( + "min_prioritization_fee", + self.min_prioritization_fee.unwrap_or(0) as i64, + i64 + ), + ( + "max_prioritization_fee", + self.max_prioritization_fee as i64, + i64 + ), ( "total_update_elapsed_us", self.total_update_elapsed_us as i64, @@ -125,6 +173,7 @@ impl PrioritizationFee { self.metrics .accumulate_total_prioritization_fee(transaction_fee); + self.metrics.update_prioritization_fee(transaction_fee); }, "update_time", ); From df93cf58885b48b521e62c41bc1613a7673faed9 Mon Sep 17 00:00:00 2001 From: Tao Zhu Date: Tue, 20 Dec 2022 10:50:09 -0600 Subject: [PATCH 2/5] get fee range of prioritized transactions only --- runtime/src/prioritization_fee.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/runtime/src/prioritization_fee.rs b/runtime/src/prioritization_fee.rs index dcbca2930e5d9a..54dd0c7b6506df 100644 --- a/runtime/src/prioritization_fee.rs +++ b/runtime/src/prioritization_fee.rs @@ -16,16 +16,16 @@ struct PrioritizationFeeMetrics { // Count of transactions that have non-zero prioritization fee. prioritized_transactions_count: u64, - // Count of transactions that have no prioritization fee. + // Count of transactions that have zero prioritization fee. non_prioritized_transactions_count: u64, // Total prioritization fees included in this slot. total_prioritization_fee: u64, - // The minimum prioritization fee in this slot. + // The minimum prioritization fee of prioritized transactions in this slot. min_prioritization_fee: Option, - // The maximum prioritization fee in this slot. + // The maximum prioritization fee of prioritized transactions in this slot. max_prioritization_fee: u64, // Accumulated time spent on tracking prioritization fee for each slot. @@ -44,10 +44,12 @@ impl PrioritizationFeeMetrics { fn update_prioritization_fee(&mut self, fee: u64) { if fee == 0 { saturating_add_assign!(self.non_prioritized_transactions_count, 1); - } else { - saturating_add_assign!(self.prioritized_transactions_count, 1); + return; } + // update prioritized transaction fee metrics. + saturating_add_assign!(self.prioritized_transactions_count, 1); + if fee > self.max_prioritization_fee { self.max_prioritization_fee = fee; } From 502b680dd830d779e316e98393762f169aa45266 Mon Sep 17 00:00:00 2001 From: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> Date: Wed, 21 Dec 2022 08:48:20 -0600 Subject: [PATCH 3/5] Update runtime/src/prioritization_fee.rs Co-authored-by: Trent Nelson --- runtime/src/prioritization_fee.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/src/prioritization_fee.rs b/runtime/src/prioritization_fee.rs index 54dd0c7b6506df..d6489910deb386 100644 --- a/runtime/src/prioritization_fee.rs +++ b/runtime/src/prioritization_fee.rs @@ -50,9 +50,8 @@ impl PrioritizationFeeMetrics { // update prioritized transaction fee metrics. saturating_add_assign!(self.prioritized_transactions_count, 1); - if fee > self.max_prioritization_fee { - self.max_prioritization_fee = fee; - } + self.max_prioritization_fee = + self.max_prioritization_fee.max(fee); if self.min_prioritization_fee.is_none() || fee < self.min_prioritization_fee.unwrap() { self.min_prioritization_fee = Some(fee); From c1b742c24b8f3be25e7e96cabebdb66fb2d0d6d6 Mon Sep 17 00:00:00 2001 From: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> Date: Wed, 21 Dec 2022 08:51:28 -0600 Subject: [PATCH 4/5] Update runtime/src/prioritization_fee.rs Co-authored-by: Trent Nelson --- runtime/src/prioritization_fee.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/runtime/src/prioritization_fee.rs b/runtime/src/prioritization_fee.rs index d6489910deb386..cb6bf8b40d7a48 100644 --- a/runtime/src/prioritization_fee.rs +++ b/runtime/src/prioritization_fee.rs @@ -53,10 +53,9 @@ impl PrioritizationFeeMetrics { self.max_prioritization_fee = self.max_prioritization_fee.max(fee); - if self.min_prioritization_fee.is_none() || fee < self.min_prioritization_fee.unwrap() { - self.min_prioritization_fee = Some(fee); - } - } + self.min_prioritization_fee = self + .min_prioritization_fee + .map_or(fee, |min_fee| min_fee.min(fee)); fn report(&self, slot: Slot) { datapoint_info!( From 9d72853800c69263f43eaf3405d84885158586cd Mon Sep 17 00:00:00 2001 From: Tao Zhu Date: Wed, 21 Dec 2022 08:58:11 -0600 Subject: [PATCH 5/5] fix format --- runtime/src/prioritization_fee.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/src/prioritization_fee.rs b/runtime/src/prioritization_fee.rs index cb6bf8b40d7a48..4b629111183ff8 100644 --- a/runtime/src/prioritization_fee.rs +++ b/runtime/src/prioritization_fee.rs @@ -50,12 +50,13 @@ impl PrioritizationFeeMetrics { // update prioritized transaction fee metrics. saturating_add_assign!(self.prioritized_transactions_count, 1); - self.max_prioritization_fee = - self.max_prioritization_fee.max(fee); + self.max_prioritization_fee = self.max_prioritization_fee.max(fee); - self.min_prioritization_fee = self - .min_prioritization_fee - .map_or(fee, |min_fee| min_fee.min(fee)); + self.min_prioritization_fee = Some( + self.min_prioritization_fee + .map_or(fee, |min_fee| min_fee.min(fee)), + ); + } fn report(&self, slot: Slot) { datapoint_info!(