From 4cd9813b0c60eac91ef0638f1d79406bf9ab8df4 Mon Sep 17 00:00:00 2001 From: Kiril Mihaylov <80464733+KirilMihaylov@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:49:40 +0300 Subject: [PATCH] refactor(chain-ops): Add `consecutive_errors` as field of `Broadcast` and use it instead to more reliably keep track of errors. --- chain-ops/src/task/broadcast.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/chain-ops/src/task/broadcast.rs b/chain-ops/src/task/broadcast.rs index cc2a292..690b293 100644 --- a/chain-ops/src/task/broadcast.rs +++ b/chain-ops/src/task/broadcast.rs @@ -53,6 +53,7 @@ where transaction_rx: mpsc::UnboundedReceiver>, delay_duration: Duration, retry_delay_duration: Duration, + consecutive_errors: u8, } impl Broadcast @@ -73,6 +74,7 @@ where transaction_rx, delay_duration, retry_delay_duration, + consecutive_errors: 0, } } @@ -154,8 +156,6 @@ where ) -> Result<()> { const SIGNATURE_VERIFICATION_ERROR_CODE: u32 = 32; - let mut consecutive_sequence_mismatch: u8 = 0; - 'broadcast_loop: loop { let raw_tx = self .simulate_and_sign_tx( @@ -198,10 +198,9 @@ where Self::log_tx_response(source.as_ref(), tx_code, &response); if tx_code.is_err() { - consecutive_sequence_mismatch = - (consecutive_sequence_mismatch + 1) % 10; + self.consecutive_errors = (self.consecutive_errors + 1) % 5; - if consecutive_sequence_mismatch == 0 { + if self.consecutive_errors == 0 { self.fetch_sequence_number() .await .context("Failed to fetch sequence number!")?;