Skip to content

Commit

Permalink
Fetch a new last_id to prevent DuplicateSignature errors during Accou…
Browse files Browse the repository at this point in the history
…ntInUse retries
  • Loading branch information
mvines authored and solana-grimes committed Dec 14, 2018
1 parent 6ac466c commit 8fcb711
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@ fn request_and_confirm_airdrop(
tokens: u64,
) -> Result<(), Box<dyn error::Error>> {
let mut last_id = get_last_id(rpc_client)?;
let mut tx = request_airdrop_transaction(drone_addr, id, tokens, last_id)?;
let mut send_retries = 3;
while send_retries > 0 {
loop {
let tx = request_airdrop_transaction(drone_addr, id, tokens, last_id)?;
let mut status_retries = 4;
let signature_str = send_tx(rpc_client, &tx)?;
let status = loop {
Expand All @@ -766,25 +766,42 @@ fn request_and_confirm_airdrop(
};
match status {
RpcSignatureStatus::AccountInUse => {
last_id = get_last_id(rpc_client)?;
tx = request_airdrop_transaction(drone_addr, id, tokens, last_id)?;
// Fetch a new last_id to prevent the retry from getting rejected as a
// DuplicateSignature
let mut next_last_id_retries = 3;
loop {
let next_last_id = get_last_id(rpc_client)?;
if next_last_id != last_id {
last_id = next_last_id;
break;
}
if next_last_id_retries == 0 {
Err(WalletError::RpcRequestError(
"Unable to fetch next last_id".to_string(),
))?;
}
next_last_id_retries -= 1;
sleep(Duration::from_secs(1));
}
send_retries -= 1;
if send_retries == 0 {
Err(WalletError::RpcRequestError(format!(
"AccountInUse after 3 retries: {:?}",
tx.account_keys[0]
)))?
}
}
RpcSignatureStatus::Confirmed => {
return Ok(());
}
_ => {
return Err(WalletError::RpcRequestError(format!(
Err(WalletError::RpcRequestError(format!(
"Transaction {:?} failed: {:?}",
signature_str, status
)))?;
}
}
}
Err(WalletError::RpcRequestError(format!(
"AccountInUse after 3 retries: {:?}",
tx.account_keys[0]
)))?
}

#[cfg(test)]
Expand Down

0 comments on commit 8fcb711

Please sign in to comment.