Fetch a new last_id to prevent DuplicateSignature errors during AccountInUse retries
This commit is contained in:
parent
6ac466c0a4
commit
8fcb7112ec
|
@ -747,9 +747,9 @@ fn request_and_confirm_airdrop(
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
) -> Result<(), Box<dyn error::Error>> {
|
) -> Result<(), Box<dyn error::Error>> {
|
||||||
let mut last_id = get_last_id(rpc_client)?;
|
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;
|
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 mut status_retries = 4;
|
||||||
let signature_str = send_tx(rpc_client, &tx)?;
|
let signature_str = send_tx(rpc_client, &tx)?;
|
||||||
let status = loop {
|
let status = loop {
|
||||||
|
@ -766,25 +766,42 @@ fn request_and_confirm_airdrop(
|
||||||
};
|
};
|
||||||
match status {
|
match status {
|
||||||
RpcSignatureStatus::AccountInUse => {
|
RpcSignatureStatus::AccountInUse => {
|
||||||
last_id = get_last_id(rpc_client)?;
|
// Fetch a new last_id to prevent the retry from getting rejected as a
|
||||||
tx = request_airdrop_transaction(drone_addr, id, tokens, last_id)?;
|
// 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;
|
send_retries -= 1;
|
||||||
|
if send_retries == 0 {
|
||||||
|
Err(WalletError::RpcRequestError(format!(
|
||||||
|
"AccountInUse after 3 retries: {:?}",
|
||||||
|
tx.account_keys[0]
|
||||||
|
)))?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RpcSignatureStatus::Confirmed => {
|
RpcSignatureStatus::Confirmed => {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(WalletError::RpcRequestError(format!(
|
Err(WalletError::RpcRequestError(format!(
|
||||||
"Transaction {:?} failed: {:?}",
|
"Transaction {:?} failed: {:?}",
|
||||||
signature_str, status
|
signature_str, status
|
||||||
)))?;
|
)))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(WalletError::RpcRequestError(format!(
|
|
||||||
"AccountInUse after 3 retries: {:?}",
|
|
||||||
tx.account_keys[0]
|
|
||||||
)))?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue