Skip to content

Commit

Permalink
v1.14: improve prioritization fee cache accuracy (backport of #32692)…
Browse files Browse the repository at this point in the history
… (#32755)

improve prioritization fee cache accuracy (#32692)

* improve prioritization cache accuracy

(cherry picked from commit ef6af30)

fix merge conflict

Co-authored-by: Tao Zhu <[email protected]>
  • Loading branch information
mergify[bot] and tao-stones authored Aug 8, 2023
1 parent 2a1d3be commit 605da4a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
5 changes: 0 additions & 5 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,6 @@ impl ReplayStage {
ancestor_hashes_replay_update_sender: &AncestorHashesReplayUpdateSender,
block_metadata_notifier: Option<BlockMetadataNotifierLock>,
replay_result_vec: &[ReplaySlotFromBlockstore],
prioritization_fee_cache: &PrioritizationFeeCache,
purge_repair_slot_counter: &mut PurgeRepairSlotCounter,
) -> bool {
// TODO: See if processing of blockstore replay results and bank completion can be made thread safe.
Expand Down Expand Up @@ -2602,9 +2601,6 @@ impl ReplayStage {
warn!("cost_update_sender failed sending bank stats: {:?}", err)
});

// finalize block's minimum prioritization fee cache for this bank
prioritization_fee_cache.finalize_priority_fee(bank.slot());

assert_ne!(bank.hash(), Hash::default());
// Needs to be updated before `check_slot_agrees_with_cluster()` so that
// any updates in `check_slot_agrees_with_cluster()` on fork choice take
Expand Down Expand Up @@ -2816,7 +2812,6 @@ impl ReplayStage {
ancestor_hashes_replay_update_sender,
block_metadata_notifier,
&replay_result_vec,
prioritization_fee_cache,
purge_repair_slot_counter,
)
} else {
Expand Down
1 change: 1 addition & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ impl Validator {
optimistically_confirmed_bank,
rpc_subscriptions.clone(),
confirmed_bank_subscribers,
prioritization_fee_cache.clone(),
)),
Some(BankNotificationSenderConfig {
sender: bank_notification_sender,
Expand Down
24 changes: 23 additions & 1 deletion rpc/src/optimistically_confirmed_bank_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use {
crate::rpc_subscriptions::RpcSubscriptions,
crossbeam_channel::{Receiver, RecvTimeoutError, Sender},
solana_client::rpc_response::{SlotTransactionStats, SlotUpdate},
solana_runtime::{bank::Bank, bank_forks::BankForks},
solana_runtime::{
bank::Bank, bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache,
},
solana_sdk::{clock::Slot, timing::timestamp},
std::{
collections::HashSet,
Expand Down Expand Up @@ -92,6 +94,7 @@ impl OptimisticallyConfirmedBankTracker {
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
subscriptions: Arc<RpcSubscriptions>,
slot_notification_subscribers: Option<Arc<RwLock<Vec<SlotNotificationSender>>>>,
prioritization_fee_cache: Arc<PrioritizationFeeCache>,
) -> Self {
let exit_ = exit.clone();
let mut pending_optimistically_confirmed_banks = HashSet::new();
Expand All @@ -115,6 +118,7 @@ impl OptimisticallyConfirmedBankTracker {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&slot_notification_subscribers,
&prioritization_fee_cache,
) {
break;
}
Expand All @@ -123,6 +127,7 @@ impl OptimisticallyConfirmedBankTracker {
Self { thread_hdl }
}

#[allow(clippy::too_many_arguments)]
fn recv_notification(
receiver: &Receiver<BankNotification>,
bank_forks: &Arc<RwLock<BankForks>>,
Expand All @@ -133,6 +138,7 @@ impl OptimisticallyConfirmedBankTracker {
highest_confirmed_slot: &mut Slot,
newest_root_slot: &mut Slot,
slot_notification_subscribers: &Option<Arc<RwLock<Vec<SlotNotificationSender>>>>,
prioritization_fee_cache: &PrioritizationFeeCache,
) -> Result<(), RecvTimeoutError> {
let notification = receiver.recv_timeout(Duration::from_secs(1))?;
Self::process_notification(
Expand All @@ -145,6 +151,7 @@ impl OptimisticallyConfirmedBankTracker {
highest_confirmed_slot,
newest_root_slot,
slot_notification_subscribers,
prioritization_fee_cache,
);
Ok(())
}
Expand Down Expand Up @@ -250,6 +257,7 @@ impl OptimisticallyConfirmedBankTracker {
}
}

#[allow(clippy::too_many_arguments)]
pub fn process_notification(
notification: BankNotification,
bank_forks: &Arc<RwLock<BankForks>>,
Expand All @@ -260,6 +268,7 @@ impl OptimisticallyConfirmedBankTracker {
highest_confirmed_slot: &mut Slot,
newest_root_slot: &mut Slot,
slot_notification_subscribers: &Option<Arc<RwLock<Vec<SlotNotificationSender>>>>,
prioritization_fee_cache: &PrioritizationFeeCache,
) {
debug!("received bank notification: {:?}", notification);
match notification {
Expand Down Expand Up @@ -299,6 +308,9 @@ impl OptimisticallyConfirmedBankTracker {
slot,
timestamp: timestamp(),
});

// finalize block's minimum prioritization fee cache for this bank
prioritization_fee_cache.finalize_priority_fee(slot);
}
BankNotification::Frozen(bank) => {
let frozen_slot = bank.slot();
Expand Down Expand Up @@ -458,6 +470,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2);
assert_eq!(highest_confirmed_slot, 2);
Expand All @@ -473,6 +486,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2);
assert_eq!(highest_confirmed_slot, 2);
Expand All @@ -488,6 +502,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2);
assert_eq!(pending_optimistically_confirmed_banks.len(), 1);
Expand All @@ -508,6 +523,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 3);
assert_eq!(highest_confirmed_slot, 3);
Expand All @@ -527,6 +543,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 3);
assert_eq!(pending_optimistically_confirmed_banks.len(), 1);
Expand Down Expand Up @@ -554,6 +571,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&subscribers,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5);
assert_eq!(pending_optimistically_confirmed_banks.len(), 0);
Expand All @@ -572,6 +590,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&subscribers,
&PrioritizationFeeCache::default(),
);

assert_eq!(newest_root_slot, 5);
Expand Down Expand Up @@ -601,6 +620,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5);
assert_eq!(pending_optimistically_confirmed_banks.len(), 0);
Expand All @@ -622,6 +642,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&subscribers,
&PrioritizationFeeCache::default(),
);
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 7);
assert_eq!(pending_optimistically_confirmed_banks.len(), 0);
Expand All @@ -639,6 +660,7 @@ mod tests {
&mut highest_confirmed_slot,
&mut newest_root_slot,
&subscribers,
&PrioritizationFeeCache::default(),
);

assert_eq!(newest_root_slot, 7);
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8324,6 +8324,7 @@ pub mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
Expand All @@ -8343,6 +8344,7 @@ pub mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
Expand All @@ -8362,6 +8364,7 @@ pub mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
Expand All @@ -8382,6 +8385,7 @@ pub mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
Expand Down
9 changes: 9 additions & 0 deletions rpc/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ pub(crate) mod tests {
solana_runtime::{
commitment::BlockCommitment,
genesis_utils::{create_genesis_config, GenesisConfigInfo},
prioritization_fee_cache::PrioritizationFeeCache,
},
solana_sdk::{
commitment_config::CommitmentConfig,
Expand Down Expand Up @@ -2032,6 +2033,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);

// a closure to reduce code duplications in building expected responses:
Expand Down Expand Up @@ -2083,6 +2085,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);

let response = receiver.recv();
Expand Down Expand Up @@ -2204,6 +2207,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);

// The following should panic
Expand Down Expand Up @@ -2321,6 +2325,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);

// a closure to reduce code duplications in building expected responses:
Expand Down Expand Up @@ -2374,6 +2379,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);

let response = receiver.recv();
Expand Down Expand Up @@ -2809,6 +2815,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);

// Now, notify the frozen bank and ensure its notifications are processed
Expand All @@ -2823,6 +2830,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);

let response = receiver0.recv();
Expand Down Expand Up @@ -2874,6 +2882,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot,
&mut highest_root_slot,
&None,
&PrioritizationFeeCache::default(),
);
let response = receiver1.recv();
let expected = json!({
Expand Down

0 comments on commit 605da4a

Please sign in to comment.