Skip to content

Commit

Permalink
tx_signer: fix retry-on-error behavior
Browse files Browse the repository at this point in the history
Fixes the logic to retry failed transactions at a higher sequence number
if the previous attempts to broadcast a transaction resulted in an
error.

Prior to this commit, the logic was never triggered as it needed to
store whether or not the prior transaction succeeded before performing a
new one.
  • Loading branch information
tony-iqlusion committed Oct 19, 2020
1 parent 3e2e752 commit 90836b5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/tx_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,26 @@ impl TxSigner {
let seq = self.seq_file.sequence();
let sign_msg = SignMsg::new(&tx_req, &self.tx_builder, seq)?;

// If no transaction broadcasted successfully before, retry with a
// higher sequence number to see if we're out-of-sync
// TODO(tarcieri): handle these errors by querying sequence number via RPC
let retry_on_failure = !self.last_tx.is_response();

if let Err(e) = self.broadcast_tx(sign_msg, seq).await {
error!("[{}] {} - {}", &self.chain_id, self.source.uri(), e);

// If the last transaction errored, speculatively try the next
// sequence number, as the previous transaction may have been
// successfully broadcast but we never got a response.
if !self.last_tx.is_response() {
if retry_on_failure {
let seq = seq.checked_add(1).unwrap();
warn!(
"[{}] {} - retrying transaction at sequence {}",
&self.chain_id,
self.source.uri(),
seq
);

let sign_msg = SignMsg::new(&tx_req, &self.tx_builder, seq)?;
self.broadcast_tx(sign_msg, seq).await?
}
Expand Down

0 comments on commit 90836b5

Please sign in to comment.