From 1d98777c202ad02bde1891598088efb13025873e Mon Sep 17 00:00:00 2001 From: Impa10r Date: Fri, 14 Feb 2025 19:38:22 +0100 Subject: [PATCH 1/2] Fix "exceeding amount_msat" check --- swap/service.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/swap/service.go b/swap/service.go index 0a6f9b90..fd2943da 100644 --- a/swap/service.go +++ b/swap/service.go @@ -396,7 +396,7 @@ func (s *SwapService) SwapOut(peer string, chain string, channelId string, initi if err != nil { return nil, err } - if sp <= amtSat*1000 { + if sp < amtSat*1000 { return nil, fmt.Errorf("exceeding spendable amount_msat: %d", sp) } @@ -460,7 +460,7 @@ func (s *SwapService) SwapIn(peer string, chain string, channelId string, initia if err != nil { return nil, err } - if rs <= amtSat*1000 { + if rs < amtSat*1000 { return nil, fmt.Errorf("exceeding receivable amount_msat: %d", rs) } maximumSwapAmountSat, err := s.estimateMaximumSwapAmountSat(chain) @@ -565,7 +565,7 @@ func (s *SwapService) OnSwapInRequestReceived(swapId *SwapId, peerId string, mes return err } - if sp <= message.Amount*1000 { + if sp < message.Amount*1000 { err = fmt.Errorf("exceeding spendable amount_msat: %d", sp) msg := fmt.Sprintf("from the %s peer: %s", s.swapServices.lightning.Implementation(), err.Error()) // We want to tell our peer why we can not do this swap. @@ -633,7 +633,7 @@ func (s *SwapService) OnSwapOutRequestReceived(swapId *SwapId, peerId string, me return err } - if rs <= message.Amount*1000 { + if rs < message.Amount*1000 { err = fmt.Errorf("exceeding receivable amount_msat: %d", rs) msg := fmt.Sprintf("from the %s peer: %s", s.swapServices.lightning.Implementation(), err.Error()) // We want to tell our peer why we can not do this swap. From ef79be4c0113ef198a8c37869962b77121467ff6 Mon Sep 17 00:00:00 2001 From: Impa10r Date: Sat, 15 Feb 2025 23:25:17 +0100 Subject: [PATCH 2/2] Reduce spendable required balance for swap out --- swap/actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap/actions.go b/swap/actions.go index 4ec93336..08a763ad 100644 --- a/swap/actions.go +++ b/swap/actions.go @@ -602,7 +602,7 @@ func (r *PayFeeInvoiceAction) Execute(services *SwapServices, swap *SwapData) Ev requiredBalance := swap.SwapOutRequest.Amount*1000 + msatAmt // Check if the spendable balance (sp) is sufficient - if sp <= requiredBalance { + if sp < requiredBalance { return swap.HandleError(fmt.Errorf("not enough spendable msat: %d, expected: %d", sp, requiredBalance)) }