Skip to content

Commit 0e09677

Browse files
authored
Merge pull request #86 from guggero/external-loop-in-fee-est
loopd: don't fail external loop in on fee estimation failure
2 parents fa1b86c + c00f831 commit 0e09677

File tree

11 files changed

+217
-466
lines changed

11 files changed

+217
-466
lines changed

client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ func (s *Client) LoopInQuote(ctx context.Context,
470470
request.Amount*btcutil.Amount(terms.SwapFeeRate)/
471471
btcutil.Amount(swap.FeeRateTotalParts)
472472

473+
// We don't calculate the on-chain fee if the HTLC is going to be
474+
// published externally.
475+
if request.ExternalHtlc {
476+
return &LoopInQuote{
477+
SwapFee: swapFee,
478+
MinerFee: 0,
479+
}, nil
480+
}
481+
473482
// Get estimate for miner fee.
474483
minerFee, err := s.lndServices.Client.EstimateFeeToP2WSH(
475484
ctx, request.Amount, request.HtlcConfTarget,

cmd/loop/loopin.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,29 @@ func loopIn(ctx *cli.Context) error {
5656
}
5757
defer cleanup()
5858

59+
external := ctx.Bool("external")
5960
quote, err := client.GetLoopInQuote(
6061
context.Background(),
6162
&looprpc.QuoteRequest{
62-
Amt: int64(amt),
63+
Amt: int64(amt),
64+
ExternalHtlc: external,
6365
},
6466
)
6567
if err != nil {
6668
return err
6769
}
6870

6971
limits := getInLimits(amt, quote)
70-
71-
if err := displayLimits(loop.TypeIn, amt, limits); err != nil {
72+
err = displayLimits(loop.TypeIn, amt, limits, external)
73+
if err != nil {
7274
return err
7375
}
7476

7577
resp, err := client.LoopIn(context.Background(), &looprpc.LoopInRequest{
7678
Amt: int64(amt),
7779
MaxMinerFee: int64(limits.maxMinerFee),
7880
MaxSwapFee: int64(limits.maxSwapFee),
79-
ExternalHtlc: ctx.Bool("external"),
81+
ExternalHtlc: external,
8082
})
8183
if err != nil {
8284
return err

cmd/loop/loopout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func loopOut(ctx *cli.Context) error {
9494

9595
limits := getLimits(amt, quote)
9696

97-
if err := displayLimits(loop.TypeOut, amt, limits); err != nil {
97+
if err := displayLimits(loop.TypeOut, amt, limits, false); err != nil {
9898
return err
9999
}
100100

cmd/loop/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,23 @@ func getLimits(amt btcutil.Amount, quote *looprpc.QuoteResponse) *limits {
116116
}
117117
}
118118

119-
func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits) error {
119+
func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits,
120+
externalHtlc bool) error {
121+
120122
totalSuccessMax := l.maxMinerFee + l.maxSwapFee
121123
if l.maxSwapRoutingFee != nil {
122124
totalSuccessMax += *l.maxSwapRoutingFee
123125
}
124126
if l.maxPrepayRoutingFee != nil {
125127
totalSuccessMax += *l.maxPrepayRoutingFee
126128
}
129+
130+
if swapType == loop.TypeIn && externalHtlc {
131+
fmt.Printf("On-chain fee for external loop in is not " +
132+
"included.\nSufficient fees will need to be paid " +
133+
"when constructing the transaction in the external " +
134+
"wallet.\n\n")
135+
}
127136

128137
fmt.Printf("Max swap fees for %d Loop %v: %d\n",
129138
btcutil.Amount(amt), swapType, totalSuccessMax,
@@ -139,7 +148,10 @@ func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits) error {
139148
return nil
140149
case "x":
141150
fmt.Println()
142-
fmt.Printf("Max on-chain fee: %d\n", l.maxMinerFee)
151+
if swapType != loop.TypeIn || !externalHtlc {
152+
fmt.Printf("Max on-chain fee: %d\n",
153+
l.maxMinerFee)
154+
}
143155

144156
if l.maxSwapRoutingFee != nil {
145157
fmt.Printf("Max off-chain swap routing fee: %d\n",

cmd/loopd/swapclient_server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
306306
quote, err := s.impl.LoopInQuote(ctx, &loop.LoopInQuoteRequest{
307307
Amount: btcutil.Amount(req.Amt),
308308
HtlcConfTarget: defaultConfTarget,
309+
ExternalHtlc: req.ExternalHtlc,
309310
})
310311
if err != nil {
311312
return nil, err

interface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ type LoopInQuoteRequest struct {
224224
// HtlcConfTarget specifies the targeted confirmation target for the
225225
// client sweep tx.
226226
HtlcConfTarget int32
227+
228+
// ExternalHtlc specifies whether the htlc is published by an external
229+
// source.
230+
ExternalHtlc bool
227231
}
228232

229233
// LoopInQuote contains estimates for the fees making up the total swap cost

looprpc/client.pb.go

Lines changed: 80 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)