2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-09 19:10:47 +00:00

cmd/loop: warn user if fee estimation fails

This commit is contained in:
Oliver Gugger 2020-02-21 10:34:08 +01:00
parent 3dd10f14dc
commit acdd2a22b2
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
3 changed files with 30 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swap" "github.com/lightninglabs/loop/swap"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
@ -76,6 +77,18 @@ func loopIn(ctx *cli.Context) error {
return err 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) limits := getInLimits(amt, quote)
err = displayLimits(swap.TypeIn, amt, limits, external, "") err = displayLimits(swap.TypeIn, amt, limits, external, "")
if err != nil { if err != nil {

View File

@ -159,9 +159,8 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
"wallet.\n\n") "wallet.\n\n")
} }
fmt.Printf("Max swap fees for %d Loop %v: %d\n", fmt.Printf("Max swap fees for %d Loop %v: %d\n", amt, swapType,
amt, swapType, totalSuccessMax, totalSuccessMax)
)
if warning != "" { if warning != "" {
fmt.Println(warning) fmt.Println(warning)

View File

@ -2,8 +2,11 @@ package main
import ( import (
"context" "context"
"fmt"
"os"
"time" "time"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/looprpc"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -59,6 +62,18 @@ func quoteIn(ctx *cli.Context) error {
return err 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) printRespJSON(quoteResp)
return nil return nil
} }