Skip to content

Commit

Permalink
purge duplicated bank prioritization fee from cache (solana-labs#33062)
Browse files Browse the repository at this point in the history
* purge duplicated bank prioritization fee from cache

* add test for purge dup bank

* Added metrics counts to monitor anomalies

* fix a flaky test
  • Loading branch information
tao-stones authored Sep 11, 2023
1 parent 527a4bb commit 4f4ce69
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 108 deletions.
2 changes: 1 addition & 1 deletion rpc/src/optimistically_confirmed_bank_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl OptimisticallyConfirmedBankTracker {
);

// finalize block's minimum prioritization fee cache for this bank
prioritization_fee_cache.finalize_priority_fee(bank.slot());
prioritization_fee_cache.finalize_priority_fee(bank.slot(), bank.bank_id());
}
} else if bank.slot() > bank_forks.read().unwrap().root() {
pending_optimistically_confirmed_banks.insert(bank.slot());
Expand Down
6 changes: 4 additions & 2 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8658,6 +8658,7 @@ pub mod tests {
0
);
let slot0 = rpc.working_bank().slot();
let bank0_id = rpc.working_bank().bank_id();
let account0 = Pubkey::new_unique();
let account1 = Pubkey::new_unique();
let account2 = Pubkey::new_unique();
Expand All @@ -8677,7 +8678,7 @@ pub mod tests {
];
rpc.update_prioritization_fee_cache(transactions);
let cache = rpc.get_prioritization_fee_cache();
cache.finalize_priority_fee(slot0);
cache.finalize_priority_fee(slot0, bank0_id);
wait_for_cache_blocks(cache, 1);

let request = create_test_request("getRecentPrioritizationFees", None);
Expand Down Expand Up @@ -8721,6 +8722,7 @@ pub mod tests {

rpc.advance_bank_to_confirmed_slot(1);
let slot1 = rpc.working_bank().slot();
let bank1_id = rpc.working_bank().bank_id();
let price1 = 11;
let transactions = vec![
Transaction::new_unsigned(Message::new(
Expand All @@ -8737,7 +8739,7 @@ pub mod tests {
];
rpc.update_prioritization_fee_cache(transactions);
let cache = rpc.get_prioritization_fee_cache();
cache.finalize_priority_fee(slot1);
cache.finalize_priority_fee(slot1, bank1_id);
wait_for_cache_blocks(cache, 2);

let request = create_test_request("getRecentPrioritizationFees", None);
Expand Down
48 changes: 33 additions & 15 deletions runtime/src/prioritization_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct PrioritizationFeeMetrics {
// Count of transactions that have zero prioritization fee.
non_prioritized_transactions_count: u64,

// Count of attempted update on finalized PrioritizationFee
attempted_update_on_finalized_fee_count: u64,

// Total prioritization fees included in this slot.
total_prioritization_fee: u64,

Expand All @@ -41,6 +44,10 @@ impl PrioritizationFeeMetrics {
saturating_add_assign!(self.total_update_elapsed_us, val);
}

fn increment_attempted_update_on_finalized_fee_count(&mut self, val: u64) {
saturating_add_assign!(self.attempted_update_on_finalized_fee_count, val);
}

fn update_prioritization_fee(&mut self, fee: u64) {
if fee == 0 {
saturating_add_assign!(self.non_prioritized_transactions_count, 1);
Expand Down Expand Up @@ -82,6 +89,11 @@ impl PrioritizationFeeMetrics {
self.non_prioritized_transactions_count as i64,
i64
),
(
"attempted_update_on_finalized_fee_count",
self.attempted_update_on_finalized_fee_count as i64,
i64
),
(
"total_prioritization_fee",
self.total_prioritization_fee as i64,
Expand All @@ -106,6 +118,7 @@ impl PrioritizationFeeMetrics {
}
}

#[derive(Debug)]
pub enum PrioritizationFeeError {
// Not able to get account locks from sanitized transaction, which is required to update block
// minimum fees.
Expand Down Expand Up @@ -159,22 +172,27 @@ impl PrioritizationFee {
) -> Result<(), PrioritizationFeeError> {
let (_, update_time) = measure!(
{
if transaction_fee < self.min_transaction_fee {
self.min_transaction_fee = transaction_fee;
if !self.is_finalized {
if transaction_fee < self.min_transaction_fee {
self.min_transaction_fee = transaction_fee;
}

for write_account in writable_accounts.iter() {
self.min_writable_account_fees
.entry(*write_account)
.and_modify(|write_lock_fee| {
*write_lock_fee = std::cmp::min(*write_lock_fee, transaction_fee)
})
.or_insert(transaction_fee);
}

self.metrics
.accumulate_total_prioritization_fee(transaction_fee);
self.metrics.update_prioritization_fee(transaction_fee);
} else {
self.metrics
.increment_attempted_update_on_finalized_fee_count(1);
}

for write_account in writable_accounts.iter() {
self.min_writable_account_fees
.entry(*write_account)
.and_modify(|write_lock_fee| {
*write_lock_fee = std::cmp::min(*write_lock_fee, transaction_fee)
})
.or_insert(transaction_fee);
}

self.metrics
.accumulate_total_prioritization_fee(transaction_fee);
self.metrics.update_prioritization_fee(transaction_fee);
},
"update_time",
);
Expand Down
Loading

0 comments on commit 4f4ce69

Please sign in to comment.