Skip to content

Commit acdd2a2

Browse files
committed
cmd/loop: warn user if fee estimation fails
1 parent 3dd10f1 commit acdd2a2

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

cmd/loop/loopin.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/btcsuite/btcutil"
8+
"github.com/lightninglabs/loop"
89
"github.com/lightninglabs/loop/looprpc"
910
"github.com/lightninglabs/loop/swap"
1011
"github.com/lightningnetwork/lnd/routing/route"
@@ -76,6 +77,18 @@ func loopIn(ctx *cli.Context) error {
7677
return err
7778
}
7879

80+
// For loop in, the fee estimation is handed to lnd which tries to
81+
// construct a real transaction to sample realistic fees to pay to the
82+
// HTLC. If the wallet doesn't have enough funds to create this TX, we
83+
// know it won't have enough to pay the real transaction either. It
84+
// makes sense to abort the loop in this case.
85+
if !external && quote.MinerFee == int64(loop.MinerFeeEstimationFailed) {
86+
return fmt.Errorf("miner fee estimation not " +
87+
"possible, lnd has insufficient funds to " +
88+
"create a sample transaction for selected " +
89+
"amount")
90+
}
91+
7992
limits := getInLimits(amt, quote)
8093
err = displayLimits(swap.TypeIn, amt, limits, external, "")
8194
if err != nil {

cmd/loop/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
159159
"wallet.\n\n")
160160
}
161161

162-
fmt.Printf("Max swap fees for %d Loop %v: %d\n",
163-
amt, swapType, totalSuccessMax,
164-
)
162+
fmt.Printf("Max swap fees for %d Loop %v: %d\n", amt, swapType,
163+
totalSuccessMax)
165164

166165
if warning != "" {
167166
fmt.Println(warning)

cmd/loop/quote.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package main
22

33
import (
44
"context"
5+
"fmt"
6+
"os"
57
"time"
68

9+
"github.com/lightninglabs/loop"
710
"github.com/lightninglabs/loop/looprpc"
811
"github.com/urfave/cli"
912
)
@@ -59,6 +62,18 @@ func quoteIn(ctx *cli.Context) error {
5962
return err
6063
}
6164

65+
// For loop in, the fee estimation is handed to lnd which tries to
66+
// construct a real transaction to sample realistic fees to pay to the
67+
// HTLC. If the wallet doesn't have enough funds to create this TX, we
68+
// don't want to fail the quote. But the user should still be informed
69+
// why the fee shows as -1.
70+
if quoteResp.MinerFee == int64(loop.MinerFeeEstimationFailed) {
71+
_, _ = fmt.Fprintf(os.Stderr, "Warning: Miner fee estimation "+
72+
"not possible, lnd has insufficient funds to "+
73+
"create a sample transaction for selected "+
74+
"amount.\n")
75+
}
76+
6277
printRespJSON(quoteResp)
6378
return nil
6479
}

0 commit comments

Comments
 (0)