Skip to content

Commit 3dd10f1

Browse files
committed
client: return miner fee of -1 if fee estimation fails
1 parent f5fbf66 commit 3dd10f1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

client.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/hex"
66
"errors"
77
"fmt"
8+
"strings"
89
"sync"
910
"sync/atomic"
1011
"time"
@@ -59,6 +60,11 @@ var (
5960
globalCallTimeout = serverRPCTimeout + lsat.PaymentTimeout
6061

6162
republishDelay = 10 * time.Second
63+
64+
// MinerFeeEstimationFailed is a magic number that is returned in a
65+
// quote call as the miner fee if the fee estimation in lnd's wallet
66+
// failed because of insufficient funds.
67+
MinerFeeEstimationFailed btcutil.Amount = -1
6268
)
6369

6470
// Client performs the client side part of swaps. This interface exists to be
@@ -505,10 +511,24 @@ func (s *Client) LoopInQuote(ctx context.Context,
505511
}, nil
506512
}
507513

508-
// Get estimate for miner fee.
514+
// Get estimate for miner fee. If estimating the miner fee for the
515+
// requested amount is not possible because lnd's wallet cannot
516+
// construct a sample TX, we just return zero instead of failing the
517+
// quote. The user interface should inform the user that fee estimation
518+
// was not possible.
519+
//
520+
// TODO(guggero): Thread through error code from lnd to avoid string
521+
// matching.
509522
minerFee, err := s.lndServices.Client.EstimateFeeToP2WSH(
510523
ctx, request.Amount, request.HtlcConfTarget,
511524
)
525+
if err != nil && strings.Contains(err.Error(), "insufficient funds") {
526+
return &LoopInQuote{
527+
SwapFee: swapFee,
528+
MinerFee: MinerFeeEstimationFailed,
529+
CltvDelta: quote.CltvDelta,
530+
}, nil
531+
}
512532
if err != nil {
513533
return nil, err
514534
}

0 commit comments

Comments
 (0)