From 167eb01735850caf5978df7c263b00b82b120213 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Tue, 27 Nov 2018 21:08:14 -0800 Subject: [PATCH] optimize bench-tps and rpc_request to work on crappy WSL boxes --- src/bin/bench-tps.rs | 109 +++++++++++++++++------------- src/rpc_request.rs | 17 ++++- src/thin_client.rs | 34 ++++++++-- src/wallet.rs | 155 ++++++++++++++++++++++++------------------- 4 files changed, 191 insertions(+), 124 deletions(-) diff --git a/src/bin/bench-tps.rs b/src/bin/bench-tps.rs index 7c5e5a70aa..8b8f4f7d72 100644 --- a/src/bin/bench-tps.rs +++ b/src/bin/bench-tps.rs @@ -1,12 +1,7 @@ -extern crate bincode; #[macro_use] extern crate clap; -extern crate rand; extern crate rayon; #[macro_use] -extern crate log; -extern crate serde_json; -#[macro_use] extern crate solana; extern crate solana_drone; extern crate solana_metrics; @@ -14,7 +9,6 @@ extern crate solana_sdk; use clap::{App, Arg}; -use rand::{thread_rng, Rng}; use rayon::prelude::*; use solana::client::mk_client; use solana::cluster_info::{ClusterInfo, NodeInfo}; @@ -190,7 +184,6 @@ fn generate_txs( ) { let mut client = mk_client(leader); let last_id = client.get_last_id(); - info!("last_id: {} {:?}", last_id, Instant::now()); let tx_count = source.len(); println!("Signing transactions... {} (reclaim={})", tx_count, reclaim); let signing_start = Instant::now(); @@ -293,24 +286,17 @@ fn do_tx_transfers( } const MAX_SPENDS_PER_TX: usize = 4; -fn verify_transfer(client: &mut ThinClient, tx: &Transaction) -> bool { - if client.poll_for_signature(&tx.signatures[0]).is_err() { - println!("no signature"); - return false; - } + +fn verify_funding_transfer(client: &mut ThinClient, tx: &Transaction, amount: u64) -> bool { for a in &tx.account_keys[1..] { - if client.poll_get_balance(a).unwrap_or(0) == 0 { - println!( - "no balance {} source bal: {} {:?}", - a, - client.poll_get_balance(&tx.account_keys[0]).unwrap_or(0), - tx - ); - return false; + if client.get_balance(a).unwrap_or(0) >= amount { + return true; } } - true + + false } + /// fund the dests keys by spending all of the source keys into MAX_SPENDS_PER_TX /// on every iteration. This allows us to replay the transfers because the source is either empty, /// or full @@ -343,34 +329,63 @@ fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], token to_fund.push((f.0, moves)); } } - println!("sending... {}", to_fund.len()); - // try to transfer a few at a time with recent last_id - to_fund.chunks(10_000).for_each(|chunk| { - loop { - let last_id = client.get_last_id(); - println!("generating... {} {}", chunk.len(), last_id); - let mut to_fund_txs: Vec<_> = chunk - .par_iter() - .map(|(k, m)| Transaction::system_move_many(k, &m, last_id, 0)) - .collect(); - // with randomly distributed the failures - // most of the account pairs should have some funding in one of the pairs - // durring generate_tx step - thread_rng().shuffle(&mut to_fund_txs); - println!("transfering... {}", chunk.len()); - to_fund_txs.iter().for_each(|tx| { - let _ = client.transfer_signed(&tx).expect("transfer"); - }); - // randomly sample some of the transfers - thread_rng().shuffle(&mut to_fund_txs); - let max = cmp::min(10, to_fund_txs.len()); - if to_fund_txs[..max] + + // try to transfer a "few" at a time with recent last_id + // assume 4MB network buffers, and 512 byte packets + const FUND_CHUNK_LEN: usize = 4 * 1024 * 1024 / 512; + + to_fund.chunks(FUND_CHUNK_LEN).for_each(|chunk| { + let mut tries = 0; + + // this set of transactions just initializes us for bookkeeping + #[cfg_attr(feature = "cargo-clippy", allow(clone_double_ref))] // sigh + let mut to_fund_txs: Vec<_> = chunk + .par_iter() + .map(|(k, m)| { + ( + k.clone(), + Transaction::system_move_many(k, &m, Default::default(), 0), + ) + }).collect(); + + let amount = chunk[0].1[0].1; + + while !to_fund_txs.is_empty() { + let receivers = to_fund_txs .iter() - .all(|tx| verify_transfer(client, tx)) - { - break; - } + .fold(0, |len, (_, tx)| len + tx.instructions.len()); + + println!( + "{} {} to {} in {} txs", + if tries == 0 { + "transferring" + } else { + " retrying" + }, + amount, + receivers, + to_fund_txs.len(), + ); + + let last_id = client.get_last_id(); + + // re-sign retained to_fund_txes with updated last_id + to_fund_txs.par_iter_mut().for_each(|(k, tx)| { + tx.sign(&[k], last_id); + }); + + to_fund_txs.iter().for_each(|(_, tx)| { + client.transfer_signed(&tx).expect("transfer"); + }); + + // retry anything that seems to have dropped through cracks + // again since these txs are all or nothing, they're fine to + // retry + to_fund_txs.retain(|(_, tx)| !verify_funding_transfer(client, &tx, amount)); + + tries += 1; } + println!("transferred"); }); println!("funded: {} left: {}", new_funded.len(), notfunded.len()); funded = new_funded; diff --git a/src/rpc_request.rs b/src/rpc_request.rs index d1b58f9659..eff3d50a70 100644 --- a/src/rpc_request.rs +++ b/src/rpc_request.rs @@ -14,15 +14,18 @@ pub enum RpcRequest { RequestAirdrop, SendTransaction, } +pub type RpcClient = reqwest::Client; + impl RpcRequest { pub fn make_rpc_request( &self, + client: &RpcClient, rpc_addr: &str, id: u64, params: Option, ) -> Result> { let request = self.build_request_json(id, params); - let client = reqwest::Client::new(); + let mut response = client .post(rpc_addr) .header(CONTENT_TYPE, "application/json") @@ -37,6 +40,7 @@ impl RpcRequest { } Ok(json["result"].clone()) } + fn build_request_json(&self, id: u64, params: Option) -> Value { let jsonrpc = "2.0"; let method = match self { @@ -168,8 +172,10 @@ mod tests { let rpc_addr = receiver.recv().unwrap(); let rpc_addr = format!("http://{}", rpc_addr.to_string()); + let rpc_client = RpcClient::new(); let balance = RpcRequest::GetBalance.make_rpc_request( + &rpc_client, &rpc_addr, 1, Some(json!(["deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"])), @@ -177,7 +183,7 @@ mod tests { assert!(balance.is_ok()); assert_eq!(balance.unwrap().as_u64().unwrap(), 50); - let last_id = RpcRequest::GetLastId.make_rpc_request(&rpc_addr, 2, None); + let last_id = RpcRequest::GetLastId.make_rpc_request(&rpc_client, &rpc_addr, 2, None); assert!(last_id.is_ok()); assert_eq!( last_id.unwrap().as_str().unwrap(), @@ -185,7 +191,12 @@ mod tests { ); // Send erroneous parameter - let last_id = RpcRequest::GetLastId.make_rpc_request(&rpc_addr, 3, Some(json!("paramter"))); + let last_id = RpcRequest::GetLastId.make_rpc_request( + &rpc_client, + &rpc_addr, + 3, + Some(json!("paramter")), + ); assert_eq!(last_id.is_err(), true); } } diff --git a/src/thin_client.rs b/src/thin_client.rs index c49ab1c827..67a3870ab8 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -11,7 +11,7 @@ use log::Level; use ncp::Ncp; use packet::PACKET_DATA_SIZE; use result::{Error, Result}; -use rpc_request::RpcRequest; +use rpc_request::{RpcClient, RpcRequest}; use serde_json; use signature::{Keypair, Signature}; use solana_metrics; @@ -42,6 +42,8 @@ pub struct ThinClient { balances: HashMap, signature_status: bool, finality: Option, + + rpc_client: RpcClient, } impl ThinClient { @@ -53,6 +55,7 @@ impl ThinClient { transactions_socket: UdpSocket, ) -> Self { ThinClient { + rpc_client: RpcClient::new(), rpc_addr, transactions_addr, transactions_socket, @@ -122,7 +125,12 @@ impl ThinClient { pub fn get_account_userdata(&mut self, pubkey: &Pubkey) -> io::Result>> { let params = json!([format!("{}", pubkey)]); let rpc_string = format!("http://{}", self.rpc_addr.to_string()); - let resp = RpcRequest::GetAccountInfo.make_rpc_request(&rpc_string, 1, Some(params)); + let resp = RpcRequest::GetAccountInfo.make_rpc_request( + &self.rpc_client, + &rpc_string, + 1, + Some(params), + ); if let Ok(account_json) = resp { let account: Account = serde_json::from_value(account_json).expect("deserialize account"); @@ -141,7 +149,12 @@ impl ThinClient { trace!("get_balance sending request to {}", self.rpc_addr); let params = json!([format!("{}", pubkey)]); let rpc_string = format!("http://{}", self.rpc_addr.to_string()); - let resp = RpcRequest::GetAccountInfo.make_rpc_request(&rpc_string, 1, Some(params)); + let resp = RpcRequest::GetAccountInfo.make_rpc_request( + &self.rpc_client, + &rpc_string, + 1, + Some(params), + ); if let Ok(account_json) = resp { let account: Account = serde_json::from_value(account_json).expect("deserialize account"); @@ -152,6 +165,7 @@ impl ThinClient { self.balances.remove(&pubkey); } trace!("get_balance {:?}", self.balances.get(pubkey)); + // TODO: This is a hard coded call to introspect the balance of a budget_dsl contract // In the future custom contracts would need their own introspection self.balances @@ -167,7 +181,8 @@ impl ThinClient { let rpc_string = format!("http://{}", self.rpc_addr.to_string()); while !done { debug!("get_finality send_to {}", &self.rpc_addr); - let resp = RpcRequest::GetFinality.make_rpc_request(&rpc_string, 1, None); + let resp = + RpcRequest::GetFinality.make_rpc_request(&self.rpc_client, &rpc_string, 1, None); if let Ok(value) = resp { done = true; @@ -187,7 +202,12 @@ impl ThinClient { let mut tries_left = 5; let rpc_string = format!("http://{}", self.rpc_addr.to_string()); while tries_left > 0 { - let resp = RpcRequest::GetTransactionCount.make_rpc_request(&rpc_string, 1, None); + let resp = RpcRequest::GetTransactionCount.make_rpc_request( + &self.rpc_client, + &rpc_string, + 1, + None, + ); if let Ok(value) = resp { debug!("transaction_count recv_response: {:?}", value); @@ -209,7 +229,8 @@ impl ThinClient { let rpc_string = format!("http://{}", self.rpc_addr.to_string()); while !done { debug!("get_last_id send_to {}", &self.rpc_addr); - let resp = RpcRequest::GetLastId.make_rpc_request(&rpc_string, 1, None); + let resp = + RpcRequest::GetLastId.make_rpc_request(&self.rpc_client, &rpc_string, 1, None); if let Ok(value) = resp { done = true; @@ -286,6 +307,7 @@ impl ThinClient { let mut done = false; while !done { let resp = RpcRequest::ConfirmTransaction.make_rpc_request( + &self.rpc_client, &rpc_string, 1, Some(params.clone()), diff --git a/src/wallet.rs b/src/wallet.rs index 4264ba69fd..986fc57b2e 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -11,7 +11,7 @@ use loader_transaction::LoaderTransaction; use ring::rand::SystemRandom; use ring::signature::Ed25519KeyPair; use rpc::RpcSignatureStatus; -use rpc_request::RpcRequest; +use rpc_request::{RpcClient, RpcRequest}; use serde_json; use signature::{Keypair, KeypairUtil, Signature}; use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT}; @@ -316,6 +316,7 @@ pub fn process_command(config: &WalletConfig) -> Result Result tokens, @@ -337,14 +338,14 @@ pub fn process_command(config: &WalletConfig) -> Result Result Ok("No account found! Request an airdrop to get started.".to_string()), @@ -370,17 +371,17 @@ pub fn process_command(config: &WalletConfig) -> Result { - let last_id = get_last_id(&rpc_addr)?; + let last_id = get_last_id(&rpc_client, &rpc_addr)?; let tx = Transaction::budget_new_signature(&config.id, pubkey, config.id.pubkey(), last_id); - let signature_str = send_tx(&rpc_addr, &tx)?; + let signature_str = send_tx(&rpc_client, &rpc_addr, &tx)?; Ok(signature_str.to_string()) } // Confirm the last client transaction by signature WalletCommand::Confirm(signature) => { let params = json!([format!("{}", signature)]); let confirmation = RpcRequest::ConfirmTransaction - .make_rpc_request(&rpc_addr, 1, Some(params))? + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params))? .as_bool(); match confirmation { Some(b) => { @@ -399,7 +400,7 @@ pub fn process_command(config: &WalletConfig) -> Result { let params = json!([format!("{}", config.id.pubkey())]); let balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params))? + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params))? .as_u64(); if let Some(tokens) = balance { if tokens < 1 { @@ -409,7 +410,7 @@ pub fn process_command(config: &WalletConfig) -> Result Result Result Result Result { let transaction_count = RpcRequest::GetTransactionCount - .make_rpc_request(&rpc_addr, 1, None)? + .make_rpc_request(&rpc_client, &rpc_addr, 1, None)? .as_u64(); match transaction_count { Some(count) => Ok(count.to_string()), @@ -482,11 +483,11 @@ pub fn process_command(config: &WalletConfig) -> Result { - let last_id = get_last_id(&rpc_addr)?; + let last_id = get_last_id(&rpc_client, &rpc_addr)?; if timestamp == None && *witnesses == None { let tx = Transaction::system_new(&config.id, to, tokens, last_id); - let signature_str = send_tx(&rpc_addr, &tx)?; + let signature_str = send_tx(&rpc_client, &rpc_addr, &tx)?; Ok(signature_str.to_string()) } else if *witnesses == None { let dt = timestamp.unwrap(); @@ -509,7 +510,7 @@ pub fn process_command(config: &WalletConfig) -> Result Result Result Result Result Result Result { let params = json!(format!("{}", config.id.pubkey())); let balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params))? + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params))? .as_u64(); if let Some(0) = balance { let params = json!([format!("{}", config.id.pubkey()), 1]); RpcRequest::RequestAirdrop - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap(); } - let last_id = get_last_id(&rpc_addr)?; + let last_id = get_last_id(&rpc_client, &rpc_addr)?; let tx = Transaction::budget_new_timestamp(&config.id, pubkey, to, dt, last_id); - let signature_str = send_tx(&rpc_addr, &tx)?; + let signature_str = send_tx(&rpc_client, &rpc_addr, &tx)?; Ok(signature_str.to_string()) } @@ -624,19 +625,19 @@ pub fn process_command(config: &WalletConfig) -> Result { let params = json!([format!("{}", config.id.pubkey())]); let balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params))? + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params))? .as_u64(); if let Some(0) = balance { let params = json!([format!("{}", config.id.pubkey()), 1]); RpcRequest::RequestAirdrop - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap(); } - let last_id = get_last_id(&rpc_addr)?; + let last_id = get_last_id(&rpc_client, &rpc_addr)?; let tx = Transaction::budget_new_signature(&config.id, pubkey, to, last_id); - let signature_str = send_tx(&rpc_addr, &tx)?; + let signature_str = send_tx(&rpc_client, &rpc_addr, &tx)?; Ok(signature_str.to_string()) } @@ -674,8 +675,8 @@ pub fn gen_keypair_file(outfile: String) -> Result> { Ok(serialized) } -fn get_last_id(rpc_addr: &str) -> Result> { - let result = RpcRequest::GetLastId.make_rpc_request(&rpc_addr, 1, None)?; +fn get_last_id(rpc_client: &RpcClient, rpc_addr: &str) -> Result> { + let result = RpcRequest::GetLastId.make_rpc_request(rpc_client, &rpc_addr, 1, None)?; if result.as_str().is_none() { Err(WalletError::RpcRequestError( "Received bad last_id".to_string(), @@ -688,10 +689,15 @@ fn get_last_id(rpc_addr: &str) -> Result> { Ok(Hash::new(&last_id_vec)) } -fn send_tx(rpc_addr: &str, tx: &Transaction) -> Result> { +fn send_tx( + rpc_client: &RpcClient, + rpc_addr: &str, + tx: &Transaction, +) -> Result> { let serialized = serialize(tx).unwrap(); let params = json!([serialized]); - let signature = RpcRequest::SendTransaction.make_rpc_request(&rpc_addr, 2, Some(params))?; + let signature = + RpcRequest::SendTransaction.make_rpc_request(rpc_client, &rpc_addr, 2, Some(params))?; if signature.as_str().is_none() { Err(WalletError::RpcRequestError( "Received result of an unexpected type".to_string(), @@ -700,10 +706,14 @@ fn send_tx(rpc_addr: &str, tx: &Transaction) -> Result Ok(signature.as_str().unwrap().to_string()) } -fn confirm_tx(rpc_addr: &str, signature: &str) -> Result> { +fn confirm_tx( + rpc_client: &RpcClient, + rpc_addr: &str, + signature: &str, +) -> Result> { let params = json!([signature.to_string()]); let signature_status = - RpcRequest::GetSignatureStatus.make_rpc_request(&rpc_addr, 1, Some(params))?; + RpcRequest::GetSignatureStatus.make_rpc_request(rpc_client, &rpc_addr, 1, Some(params))?; if let Some(status) = signature_status.as_str() { let rpc_status = RpcSignatureStatus::from_str(status).map_err(|_| { WalletError::RpcRequestError("Unable to parse signature status".to_string()) @@ -716,13 +726,17 @@ fn confirm_tx(rpc_addr: &str, signature: &str) -> Result Result<(), Box> { +fn send_and_confirm_tx( + rpc_client: &RpcClient, + rpc_addr: &str, + tx: &Transaction, +) -> Result<(), Box> { let mut send_retries = 3; while send_retries > 0 { let mut status_retries = 4; - let signature_str = send_tx(rpc_addr, tx)?; + let signature_str = send_tx(rpc_client, rpc_addr, tx)?; let status = loop { - let status = confirm_tx(rpc_addr, &signature_str)?; + let status = confirm_tx(rpc_client, rpc_addr, &signature_str)?; if status == RpcSignatureStatus::SignatureNotFound { status_retries -= 1; if status_retries == 0 { @@ -1200,9 +1214,11 @@ mod tests { assert!(sig_response.is_ok()); let rpc_addr = format!("http://{}", leader_data.rpc.to_string()); + let rpc_client = RpcClient::new(); + let params = json!([format!("{}", bob_config.id.pubkey())]); let balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); @@ -1272,6 +1288,7 @@ mod tests { let drone_addr = receiver.recv().unwrap(); let rpc_addr = format!("http://{}", leader_data.rpc.to_string()); + let rpc_client = RpcClient::new(); let mut config_payer = WalletConfig::default(); config_payer.network = leader_data.ncp; @@ -1283,11 +1300,11 @@ mod tests { assert_ne!(config_payer.id.pubkey(), config_witness.id.pubkey()); - let last_id = get_last_id(&rpc_addr).unwrap(); + let last_id = get_last_id(&rpc_client, &rpc_addr).unwrap(); let transaction = request_airdrop_transaction(&drone_addr, &config_payer.id.pubkey(), 50, last_id) .unwrap(); - send_and_confirm_tx(&rpc_addr, &transaction).unwrap(); + send_and_confirm_tx(&rpc_client, &rpc_addr, &transaction).unwrap(); // Make transaction (from config_payer to bob_pubkey) requiring timestamp from config_witness let date_string = "\"2018-09-19T17:30:59Z\""; @@ -1312,21 +1329,21 @@ mod tests { let params = json!([format!("{}", config_payer.id.pubkey())]); let config_payer_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(config_payer_balance, 39); let params = json!([format!("{}", process_id)]); let contract_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(contract_balance, 11); let params = json!([format!("{}", bob_pubkey)]); let recipient_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); @@ -1339,21 +1356,21 @@ mod tests { let params = json!([format!("{}", config_payer.id.pubkey())]); let config_payer_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(config_payer_balance, 39); let params = json!([format!("{}", process_id)]); let contract_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(contract_balance, 1); let params = json!([format!("{}", bob_pubkey)]); let recipient_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); @@ -1400,14 +1417,15 @@ mod tests { let drone_addr = receiver.recv().unwrap(); let rpc_addr = format!("http://{}", leader_data.rpc.to_string()); + let rpc_client = RpcClient::new(); assert_ne!(config_payer.id.pubkey(), config_witness.id.pubkey()); - let last_id = get_last_id(&rpc_addr).unwrap(); + let last_id = get_last_id(&rpc_client, &rpc_addr).unwrap(); let transaction = request_airdrop_transaction(&drone_addr, &config_payer.id.pubkey(), 50, last_id) .unwrap(); - send_and_confirm_tx(&rpc_addr, &transaction).unwrap(); + send_and_confirm_tx(&rpc_client, &rpc_addr, &transaction).unwrap(); // Make transaction (from config_payer to bob_pubkey) requiring witness signature from config_witness config_payer.command = WalletCommand::Pay( @@ -1430,21 +1448,21 @@ mod tests { let params = json!([format!("{}", config_payer.id.pubkey())]); let config_payer_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(config_payer_balance, 39); let params = json!([format!("{}", process_id)]); let contract_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(contract_balance, 11); let params = json!([format!("{}", bob_pubkey)]); let recipient_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); @@ -1457,21 +1475,21 @@ mod tests { let params = json!([format!("{}", config_payer.id.pubkey())]); let config_payer_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(config_payer_balance, 39); let params = json!([format!("{}", process_id)]); let contract_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(contract_balance, 1); let params = json!([format!("{}", bob_pubkey)]); let recipient_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); @@ -1517,6 +1535,7 @@ mod tests { let drone_addr = receiver.recv().unwrap(); let rpc_addr = format!("http://{}", leader_data.rpc.to_string()); + let rpc_client = RpcClient::new(); let mut config_payer = WalletConfig::default(); config_payer.network = leader_data.ncp; @@ -1528,11 +1547,11 @@ mod tests { assert_ne!(config_payer.id.pubkey(), config_witness.id.pubkey()); - let last_id = get_last_id(&rpc_addr).unwrap(); + let last_id = get_last_id(&rpc_client, &rpc_addr).unwrap(); let transaction = request_airdrop_transaction(&drone_addr, &config_payer.id.pubkey(), 50, last_id) .unwrap(); - send_and_confirm_tx(&rpc_addr, &transaction).unwrap(); + send_and_confirm_tx(&rpc_client, &rpc_addr, &transaction).unwrap(); // Make transaction (from config_payer to bob_pubkey) requiring witness signature from config_witness config_payer.command = WalletCommand::Pay( @@ -1555,21 +1574,21 @@ mod tests { let params = json!([format!("{}", config_payer.id.pubkey())]); let config_payer_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(config_payer_balance, 39); let params = json!([format!("{}", process_id)]); let contract_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(contract_balance, 11); let params = json!([format!("{}", bob_pubkey)]); let recipient_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); @@ -1582,21 +1601,21 @@ mod tests { let params = json!([format!("{}", config_payer.id.pubkey())]); let config_payer_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(config_payer_balance, 49); let params = json!([format!("{}", process_id)]); let contract_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap(); assert_eq!(contract_balance, 1); let params = json!([format!("{}", bob_pubkey)]); let recipient_balance = RpcRequest::GetBalance - .make_rpc_request(&rpc_addr, 1, Some(params)) + .make_rpc_request(&rpc_client, &rpc_addr, 1, Some(params)) .unwrap() .as_u64() .unwrap();