diff --git a/cmd/loop/loopin.go b/cmd/loop/loopin.go index 0cb4812..b8592c3 100644 --- a/cmd/loop/loopin.go +++ b/cmd/loop/loopin.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/btcsuite/btcutil" + "github.com/lightninglabs/loop" "github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/swap" "github.com/lightningnetwork/lnd/routing/route" @@ -76,6 +77,18 @@ func loopIn(ctx *cli.Context) error { return err } + // For loop in, the fee estimation is handed to lnd which tries to + // construct a real transaction to sample realistic fees to pay to the + // HTLC. If the wallet doesn't have enough funds to create this TX, we + // know it won't have enough to pay the real transaction either. It + // makes sense to abort the loop in this case. + if !external && quote.MinerFee == int64(loop.MinerFeeEstimationFailed) { + return fmt.Errorf("miner fee estimation not " + + "possible, lnd has insufficient funds to " + + "create a sample transaction for selected " + + "amount") + } + limits := getInLimits(amt, quote) err = displayLimits(swap.TypeIn, amt, limits, external, "") if err != nil { diff --git a/cmd/loop/main.go b/cmd/loop/main.go index b2a0d99..c8df8f1 100644 --- a/cmd/loop/main.go +++ b/cmd/loop/main.go @@ -159,9 +159,8 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits, "wallet.\n\n") } - fmt.Printf("Max swap fees for %d Loop %v: %d\n", - amt, swapType, totalSuccessMax, - ) + fmt.Printf("Max swap fees for %d Loop %v: %d\n", amt, swapType, + totalSuccessMax) if warning != "" { fmt.Println(warning) diff --git a/cmd/loop/quote.go b/cmd/loop/quote.go index 82a2342..ebef99a 100644 --- a/cmd/loop/quote.go +++ b/cmd/loop/quote.go @@ -2,8 +2,11 @@ package main import ( "context" + "fmt" + "os" "time" + "github.com/lightninglabs/loop" "github.com/lightninglabs/loop/looprpc" "github.com/urfave/cli" ) @@ -59,6 +62,18 @@ func quoteIn(ctx *cli.Context) error { return err } + // For loop in, the fee estimation is handed to lnd which tries to + // construct a real transaction to sample realistic fees to pay to the + // HTLC. If the wallet doesn't have enough funds to create this TX, we + // don't want to fail the quote. But the user should still be informed + // why the fee shows as -1. + if quoteResp.MinerFee == int64(loop.MinerFeeEstimationFailed) { + _, _ = fmt.Fprintf(os.Stderr, "Warning: Miner fee estimation "+ + "not possible, lnd has insufficient funds to "+ + "create a sample transaction for selected "+ + "amount.\n") + } + printRespJSON(quoteResp) return nil }