improve prioritization fee cache accuracy (#32692)

* improve prioritization cache accuracy
This commit is contained in:
Tao Zhu 2023-08-07 19:27:28 -05:00 committed by GitHub
parent bf6d0aba4c
commit ef6af307a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 6 deletions

View File

@ -2719,7 +2719,6 @@ impl ReplayStage {
ancestor_hashes_replay_update_sender: &AncestorHashesReplayUpdateSender, ancestor_hashes_replay_update_sender: &AncestorHashesReplayUpdateSender,
block_metadata_notifier: Option<BlockMetadataNotifierLock>, block_metadata_notifier: Option<BlockMetadataNotifierLock>,
replay_result_vec: &[ReplaySlotFromBlockstore], replay_result_vec: &[ReplaySlotFromBlockstore],
prioritization_fee_cache: &PrioritizationFeeCache,
purge_repair_slot_counter: &mut PurgeRepairSlotCounter, purge_repair_slot_counter: &mut PurgeRepairSlotCounter,
) -> bool { ) -> bool {
// TODO: See if processing of blockstore replay results and bank completion can be made thread safe. // TODO: See if processing of blockstore replay results and bank completion can be made thread safe.
@ -2795,9 +2794,6 @@ impl ReplayStage {
warn!("cost_update_sender failed sending bank stats: {:?}", err) 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()); assert_ne!(bank.hash(), Hash::default());
// Needs to be updated before `check_slot_agrees_with_cluster()` so that // Needs to be updated before `check_slot_agrees_with_cluster()` so that
// any updates in `check_slot_agrees_with_cluster()` on fork choice take // any updates in `check_slot_agrees_with_cluster()` on fork choice take
@ -2985,7 +2981,6 @@ impl ReplayStage {
ancestor_hashes_replay_update_sender, ancestor_hashes_replay_update_sender,
block_metadata_notifier, block_metadata_notifier,
&replay_result_vec, &replay_result_vec,
prioritization_fee_cache,
purge_repair_slot_counter, purge_repair_slot_counter,
) )
} else { } else {

View File

@ -988,6 +988,7 @@ impl Validator {
optimistically_confirmed_bank, optimistically_confirmed_bank,
rpc_subscriptions.clone(), rpc_subscriptions.clone(),
confirmed_bank_subscribers, confirmed_bank_subscribers,
prioritization_fee_cache.clone(),
)), )),
Some(BankNotificationSenderConfig { Some(BankNotificationSenderConfig {
sender: bank_notification_sender, sender: bank_notification_sender,

View File

@ -12,7 +12,9 @@ use {
crate::rpc_subscriptions::RpcSubscriptions, crate::rpc_subscriptions::RpcSubscriptions,
crossbeam_channel::{Receiver, RecvTimeoutError, Sender}, crossbeam_channel::{Receiver, RecvTimeoutError, Sender},
solana_rpc_client_api::response::{SlotTransactionStats, SlotUpdate}, solana_rpc_client_api::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}, solana_sdk::{clock::Slot, timing::timestamp},
std::{ std::{
collections::HashSet, collections::HashSet,
@ -92,6 +94,7 @@ impl OptimisticallyConfirmedBankTracker {
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>, optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
subscriptions: Arc<RpcSubscriptions>, subscriptions: Arc<RpcSubscriptions>,
slot_notification_subscribers: Option<Arc<RwLock<Vec<SlotNotificationSender>>>>, slot_notification_subscribers: Option<Arc<RwLock<Vec<SlotNotificationSender>>>>,
prioritization_fee_cache: Arc<PrioritizationFeeCache>,
) -> Self { ) -> Self {
let mut pending_optimistically_confirmed_banks = HashSet::new(); let mut pending_optimistically_confirmed_banks = HashSet::new();
let mut last_notified_confirmed_slot: Slot = 0; let mut last_notified_confirmed_slot: Slot = 0;
@ -114,6 +117,7 @@ impl OptimisticallyConfirmedBankTracker {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&slot_notification_subscribers, &slot_notification_subscribers,
&prioritization_fee_cache,
) { ) {
break; break;
} }
@ -122,6 +126,7 @@ impl OptimisticallyConfirmedBankTracker {
Self { thread_hdl } Self { thread_hdl }
} }
#[allow(clippy::too_many_arguments)]
fn recv_notification( fn recv_notification(
receiver: &Receiver<BankNotification>, receiver: &Receiver<BankNotification>,
bank_forks: &RwLock<BankForks>, bank_forks: &RwLock<BankForks>,
@ -132,6 +137,7 @@ impl OptimisticallyConfirmedBankTracker {
highest_confirmed_slot: &mut Slot, highest_confirmed_slot: &mut Slot,
newest_root_slot: &mut Slot, newest_root_slot: &mut Slot,
slot_notification_subscribers: &Option<Arc<RwLock<Vec<SlotNotificationSender>>>>, slot_notification_subscribers: &Option<Arc<RwLock<Vec<SlotNotificationSender>>>>,
prioritization_fee_cache: &PrioritizationFeeCache,
) -> Result<(), RecvTimeoutError> { ) -> Result<(), RecvTimeoutError> {
let notification = receiver.recv_timeout(Duration::from_secs(1))?; let notification = receiver.recv_timeout(Duration::from_secs(1))?;
Self::process_notification( Self::process_notification(
@ -144,6 +150,7 @@ impl OptimisticallyConfirmedBankTracker {
highest_confirmed_slot, highest_confirmed_slot,
newest_root_slot, newest_root_slot,
slot_notification_subscribers, slot_notification_subscribers,
prioritization_fee_cache,
); );
Ok(()) Ok(())
} }
@ -249,6 +256,7 @@ impl OptimisticallyConfirmedBankTracker {
} }
} }
#[allow(clippy::too_many_arguments)]
pub fn process_notification( pub fn process_notification(
notification: BankNotification, notification: BankNotification,
bank_forks: &RwLock<BankForks>, bank_forks: &RwLock<BankForks>,
@ -259,6 +267,7 @@ impl OptimisticallyConfirmedBankTracker {
highest_confirmed_slot: &mut Slot, highest_confirmed_slot: &mut Slot,
newest_root_slot: &mut Slot, newest_root_slot: &mut Slot,
slot_notification_subscribers: &Option<Arc<RwLock<Vec<SlotNotificationSender>>>>, slot_notification_subscribers: &Option<Arc<RwLock<Vec<SlotNotificationSender>>>>,
prioritization_fee_cache: &PrioritizationFeeCache,
) { ) {
debug!("received bank notification: {:?}", notification); debug!("received bank notification: {:?}", notification);
match notification { match notification {
@ -298,6 +307,9 @@ impl OptimisticallyConfirmedBankTracker {
slot, slot,
timestamp: timestamp(), timestamp: timestamp(),
}); });
// finalize block's minimum prioritization fee cache for this bank
prioritization_fee_cache.finalize_priority_fee(slot);
} }
BankNotification::Frozen(bank) => { BankNotification::Frozen(bank) => {
let frozen_slot = bank.slot(); let frozen_slot = bank.slot();
@ -457,6 +469,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2);
assert_eq!(highest_confirmed_slot, 2); assert_eq!(highest_confirmed_slot, 2);
@ -472,6 +485,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2);
assert_eq!(highest_confirmed_slot, 2); assert_eq!(highest_confirmed_slot, 2);
@ -487,6 +501,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 2);
assert_eq!(pending_optimistically_confirmed_banks.len(), 1); assert_eq!(pending_optimistically_confirmed_banks.len(), 1);
@ -507,6 +522,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 3); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 3);
assert_eq!(highest_confirmed_slot, 3); assert_eq!(highest_confirmed_slot, 3);
@ -526,6 +542,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 3); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 3);
assert_eq!(pending_optimistically_confirmed_banks.len(), 1); assert_eq!(pending_optimistically_confirmed_banks.len(), 1);
@ -553,6 +570,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&subscribers, &subscribers,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5);
assert_eq!(pending_optimistically_confirmed_banks.len(), 0); assert_eq!(pending_optimistically_confirmed_banks.len(), 0);
@ -571,6 +589,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&subscribers, &subscribers,
&PrioritizationFeeCache::default(),
); );
assert_eq!(newest_root_slot, 5); assert_eq!(newest_root_slot, 5);
@ -600,6 +619,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 5);
assert_eq!(pending_optimistically_confirmed_banks.len(), 0); assert_eq!(pending_optimistically_confirmed_banks.len(), 0);
@ -621,6 +641,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&subscribers, &subscribers,
&PrioritizationFeeCache::default(),
); );
assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 7); assert_eq!(optimistically_confirmed_bank.read().unwrap().bank.slot(), 7);
assert_eq!(pending_optimistically_confirmed_banks.len(), 0); assert_eq!(pending_optimistically_confirmed_banks.len(), 0);
@ -638,6 +659,7 @@ mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut newest_root_slot, &mut newest_root_slot,
&subscribers, &subscribers,
&PrioritizationFeeCache::default(),
); );
assert_eq!(newest_root_slot, 7); assert_eq!(newest_root_slot, 7);

View File

@ -8360,6 +8360,7 @@ pub mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let req = let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#; r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
@ -8379,6 +8380,7 @@ pub mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let req = let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#; r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
@ -8398,6 +8400,7 @@ pub mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let req = let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#; r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
@ -8418,6 +8421,7 @@ pub mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let req = let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#; r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;

View File

@ -1267,6 +1267,7 @@ pub(crate) mod tests {
solana_runtime::{ solana_runtime::{
commitment::BlockCommitment, commitment::BlockCommitment,
genesis_utils::{create_genesis_config, GenesisConfigInfo}, genesis_utils::{create_genesis_config, GenesisConfigInfo},
prioritization_fee_cache::PrioritizationFeeCache,
}, },
solana_sdk::{ solana_sdk::{
commitment_config::CommitmentConfig, commitment_config::CommitmentConfig,
@ -2050,6 +2051,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
// a closure to reduce code duplications in building expected responses: // a closure to reduce code duplications in building expected responses:
@ -2102,6 +2104,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let response = receiver.recv(); let response = receiver.recv();
@ -2223,6 +2226,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
// The following should panic // The following should panic
@ -2340,6 +2344,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
// a closure to reduce code duplications in building expected responses: // a closure to reduce code duplications in building expected responses:
@ -2394,6 +2399,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let response = receiver.recv(); let response = receiver.recv();
@ -2830,6 +2836,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
// Now, notify the frozen bank and ensure its notifications are processed // Now, notify the frozen bank and ensure its notifications are processed
@ -2844,6 +2851,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let response = receiver0.recv(); let response = receiver0.recv();
@ -2898,6 +2906,7 @@ pub(crate) mod tests {
&mut highest_confirmed_slot, &mut highest_confirmed_slot,
&mut highest_root_slot, &mut highest_root_slot,
&None, &None,
&PrioritizationFeeCache::default(),
); );
let response = receiver1.recv(); let response = receiver1.recv();
let expected = json!({ let expected = json!({