From 90836b572f20ecafb7c8594cfd38e79c06e94c6c Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 19 Oct 2020 06:17:13 -0700 Subject: [PATCH] tx_signer: fix retry-on-error behavior 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. --- src/tx_signer.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tx_signer.rs b/src/tx_signer.rs index 114a2045..61011c01 100644 --- a/src/tx_signer.rs +++ b/src/tx_signer.rs @@ -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? }