From 17a8cc862ba4182dd01f5d61dceb1ab470e13a71 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 8 Jul 2020 19:13:42 -0600 Subject: [PATCH] Remove core dependencies from SendTransactionService (#10965) * Remove core dependencies from SendTransactionService * Fix clippy warnings --- core/src/rpc.rs | 59 ++++++++++------------------ core/src/rpc_service.rs | 3 +- core/src/send_transaction_service.rs | 33 +++++++--------- 3 files changed, 38 insertions(+), 57 deletions(-) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index e9357d0f07..d08f4e0232 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -176,6 +176,7 @@ impl JsonRpcRequestProcessor { let blockstore = Arc::new(Blockstore::open(&get_tmp_ledger_path!()).unwrap()); let exit = Arc::new(AtomicBool::new(false)); let cluster_info = Arc::new(ClusterInfo::default()); + let tpu_address = cluster_info.my_contact_info().tpu; Self { config: JsonRpcConfig::default(), bank_forks: bank_forks.clone(), @@ -190,10 +191,10 @@ impl JsonRpcRequestProcessor { blockstore, validator_exit: create_validator_exit(&exit), health: Arc::new(RpcHealth::new(cluster_info.clone(), None, 0, exit.clone())), - cluster_info: cluster_info.clone(), + cluster_info, genesis_hash, send_transaction_service: Arc::new(SendTransactionService::new( - &cluster_info, + tpu_address, &bank_forks, &exit, )), @@ -1867,6 +1868,7 @@ pub mod tests { let _ = bank.process_transaction(&tx); let cluster_info = Arc::new(ClusterInfo::default()); + let tpu_address = cluster_info.my_contact_info().tpu; cluster_info.insert_info(ContactInfo::new_with_pubkey_socketaddr( &leader_pubkey, @@ -1886,11 +1888,7 @@ pub mod tests { RpcHealth::stub(), cluster_info.clone(), Hash::default(), - Arc::new(SendTransactionService::new( - &cluster_info, - &bank_forks, - &exit, - )), + Arc::new(SendTransactionService::new(tpu_address, &bank_forks, &exit)), ); cluster_info.insert_info(ContactInfo::new_with_pubkey_socketaddr( @@ -3021,6 +3019,7 @@ pub mod tests { let rpc = RpcSolImpl; io.extend_with(rpc.to_delegate()); let cluster_info = Arc::new(ClusterInfo::default()); + let tpu_address = cluster_info.my_contact_info().tpu; let bank_forks = new_bank_forks().0; let meta = JsonRpcRequestProcessor::new( JsonRpcConfig::default(), @@ -3029,13 +3028,9 @@ pub mod tests { blockstore, validator_exit, RpcHealth::stub(), - cluster_info.clone(), + cluster_info, Hash::default(), - Arc::new(SendTransactionService::new( - &cluster_info, - &bank_forks, - &exit, - )), + Arc::new(SendTransactionService::new(tpu_address, &bank_forks, &exit)), ); let req = r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["37u9WtQpcm6ULa3Vmu7ySnANv"]}"#; @@ -3064,6 +3059,7 @@ pub mod tests { let cluster_info = Arc::new(ClusterInfo::new_with_invalid_keypair( ContactInfo::new_with_socketaddr(&socketaddr!("127.0.0.1:1234")), )); + let tpu_address = cluster_info.my_contact_info().tpu; let meta = JsonRpcRequestProcessor::new( JsonRpcConfig::default(), bank_forks.clone(), @@ -3071,13 +3067,9 @@ pub mod tests { blockstore, validator_exit, health.clone(), - cluster_info.clone(), + cluster_info, Hash::default(), - Arc::new(SendTransactionService::new( - &cluster_info, - &bank_forks, - &exit, - )), + Arc::new(SendTransactionService::new(tpu_address, &bank_forks, &exit)), ); let mut bad_transaction = @@ -3185,7 +3177,7 @@ pub mod tests { ); } - pub(crate) fn new_bank_forks() -> (Arc>, Keypair, Keypair) { + fn new_bank_forks() -> (Arc>, Keypair, Keypair) { let GenesisConfigInfo { mut genesis_config, mint_keypair, @@ -3213,6 +3205,7 @@ pub mod tests { let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default())); let cluster_info = Arc::new(ClusterInfo::default()); + let tpu_address = cluster_info.my_contact_info().tpu; let bank_forks = new_bank_forks().0; let request_processor = JsonRpcRequestProcessor::new( JsonRpcConfig::default(), @@ -3221,13 +3214,9 @@ pub mod tests { blockstore, validator_exit, RpcHealth::stub(), - cluster_info.clone(), + cluster_info, Hash::default(), - Arc::new(SendTransactionService::new( - &cluster_info, - &bank_forks, - &exit, - )), + Arc::new(SendTransactionService::new(tpu_address, &bank_forks, &exit)), ); assert_eq!(request_processor.validator_exit(), false); assert_eq!(exit.load(Ordering::Relaxed), false); @@ -3244,6 +3233,7 @@ pub mod tests { config.enable_validator_exit = true; let bank_forks = new_bank_forks().0; let cluster_info = Arc::new(ClusterInfo::default()); + let tpu_address = cluster_info.my_contact_info().tpu; let request_processor = JsonRpcRequestProcessor::new( config, bank_forks.clone(), @@ -3251,13 +3241,9 @@ pub mod tests { blockstore, validator_exit, RpcHealth::stub(), - cluster_info.clone(), + cluster_info, Hash::default(), - Arc::new(SendTransactionService::new( - &cluster_info, - &bank_forks, - &exit, - )), + Arc::new(SendTransactionService::new(tpu_address, &bank_forks, &exit)), ); assert_eq!(request_processor.validator_exit(), true); assert_eq!(exit.load(Ordering::Relaxed), true); @@ -3334,6 +3320,7 @@ pub mod tests { let mut config = JsonRpcConfig::default(); config.enable_validator_exit = true; let cluster_info = Arc::new(ClusterInfo::default()); + let tpu_address = cluster_info.my_contact_info().tpu; let request_processor = JsonRpcRequestProcessor::new( config, bank_forks.clone(), @@ -3341,13 +3328,9 @@ pub mod tests { blockstore, validator_exit, RpcHealth::stub(), - cluster_info.clone(), + cluster_info, Hash::default(), - Arc::new(SendTransactionService::new( - &cluster_info, - &bank_forks, - &exit, - )), + Arc::new(SendTransactionService::new(tpu_address, &bank_forks, &exit)), ); assert_eq!( request_processor.get_block_commitment(0), diff --git a/core/src/rpc_service.rs b/core/src/rpc_service.rs index f9bc93db35..39c309d3df 100644 --- a/core/src/rpc_service.rs +++ b/core/src/rpc_service.rs @@ -250,9 +250,10 @@ impl JsonRpcService { override_health_check, )); + let tpu_address = cluster_info.my_contact_info().tpu; let exit_send_transaction_service = Arc::new(AtomicBool::new(false)); let send_transaction_service = Arc::new(SendTransactionService::new( - &cluster_info, + tpu_address, &bank_forks, &exit_send_transaction_service, )); diff --git a/core/src/send_transaction_service.rs b/core/src/send_transaction_service.rs index eca31d6089..12047704ce 100644 --- a/core/src/send_transaction_service.rs +++ b/core/src/send_transaction_service.rs @@ -1,4 +1,3 @@ -use crate::cluster_info::ClusterInfo; use solana_metrics::{datapoint_warn, inc_new_counter_info}; use solana_runtime::{bank::Bank, bank_forks::BankForks}; use solana_sdk::{clock::Slot, signature::Signature}; @@ -41,12 +40,11 @@ struct ProcessTransactionsResult { impl SendTransactionService { pub fn new( - cluster_info: &Arc, + tpu_address: SocketAddr, bank_forks: &Arc>, exit: &Arc, ) -> Self { let (sender, receiver) = channel::(); - let tpu_address = cluster_info.my_contact_info().tpu; let thread = Self::retry_thread(receiver, bank_forks.clone(), tpu_address, exit.clone()); Self { @@ -192,17 +190,19 @@ impl SendTransactionService { #[cfg(test)] mod test { use super::*; - use crate::rpc::tests::new_bank_forks; - use solana_sdk::{pubkey::Pubkey, signature::Signer}; + use solana_sdk::{ + genesis_config::create_genesis_config, pubkey::Pubkey, signature::Signer, + system_transaction, + }; #[test] fn service_exit() { - let cluster_info = Arc::new(ClusterInfo::default()); - let bank_forks = new_bank_forks().0; + let tpu_address = "127.0.0.1:0".parse().unwrap(); + let bank = Bank::default(); + let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); let exit = Arc::new(AtomicBool::new(false)); - let send_tranaction_service = - SendTransactionService::new(&cluster_info, &bank_forks, &exit); + let send_tranaction_service = SendTransactionService::new(tpu_address, &bank_forks, &exit); exit.store(true, Ordering::Relaxed); send_tranaction_service.join().unwrap(); @@ -212,10 +212,11 @@ mod test { fn process_transactions() { solana_logger::setup(); - let (bank_forks, mint_keypair, _voting_keypair) = new_bank_forks(); - let cluster_info = ClusterInfo::default(); + let (genesis_config, mint_keypair) = create_genesis_config(4); + let bank = Bank::new(&genesis_config); + let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); let send_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); - let tpu_address = cluster_info.my_contact_info().tpu; + let tpu_address = "127.0.0.1:0".parse().unwrap(); let root_bank = Arc::new(Bank::new_from_parent( &bank_forks.read().unwrap().working_bank(), @@ -234,12 +235,8 @@ mod test { let failed_signature = { let blockhash = working_bank.last_blockhash(); - let transaction = solana_sdk::system_transaction::transfer( - &mint_keypair, - &Pubkey::default(), - 1, - blockhash, - ); + let transaction = + system_transaction::transfer(&mint_keypair, &Pubkey::default(), 1, blockhash); let signature = transaction.signatures[0]; working_bank.process_transaction(&transaction).unwrap_err(); signature