From e0feb85b2099217d77b2aef5ad16a5fe1016a255 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 26 Sep 2022 15:30:38 +0300 Subject: [PATCH] fail if transaction submit has failed (#1584) --- relays/messages/src/message_race_loop.rs | 2 +- relays/utils/src/lib.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/relays/messages/src/message_race_loop.rs b/relays/messages/src/message_race_loop.rs index a68efbfd1938..546e283ceab2 100644 --- a/relays/messages/src/message_race_loop.rs +++ b/relays/messages/src/message_race_loop.rs @@ -416,7 +416,7 @@ pub async fn run, TC: TargetClient

>( &mut target_go_offline_future, async_std::task::sleep, || format!("Error submitting proof {}", P::target_name()), - ).fail_if_connection_error(FailedClient::Target)?; + ).fail_if_error(FailedClient::Target).map(|_| true)?; }, target_transaction_status = target_tx_tracker => { if target_transaction_status == TrackedTransactionStatus::Lost { diff --git a/relays/utils/src/lib.rs b/relays/utils/src/lib.rs index dbc8e5df8218..b19b9cd44988 100644 --- a/relays/utils/src/lib.rs +++ b/relays/utils/src/lib.rs @@ -236,6 +236,16 @@ impl ProcessFutureResult { } } + /// Returns `Ok(())` if future has succeeded. + /// Returns `Err(failed_client)` otherwise. + pub fn fail_if_error(self, failed_client: FailedClient) -> Result<(), FailedClient> { + if self.is_ok() { + Ok(()) + } else { + Err(failed_client) + } + } + /// Returns Ok(true) if future has succeeded. /// Returns Ok(false) if future has failed with non-connection error. /// Returns Err if future is `ConnectionFailed`.