Clean up stray retry_get_balance() function
This commit is contained in:
parent
42cea7a785
commit
9632136cda
|
@ -204,6 +204,29 @@ impl RpcClient {
|
|||
self.poll_balance_with_timeout(pubkey, &Duration::from_millis(100), &Duration::from_secs(1))
|
||||
}
|
||||
|
||||
pub fn wait_for_balance(&self, pubkey: &Pubkey, expected_balance: Option<u64>) -> Option<u64> {
|
||||
const LAST: usize = 30;
|
||||
for run in 0..LAST {
|
||||
let balance_result = self.poll_get_balance(pubkey);
|
||||
if expected_balance.is_none() {
|
||||
return balance_result.ok();
|
||||
}
|
||||
trace!(
|
||||
"retry_get_balance[{}] {:?} {:?}",
|
||||
run,
|
||||
balance_result,
|
||||
expected_balance
|
||||
);
|
||||
if let (Some(expected_balance), Ok(balance_result)) = (expected_balance, balance_result)
|
||||
{
|
||||
if expected_balance == balance_result {
|
||||
return Some(balance_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Poll the server to confirm a transaction.
|
||||
pub fn poll_for_signature(&self, signature: &Signature) -> io::Result<()> {
|
||||
let now = Instant::now();
|
||||
|
|
|
@ -137,6 +137,10 @@ impl ThinClient {
|
|||
self.rpc_client.poll_get_balance(pubkey)
|
||||
}
|
||||
|
||||
pub fn wait_for_balance(&self, pubkey: &Pubkey, expected_balance: Option<u64>) -> Option<u64> {
|
||||
self.rpc_client.wait_for_balance(pubkey, expected_balance)
|
||||
}
|
||||
|
||||
pub fn poll_for_signature(&self, signature: &Signature) -> io::Result<()> {
|
||||
self.rpc_client.poll_for_signature(signature)
|
||||
}
|
||||
|
@ -163,29 +167,3 @@ pub fn create_client_with_timeout(
|
|||
let (_, transactions_socket) = solana_netutil::bind_in_range(range).unwrap();
|
||||
ThinClient::new_socket_with_timeout(rpc, tpu, transactions_socket, timeout)
|
||||
}
|
||||
|
||||
pub fn retry_get_balance(
|
||||
client: &ThinClient,
|
||||
bob_pubkey: &Pubkey,
|
||||
expected_balance: Option<u64>,
|
||||
) -> Option<u64> {
|
||||
const LAST: usize = 30;
|
||||
for run in 0..LAST {
|
||||
let balance_result = client.poll_get_balance(bob_pubkey);
|
||||
if expected_balance.is_none() {
|
||||
return balance_result.ok();
|
||||
}
|
||||
trace!(
|
||||
"retry_get_balance[{}] {:?} {:?}",
|
||||
run,
|
||||
balance_result,
|
||||
expected_balance
|
||||
);
|
||||
if let (Some(expected_balance), Ok(balance_result)) = (expected_balance, balance_result) {
|
||||
if expected_balance == balance_result {
|
||||
return Some(balance_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::gossip_service::discover;
|
|||
use crate::replicator::Replicator;
|
||||
use crate::service::Service;
|
||||
use solana_client::thin_client::create_client;
|
||||
use solana_client::thin_client::{retry_get_balance, ThinClient};
|
||||
use solana_client::thin_client::ThinClient;
|
||||
use solana_sdk::genesis_block::GenesisBlock;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
|
@ -209,7 +209,9 @@ impl LocalCluster {
|
|||
client
|
||||
.retry_transfer(&source_keypair, &mut tx, 5)
|
||||
.expect("client transfer");
|
||||
retry_get_balance(client, dest_pubkey, Some(lamports)).expect("get balance")
|
||||
client
|
||||
.wait_for_balance(dest_pubkey, Some(lamports))
|
||||
.expect("get balance")
|
||||
}
|
||||
|
||||
fn create_and_fund_vote_account(
|
||||
|
@ -234,7 +236,9 @@ impl LocalCluster {
|
|||
client
|
||||
.retry_transfer(&from_account, &mut transaction, 5)
|
||||
.expect("client transfer");
|
||||
retry_get_balance(client, &vote_account_pubkey, Some(amount)).expect("get balance");
|
||||
client
|
||||
.wait_for_balance(&vote_account_pubkey, Some(amount))
|
||||
.expect("get balance");
|
||||
|
||||
// 2) Set delegate for new vote account
|
||||
let mut transaction = VoteTransaction::delegate_vote_account(
|
||||
|
|
|
@ -14,7 +14,7 @@ use rand::thread_rng;
|
|||
use rand::Rng;
|
||||
use solana_client::rpc_client::RpcClient;
|
||||
use solana_client::rpc_request::RpcRequest;
|
||||
use solana_client::thin_client::{create_client, retry_get_balance, ThinClient};
|
||||
use solana_client::thin_client::{create_client, ThinClient};
|
||||
use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT};
|
||||
use solana_sdk::hash::{Hash, Hasher};
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||
|
@ -382,7 +382,7 @@ impl Replicator {
|
|||
keypair: &Keypair,
|
||||
cluster_entrypoint: &ContactInfo,
|
||||
) {
|
||||
if retry_get_balance(client, &keypair.pubkey(), None).is_none() {
|
||||
if client.wait_for_balance(&keypair.pubkey(), None).is_none() {
|
||||
let mut drone_addr = cluster_entrypoint.tpu;
|
||||
drone_addr.set_port(DRONE_PORT);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use solana::cluster_info::FULLNODE_PORT_RANGE;
|
|||
use solana::fullnode::new_fullnode_for_tests;
|
||||
use solana::gossip_service::discover;
|
||||
use solana_client::thin_client::create_client;
|
||||
use solana_client::thin_client::{retry_get_balance, ThinClient};
|
||||
use solana_client::thin_client::ThinClient;
|
||||
use solana_logger;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
@ -129,7 +129,8 @@ fn test_register_vote_account() {
|
|||
let signature = client.transfer_signed(&transaction).unwrap();
|
||||
client.poll_for_signature(&signature).unwrap();
|
||||
|
||||
let balance = retry_get_balance(&client, &vote_account_id, Some(1))
|
||||
let balance = client
|
||||
.wait_for_balance(&vote_account_id, Some(1))
|
||||
.expect("Expected balance for new account to exist");
|
||||
assert_eq!(balance, 1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue