From 1e949caa7fedbfca1ab67851f638e524e51772cb Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 9 May 2019 09:48:27 -0700 Subject: [PATCH] Move airdrop retries fully out of bash (#4234) automerge --- multinode-demo/fullnode.sh | 31 +------------------------------ wallet/src/wallet.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/multinode-demo/fullnode.sh b/multinode-demo/fullnode.sh index cf2e18940..4c9800368 100755 --- a/multinode-demo/fullnode.sh +++ b/multinode-demo/fullnode.sh @@ -70,35 +70,6 @@ rsync_url() { # adds the 'rsync://` prefix to URLs that need it echo "rsync://$url" } -airdrop() { - declare keypair_file=$1 - declare entrypoint_ip=$2 - declare amount=$3 - - declare address - address=$($solana_wallet --keypair "$keypair_file" address) - - # TODO: Until https://github.com/solana-labs/solana/issues/2355 is resolved - # a fullnode needs N lamports as its vote account gets re-created on every - # node restart, costing it lamports - declare retries=5 - - while ! $solana_wallet --keypair "$keypair_file" --url "http://$entrypoint_ip:8899" airdrop "$amount"; do - - # TODO: Consider moving this retry logic into `solana-wallet airdrop` - # itself, currently it does not retry on "Connection refused" errors. - ((retries--)) - if [[ $retries -le 0 ]]; then - echo "Airdrop to $address failed." - return 1 - fi - echo "Airdrop to $address failed. Remaining retries: $retries" - sleep 1 - done - - return 0 -} - setup_vote_account() { declare entrypoint_ip=$1 declare node_keypair_path=$2 @@ -114,7 +85,7 @@ setup_vote_account() { if [[ -f "$vote_keypair_path".configured ]]; then echo "Vote account has already been configured" else - airdrop "$node_keypair_path" "$entrypoint_ip" "$stake" || return $? + $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" airdrop "$stake" || return $? # Fund the vote account from the node, with the node as the node_keypair $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 15f341466..c5e396373 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -30,6 +30,8 @@ use solana_vote_api::vote_instruction; use std::fs::File; use std::io::Read; use std::net::{IpAddr, SocketAddr}; +use std::thread::sleep; +use std::time::Duration; use std::{error, fmt, mem}; const USERDATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE @@ -776,7 +778,17 @@ pub fn request_and_confirm_airdrop( lamports: u64, ) -> Result<(), Box> { let blockhash = rpc_client.get_recent_blockhash()?; - let keypair = DroneKeypair::new_keypair(drone_addr, to_pubkey, lamports, blockhash)?; + let keypair = { + let mut retries = 5; + loop { + let result = DroneKeypair::new_keypair(drone_addr, to_pubkey, lamports, blockhash); + if result.is_ok() || retries == 0 { + break result; + } + retries -= 1; + sleep(Duration::from_secs(1)); + } + }?; let mut tx = keypair.airdrop_transaction(); let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&keypair]); log_instruction_custom_error::(result)?;