Remove client resends (#12290)

* Remove resends from client send_tx methods

* Retry status queries until blockhash expires
This commit is contained in:
Tyera Eulberg 2020-09-16 17:47:55 -06:00 committed by GitHub
parent 3ecb390b10
commit a79790dea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 69 additions and 85 deletions

View File

@ -411,15 +411,19 @@ impl RpcClient {
&self, &self,
transaction: &Transaction, transaction: &Transaction,
) -> ClientResult<Signature> { ) -> ClientResult<Signature> {
let mut send_retries = 20;
loop {
let mut status_retries = 15;
let signature = self.send_transaction(transaction)?; let signature = self.send_transaction(transaction)?;
let recent_blockhash = transaction.message.recent_blockhash;
let status = loop { let status = loop {
let status = self.get_signature_status(&signature)?; let status = self.get_signature_status(&signature)?;
if status.is_none() { if status.is_none() {
status_retries -= 1; if self
if status_retries == 0 { .get_fee_calculator_for_blockhash_with_commitment(
&recent_blockhash,
CommitmentConfig::recent(),
)?
.value
.is_none()
{
break status; break status;
} }
} else { } else {
@ -430,25 +434,19 @@ impl RpcClient {
sleep(Duration::from_millis(500)); sleep(Duration::from_millis(500));
} }
}; };
send_retries = if let Some(result) = status.clone() { if let Some(result) = status {
match result { match result {
Ok(_) => return Ok(signature), Ok(_) => Ok(signature),
Err(_) => 0, Err(err) => Err(err.into()),
} }
} else { } else {
send_retries - 1 Err(RpcError::ForUser(
}; "unable to confirm transaction. \
if send_retries == 0 {
if let Some(err) = status {
return Err(err.unwrap_err().into());
} else {
return Err(
RpcError::ForUser("unable to confirm transaction. \
This can happen in situations such as transaction expiration \ This can happen in situations such as transaction expiration \
and insufficient fee-payer funds".to_string()).into(), and insufficient fee-payer funds"
); .to_string(),
} )
} .into())
} }
} }
@ -1043,22 +1041,25 @@ impl RpcClient {
let progress_bar = new_spinner_progress_bar(); let progress_bar = new_spinner_progress_bar();
let mut send_retries = 20;
let signature = loop {
progress_bar.set_message(&format!( progress_bar.set_message(&format!(
"[{}/{}] Finalizing transaction {}", "[{}/{}] Finalizing transaction {}",
confirmations, desired_confirmations, transaction.signatures[0], confirmations, desired_confirmations, transaction.signatures[0],
)); ));
let mut status_retries = 15; let recent_blockhash = transaction.message.recent_blockhash;
let (signature, status) = loop {
let signature = self.send_transaction_with_config(transaction, config)?; let signature = self.send_transaction_with_config(transaction, config)?;
let (signature, status) = loop {
// Get recent commitment in order to count confirmations for successful transactions // Get recent commitment in order to count confirmations for successful transactions
let status = self let status =
.get_signature_status_with_commitment(&signature, CommitmentConfig::recent())?; self.get_signature_status_with_commitment(&signature, CommitmentConfig::recent())?;
if status.is_none() { if status.is_none() {
status_retries -= 1; if self
if status_retries == 0 { .get_fee_calculator_for_blockhash_with_commitment(
&recent_blockhash,
CommitmentConfig::recent(),
)?
.value
.is_none()
{
break (signature, status); break (signature, status);
} }
} else { } else {
@ -1069,36 +1070,19 @@ impl RpcClient {
sleep(Duration::from_millis(500)); sleep(Duration::from_millis(500));
} }
}; };
send_retries = if let Some(result) = status.clone() {
match result {
Ok(_) => 0,
// If transaction errors, return right away; no point in counting confirmations
Err(_) => 0,
}
} else {
send_retries - 1
};
if send_retries == 0 {
if let Some(result) = status { if let Some(result) = status {
match result { if let Err(err) = result {
Ok(_) => {
break signature;
}
Err(err) => {
return Err(err.into()); return Err(err.into());
} }
}
} else { } else {
return Err(RpcError::ForUser( return Err(RpcError::ForUser(
"unable to confirm transaction. \ "unable to confirm transaction. \
This can happen in situations such as transaction \ This can happen in situations such as transaction expiration \
expiration and insufficient fee-payer funds" and insufficient fee-payer funds"
.to_string(), .to_string(),
) )
.into()); .into());
} }
}
};
let now = Instant::now(); let now = Instant::now();
loop { loop {
match commitment.commitment { match commitment.commitment {