From eba1b2d3e39b516dae736f07438d0b498c08191b Mon Sep 17 00:00:00 2001 From: Lijun Wang <83639177+lijunwangs@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:28:56 -0800 Subject: [PATCH] Remove RwLock on TransactionNotifier (#33962) * Remove RwLock on TransactionNotifier --- core/src/validator.rs | 6 +++--- .../src/geyser_plugin_service.rs | 10 +++++----- rpc/src/transaction_notifier_interface.rs | 4 ++-- rpc/src/transaction_status_service.rs | 19 +++++++++---------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/core/src/validator.rs b/core/src/validator.rs index 2becf9590330a3..4aa6fb992a0a42 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -83,7 +83,7 @@ use { rpc_pubsub_service::{PubSubConfig, PubSubService}, rpc_service::JsonRpcService, rpc_subscriptions::RpcSubscriptions, - transaction_notifier_interface::TransactionNotifierLock, + transaction_notifier_interface::TransactionNotifierArc, transaction_status_service::TransactionStatusService, }, solana_runtime::{ @@ -1689,7 +1689,7 @@ fn load_blockstore( exit: Arc, start_progress: &Arc>, accounts_update_notifier: Option, - transaction_notifier: Option, + transaction_notifier: Option, entry_notifier: Option, poh_timing_point_sender: Option, ) -> Result< @@ -2167,7 +2167,7 @@ fn initialize_rpc_transaction_history_services( exit: Arc, enable_rpc_transaction_history: bool, enable_extended_tx_metadata_storage: bool, - transaction_notifier: Option, + transaction_notifier: Option, ) -> TransactionHistoryServices { let max_complete_transaction_status_slot = Arc::new(AtomicU64::new(blockstore.max_root())); let (transaction_status_sender, transaction_status_receiver) = unbounded(); diff --git a/geyser-plugin-manager/src/geyser_plugin_service.rs b/geyser-plugin-manager/src/geyser_plugin_service.rs index a95c1b7e1a18c5..83ab9284cecb2a 100644 --- a/geyser-plugin-manager/src/geyser_plugin_service.rs +++ b/geyser-plugin-manager/src/geyser_plugin_service.rs @@ -15,7 +15,7 @@ use { solana_ledger::entry_notifier_interface::EntryNotifierArc, solana_rpc::{ optimistically_confirmed_bank_tracker::SlotNotification, - transaction_notifier_interface::TransactionNotifierLock, + transaction_notifier_interface::TransactionNotifierArc, }, std::{ path::{Path, PathBuf}, @@ -34,7 +34,7 @@ pub struct GeyserPluginService { slot_status_observer: Option, plugin_manager: Arc>, accounts_update_notifier: Option, - transaction_notifier: Option, + transaction_notifier: Option, entry_notifier: Option, block_metadata_notifier: Option, } @@ -92,10 +92,10 @@ impl GeyserPluginService { None }; - let transaction_notifier: Option = + let transaction_notifier: Option = if transaction_notifications_enabled { let transaction_notifier = TransactionNotifierImpl::new(plugin_manager.clone()); - Some(Arc::new(RwLock::new(transaction_notifier))) + Some(Arc::new(transaction_notifier)) } else { None }; @@ -160,7 +160,7 @@ impl GeyserPluginService { self.accounts_update_notifier.clone() } - pub fn get_transaction_notifier(&self) -> Option { + pub fn get_transaction_notifier(&self) -> Option { self.transaction_notifier.clone() } diff --git a/rpc/src/transaction_notifier_interface.rs b/rpc/src/transaction_notifier_interface.rs index ab765d1207fe27..d09a207b1c6e18 100644 --- a/rpc/src/transaction_notifier_interface.rs +++ b/rpc/src/transaction_notifier_interface.rs @@ -1,7 +1,7 @@ use { solana_sdk::{clock::Slot, signature::Signature, transaction::SanitizedTransaction}, solana_transaction_status::TransactionStatusMeta, - std::sync::{Arc, RwLock}, + std::sync::Arc, }; pub trait TransactionNotifier { @@ -15,4 +15,4 @@ pub trait TransactionNotifier { ); } -pub type TransactionNotifierLock = Arc>; +pub type TransactionNotifierArc = Arc; diff --git a/rpc/src/transaction_status_service.rs b/rpc/src/transaction_status_service.rs index 193efb69fa481f..b98f0831518675 100644 --- a/rpc/src/transaction_status_service.rs +++ b/rpc/src/transaction_status_service.rs @@ -1,5 +1,5 @@ use { - crate::transaction_notifier_interface::TransactionNotifierLock, + crate::transaction_notifier_interface::TransactionNotifierArc, crossbeam_channel::{Receiver, RecvTimeoutError}, itertools::izip, solana_accounts_db::transaction_results::{DurableNonceFee, TransactionExecutionDetails}, @@ -29,7 +29,7 @@ impl TransactionStatusService { write_transaction_status_receiver: Receiver, max_complete_transaction_status_slot: Arc, enable_rpc_transaction_history: bool, - transaction_notifier: Option, + transaction_notifier: Option, blockstore: Arc, enable_extended_tx_metadata_storage: bool, exit: Arc, @@ -60,7 +60,7 @@ impl TransactionStatusService { write_transaction_status_receiver: &Receiver, max_complete_transaction_status_slot: &Arc, enable_rpc_transaction_history: bool, - transaction_notifier: Option, + transaction_notifier: Option, blockstore: &Blockstore, enable_extended_tx_metadata_storage: bool, ) -> Result<(), RecvTimeoutError> { @@ -169,7 +169,7 @@ impl TransactionStatusService { }; if let Some(transaction_notifier) = transaction_notifier.as_ref() { - transaction_notifier.write().unwrap().notify_transaction( + transaction_notifier.notify_transaction( slot, transaction_index, transaction.signature(), @@ -255,7 +255,7 @@ pub(crate) mod tests { std::{ sync::{ atomic::{AtomicBool, Ordering}, - Arc, RwLock, + Arc, }, thread::sleep, time::Duration, @@ -432,7 +432,7 @@ pub(crate) mod tests { transaction_indexes: vec![transaction_index], }; - let test_notifier = Arc::new(RwLock::new(TestTransactionNotifier::new())); + let test_notifier = Arc::new(TestTransactionNotifier::new()); let exit = Arc::new(AtomicBool::new(false)); let transaction_status_service = TransactionStatusService::new( @@ -452,16 +452,15 @@ pub(crate) mod tests { exit.store(true, Ordering::Relaxed); transaction_status_service.join().unwrap(); - let notifier = test_notifier.read().unwrap(); - assert_eq!(notifier.notifications.len(), 1); + assert_eq!(test_notifier.notifications.len(), 1); let key = TestNotifierKey { slot, transaction_index, signature, }; - assert!(notifier.notifications.contains_key(&key)); + assert!(test_notifier.notifications.contains_key(&key)); - let result = &*notifier.notifications.get(&key).unwrap(); + let result = test_notifier.notifications.get(&key).unwrap(); assert_eq!( expected_transaction.signature(), result.transaction.signature()