Remove core dependencies from SendTransactionService (#10965)

* Remove core dependencies from SendTransactionService

* Fix clippy warnings
This commit is contained in:
Greg Fitzgerald 2020-07-08 19:13:42 -06:00 committed by GitHub
parent ebadbce920
commit 17a8cc862b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 57 deletions

View File

@ -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<RwLock<BankForks>>, Keypair, Keypair) {
fn new_bank_forks() -> (Arc<RwLock<BankForks>>, 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),

View File

@ -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,
));

View File

@ -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<ClusterInfo>,
tpu_address: SocketAddr,
bank_forks: &Arc<RwLock<BankForks>>,
exit: &Arc<AtomicBool>,
) -> Self {
let (sender, receiver) = channel::<TransactionInfo>();
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