diff --git a/lnd/client.go b/lnd/client.go index b360d14e..18c50007 100644 --- a/lnd/client.go +++ b/lnd/client.go @@ -131,7 +131,7 @@ func (l *Client) SpendableMsat(scid string) (uint64, error) { return 0, err } spendable := (uint64(ch.GetLocalBalance()) - - ch.GetLocalConstraints().GetChanReserveSat()*1000) + ch.GetLocalConstraints().GetChanReserveSat()) * 1000 // since the max htlc limit is not always set reliably, // the check is skipped if it is not set. if maxHtlcAmtMsat == 0 { @@ -168,7 +168,7 @@ func (l *Client) ReceivableMsat(scid string) (uint64, error) { return 0, err } receivable := (uint64(ch.GetRemoteBalance()) - - ch.GetRemoteConstraints().GetChanReserveSat()*1000) + ch.GetRemoteConstraints().GetChanReserveSat()) * 1000 // since the max htlc limit is not always set reliably, // the check is skipped if it is not set. if maxHtlcAmtMsat == 0 { diff --git a/swap/actions.go b/swap/actions.go index a043ea96..c08e5f6b 100644 --- a/swap/actions.go +++ b/swap/actions.go @@ -589,20 +589,29 @@ func (r *PayFeeInvoiceAction) Execute(services *SwapServices, swap *SwapData) Ev } ll := services.lightning - // policy := services.policy + _, msatAmt, _, err := ll.DecodePayreq(swap.SwapOutAgreement.Payreq) if err != nil { return swap.HandleError(err) } + sp, err := ll.SpendableMsat(swap.SwapOutRequest.Scid) if err != nil { return swap.HandleError(err) } - if sp <= swap.SwapOutRequest.Amount*1000 { - return swap.HandleError(err) + // Calculate the total required balance + // This includes the swap amount (multiplied by 1000 to convert from sat to msat) + // plus the fee in millisatoshis + requiredBalance := swap.SwapOutRequest.Amount*1000 + msatAmt + + // Check if the spendable balance (sp) is sufficient + if sp <= requiredBalance { + return swap.HandleError(fmt.Errorf("not enough spendable msat: %d, expected: %d", sp, requiredBalance)) } - success, failureReason, err := ll.ProbePayment(swap.SwapOutRequest.Scid, swap.SwapOutRequest.Amount*1000) + + // Probe the payment to check if it's possible + success, failureReason, err := ll.ProbePayment(swap.SwapOutRequest.Scid, requiredBalance) if err != nil { return swap.HandleError(err) } diff --git a/swap/service.go b/swap/service.go index a5c55fdf..7f6ac99b 100644 --- a/swap/service.go +++ b/swap/service.go @@ -391,14 +391,6 @@ func (s *SwapService) SwapOut(peer string, chain string, channelId string, initi return nil, fmt.Errorf("exceeding spendable amount_msat: %d", sp) } - success, failureReason, err := s.swapServices.lightning.ProbePayment(channelId, amtSat*1000) - if err != nil { - return nil, err - } - if !success { - return nil, fmt.Errorf("the prepayment probe was unsuccessful: %s", failureReason) - } - swap := newSwapOutSenderFSM(s.swapServices, initiator, peer) err = s.lockSwap(swap.SwapId.String(), channelId, swap) if err != nil {