client/: get_transaction_count() now returns a Result
This commit is contained in:
parent
73ceaf07b1
commit
ac03c59b41
|
@ -54,14 +54,14 @@ pub fn sample_tx_count(
|
||||||
) {
|
) {
|
||||||
let client = create_client(v.client_facing_addr(), FULLNODE_PORT_RANGE);
|
let client = create_client(v.client_facing_addr(), FULLNODE_PORT_RANGE);
|
||||||
let mut now = Instant::now();
|
let mut now = Instant::now();
|
||||||
let mut initial_tx_count = client.transaction_count();
|
let mut initial_tx_count = client.get_transaction_count().expect("transaction count");
|
||||||
let mut max_tps = 0.0;
|
let mut max_tps = 0.0;
|
||||||
let mut total;
|
let mut total;
|
||||||
|
|
||||||
let log_prefix = format!("{:21}:", v.tpu.to_string());
|
let log_prefix = format!("{:21}:", v.tpu.to_string());
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let tx_count = client.transaction_count();
|
let tx_count = client.get_transaction_count().expect("transaction count");
|
||||||
assert!(
|
assert!(
|
||||||
tx_count >= initial_tx_count,
|
tx_count >= initial_tx_count,
|
||||||
"expected tx_count({}) >= initial_tx_count({})",
|
"expected tx_count({}) >= initial_tx_count({})",
|
||||||
|
|
|
@ -106,7 +106,7 @@ fn main() {
|
||||||
let mut blockhash = client.get_recent_blockhash();
|
let mut blockhash = client.get_recent_blockhash();
|
||||||
println!("Got last ID {:?}", blockhash);
|
println!("Got last ID {:?}", blockhash);
|
||||||
|
|
||||||
let first_tx_count = client.transaction_count();
|
let first_tx_count = client.get_transaction_count().expect("transaction count");
|
||||||
println!("Initial transaction count {}", first_tx_count);
|
println!("Initial transaction count {}", first_tx_count);
|
||||||
|
|
||||||
let exit_signal = Arc::new(AtomicBool::new(false));
|
let exit_signal = Arc::new(AtomicBool::new(false));
|
||||||
|
|
|
@ -102,23 +102,28 @@ impl RpcClient {
|
||||||
|
|
||||||
/// Request the transaction count. If the response packet is dropped by the network,
|
/// Request the transaction count. If the response packet is dropped by the network,
|
||||||
/// this method will try again 5 times.
|
/// this method will try again 5 times.
|
||||||
pub fn transaction_count(&self) -> u64 {
|
pub fn get_transaction_count(&self) -> Result<u64, Box<dyn error::Error>> {
|
||||||
debug!("transaction_count");
|
debug!("get_transaction_count");
|
||||||
for _tries in 0..5 {
|
|
||||||
|
let mut num_retries = 5;
|
||||||
|
loop {
|
||||||
let response = self.client.send(&RpcRequest::GetTransactionCount, None, 0);
|
let response = self.client.send(&RpcRequest::GetTransactionCount, None, 0);
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
debug!("transaction_count response: {:?}", value);
|
debug!("transaction_count response: {:?}", value);
|
||||||
let transaction_count = value.as_u64().unwrap();
|
let transaction_count = value.as_u64().unwrap();
|
||||||
return transaction_count;
|
return Ok(transaction_count);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
debug!("transaction_count failed: {:?}", err);
|
||||||
|
num_retries -= 1;
|
||||||
|
if num_retries == 0 {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(error) => {
|
|
||||||
debug!("transaction_count failed: {:?}", error);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request the last Entry ID from the server without blocking.
|
/// Request the last Entry ID from the server without blocking.
|
||||||
|
|
|
@ -15,7 +15,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::timing;
|
use solana_sdk::timing;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std;
|
use std::error;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::{SocketAddr, UdpSocket};
|
use std::net::{SocketAddr, UdpSocket};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
@ -141,8 +141,8 @@ impl ThinClient {
|
||||||
self.rpc_client.get_balance(pubkey)
|
self.rpc_client.get_balance(pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transaction_count(&self) -> u64 {
|
pub fn get_transaction_count(&self) -> Result<u64, Box<dyn error::Error>> {
|
||||||
self.rpc_client.transaction_count()
|
self.rpc_client.get_transaction_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_get_recent_blockhash(&self, num_retries: u64) -> Option<Hash> {
|
pub fn try_get_recent_blockhash(&self, num_retries: u64) -> Option<Hash> {
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn test_thin_client_basic() {
|
||||||
|
|
||||||
let client = create_client(leader_data.client_facing_addr(), FULLNODE_PORT_RANGE);
|
let client = create_client(leader_data.client_facing_addr(), FULLNODE_PORT_RANGE);
|
||||||
|
|
||||||
let transaction_count = client.transaction_count();
|
let transaction_count = client.get_transaction_count().unwrap();
|
||||||
assert_eq!(transaction_count, 0);
|
assert_eq!(transaction_count, 0);
|
||||||
|
|
||||||
let blockhash = client.get_recent_blockhash();
|
let blockhash = client.get_recent_blockhash();
|
||||||
|
@ -40,7 +40,7 @@ fn test_thin_client_basic() {
|
||||||
let balance = client.get_balance(&bob_pubkey);
|
let balance = client.get_balance(&bob_pubkey);
|
||||||
assert_eq!(balance.unwrap(), 500);
|
assert_eq!(balance.unwrap(), 500);
|
||||||
|
|
||||||
let transaction_count = client.transaction_count();
|
let transaction_count = client.get_transaction_count().unwrap();
|
||||||
assert_eq!(transaction_count, 1);
|
assert_eq!(transaction_count, 1);
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -144,7 +144,7 @@ fn test_transaction_count() {
|
||||||
transactions_socket,
|
transactions_socket,
|
||||||
Duration::from_secs(2),
|
Duration::from_secs(2),
|
||||||
);
|
);
|
||||||
assert_eq!(client.transaction_count(), 0);
|
client.get_transaction_count().unwrap_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue