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,44 +411,42 @@ impl RpcClient {
&self, &self,
transaction: &Transaction, transaction: &Transaction,
) -> ClientResult<Signature> { ) -> ClientResult<Signature> {
let mut send_retries = 20; let signature = self.send_transaction(transaction)?;
loop { let recent_blockhash = transaction.message.recent_blockhash;
let mut status_retries = 15; let status = loop {
let signature = self.send_transaction(transaction)?; let status = self.get_signature_status(&signature)?;
let status = loop { if status.is_none() {
let status = self.get_signature_status(&signature)?; if self
if status.is_none() { .get_fee_calculator_for_blockhash_with_commitment(
status_retries -= 1; &recent_blockhash,
if status_retries == 0 { CommitmentConfig::recent(),
break status; )?
} .value
} else { .is_none()
{
break status; break status;
} }
if cfg!(not(test)) {
// Retry twice a second
sleep(Duration::from_millis(500));
}
};
send_retries = if let Some(result) = status.clone() {
match result {
Ok(_) => return Ok(signature),
Err(_) => 0,
}
} else { } else {
send_retries - 1 break status;
};
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 \
and insufficient fee-payer funds".to_string()).into(),
);
}
} }
if cfg!(not(test)) {
// Retry twice a second
sleep(Duration::from_millis(500));
}
};
if let Some(result) = status {
match result {
Ok(_) => Ok(signature),
Err(err) => Err(err.into()),
}
} else {
Err(RpcError::ForUser(
"unable to confirm transaction. \
This can happen in situations such as transaction expiration \
and insufficient fee-payer funds"
.to_string(),
)
.into())
} }
} }
@ -1043,62 +1041,48 @@ impl RpcClient {
let progress_bar = new_spinner_progress_bar(); let progress_bar = new_spinner_progress_bar();
let mut send_retries = 20; progress_bar.set_message(&format!(
let signature = loop { "[{}/{}] Finalizing transaction {}",
progress_bar.set_message(&format!( confirmations, desired_confirmations, transaction.signatures[0],
"[{}/{}] Finalizing transaction {}", ));
confirmations, desired_confirmations, transaction.signatures[0], let recent_blockhash = transaction.message.recent_blockhash;
)); let signature = self.send_transaction_with_config(transaction, config)?;
let mut status_retries = 15; let (signature, status) = loop {
let (signature, status) = loop { // Get recent commitment in order to count confirmations for successful transactions
let signature = self.send_transaction_with_config(transaction, config)?; let status =
self.get_signature_status_with_commitment(&signature, CommitmentConfig::recent())?;
// Get recent commitment in order to count confirmations for successful transactions if status.is_none() {
let status = self if self
.get_signature_status_with_commitment(&signature, CommitmentConfig::recent())?; .get_fee_calculator_for_blockhash_with_commitment(
if status.is_none() { &recent_blockhash,
status_retries -= 1; CommitmentConfig::recent(),
if status_retries == 0 { )?
break (signature, status); .value
} .is_none()
} else { {
break (signature, status); break (signature, status);
} }
if cfg!(not(test)) {
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 { } else {
send_retries - 1 break (signature, status);
}; }
if send_retries == 0 {
if let Some(result) = status { if cfg!(not(test)) {
match result { sleep(Duration::from_millis(500));
Ok(_) => {
break signature;
}
Err(err) => {
return Err(err.into());
}
}
} else {
return Err(RpcError::ForUser(
"unable to confirm transaction. \
This can happen in situations such as transaction \
expiration and insufficient fee-payer funds"
.to_string(),
)
.into());
}
} }
}; };
if let Some(result) = status {
if let Err(err) = result {
return Err(err.into());
}
} else {
return Err(RpcError::ForUser(
"unable to confirm transaction. \
This can happen in situations such as transaction expiration \
and insufficient fee-payer funds"
.to_string(),
)
.into());
}
let now = Instant::now(); let now = Instant::now();
loop { loop {
match commitment.commitment { match commitment.commitment {