Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet airdrop: Fetch a new last_id to prevent DuplicateSignature errors during AccountInUse retries #2171

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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