Remove unnecessary retrying (#4219)
This commit is contained in:
parent
518227eac0
commit
5a86f2506d
|
@ -4,7 +4,6 @@ use crate::mock_rpc_client_request::MockRpcClientRequest;
|
||||||
use crate::rpc_client_request::RpcClientRequest;
|
use crate::rpc_client_request::RpcClientRequest;
|
||||||
use crate::rpc_request::RpcRequest;
|
use crate::rpc_request::RpcRequest;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use bs58;
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
|
@ -255,53 +254,40 @@ 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 get_transaction_count(&self) -> io::Result<u64> {
|
pub fn get_transaction_count(&self) -> io::Result<u64> {
|
||||||
debug!("get_transaction_count");
|
let response = self
|
||||||
|
.client
|
||||||
let mut num_retries = 5;
|
.send(&RpcRequest::GetTransactionCount, None, 0)
|
||||||
while num_retries > 0 {
|
.map_err(|err| {
|
||||||
let response = self.client.send(&RpcRequest::GetTransactionCount, None, 0);
|
io::Error::new(
|
||||||
|
|
||||||
match response {
|
|
||||||
Ok(value) => {
|
|
||||||
debug!("transaction_count response: {:?}", value);
|
|
||||||
if let Some(transaction_count) = value.as_u64() {
|
|
||||||
return Ok(transaction_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
debug!("transaction_count failed: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
num_retries -= 1;
|
|
||||||
}
|
|
||||||
Err(io::Error::new(
|
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"Unable to get transaction count, too many retries",
|
format!("GetTransactionCount request failure: {:?}", err),
|
||||||
))?
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
serde_json::from_value(response).map_err(|error| {
|
||||||
|
debug!("ParseError: get_transaction_count: {}", error);
|
||||||
|
io::Error::new(io::ErrorKind::Other, "GetTransactionCount parse failure")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_recent_blockhash(&self) -> io::Result<Hash> {
|
pub fn get_recent_blockhash(&self) -> io::Result<Hash> {
|
||||||
let mut num_retries = 5;
|
let response = self
|
||||||
while num_retries > 0 {
|
.client
|
||||||
match self.client.send(&RpcRequest::GetRecentBlockhash, None, 0) {
|
.send(&RpcRequest::GetRecentBlockhash, None, 0)
|
||||||
Ok(value) => {
|
.map_err(|err| {
|
||||||
if let Some(blockhash_str) = value.as_str() {
|
io::Error::new(
|
||||||
let blockhash_vec = bs58::decode(blockhash_str)
|
|
||||||
.into_vec()
|
|
||||||
.expect("bs58::decode");
|
|
||||||
return Ok(Hash::new(&blockhash_vec));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
debug!("retry_get_recent_blockhash failed: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
num_retries -= 1;
|
|
||||||
}
|
|
||||||
Err(io::Error::new(
|
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"Unable to get recent blockhash, too many retries",
|
format!("GetRecentBlockhash request failure: {:?}", err),
|
||||||
))
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
response
|
||||||
|
.as_str()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
io::Error::new(io::ErrorKind::Other, "GetRecentBlockhash parse failure")
|
||||||
|
})?
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| io::Error::new(io::ErrorKind::Other, "GetRecentBlockhash parse failure"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_new_blockhash(&self, blockhash: &Hash) -> io::Result<Hash> {
|
pub fn get_new_blockhash(&self, blockhash: &Hash) -> io::Result<Hash> {
|
||||||
|
|
Loading…
Reference in New Issue