From 913cb3728d6e2f76129de2a2f3da1d905b8cdcee Mon Sep 17 00:00:00 2001 From: yse Date: Fri, 20 Sep 2024 15:38:12 +0200 Subject: [PATCH] fix: remove warning logs when Pending swap has not expired --- lib/core/src/chain_swap.rs | 24 +++++++----------------- lib/core/src/send_swap.rs | 14 ++++++-------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index 4a0608551..5a6126b16 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -942,20 +942,16 @@ impl ChainSwapHandler { } let has_swap_expired = self.check_swap_expiry(&swap).await.unwrap_or(false); + + if !has_swap_expired && swap.direction == Direction::Outgoing && swap.state == Pending { + continue; + } + match swap.direction { // Track refunds Direction::Outgoing => { let refund_tx_id_result: Result = match swap.state { - Pending => { - if !has_swap_expired { - warn!( - "Cannot refund non-cooperatively: Locktime for pending outgoing Chain swap {} has not elapsed yet.", - swap.id - ); - continue; - } - self.refund_outgoing_swap(&swap, false).await - } + Pending => self.refund_outgoing_swap(&swap, false).await, RefundPending => match has_swap_expired { true => { self.refund_outgoing_swap(&swap, true) @@ -965,10 +961,6 @@ impl ChainSwapHandler { false => self.refund_outgoing_swap(&swap, true).await, }, _ => { - warn!( - "Invalid outgoing Chain swap state for swap {} when attempting to refund, state: {:?}", - swap.id, swap.state - ); continue; } }; @@ -995,9 +987,7 @@ impl ChainSwapHandler { // Track refundables by verifying that the expiry has elapsed, and set the state of the incoming swap to `Refundable` Direction::Incoming => { - if swap.user_lockup_tx_id.is_some() - && self.check_swap_expiry(&swap).await.unwrap_or(false) - { + if swap.user_lockup_tx_id.is_some() && has_swap_expired { let update_swap_info_result = self .update_swap_info(&swap.id, Refundable, None, None, None, None) .await; diff --git a/lib/core/src/send_swap.rs b/lib/core/src/send_swap.rs index 485bf8a1c..dd2ec6721 100644 --- a/lib/core/src/send_swap.rs +++ b/lib/core/src/send_swap.rs @@ -446,15 +446,13 @@ impl SendSwapHandler { } let has_swap_expired = self.check_swap_expiry(swap).await.unwrap_or(false); - let refund_tx_id_result = match swap.state { - Pending => { - if !has_swap_expired { - warn!("Cannot refund non-cooperatively: Locktime for pending Send swap {} has not elapsed yet.", swap.id); - continue; - } - self.refund(swap, false).await - } + if !has_swap_expired && swap.state == Pending { + continue; + } + + let refund_tx_id_result = match swap.state { + Pending => self.refund(swap, false).await, RefundPending => match has_swap_expired { true => { self.refund(swap, true)