Skip to content

Commit a9be69b

Browse files
committed
multi: use isExternalAddr flag
1 parent 627eb5c commit a9be69b

File tree

7 files changed

+25
-0
lines changed

7 files changed

+25
-0
lines changed

cmd/loop/loopout.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ func loopOut(ctx *cli.Context) error {
238238
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
239239
Amt: int64(amt),
240240
Dest: destAddr,
241+
IsExternalAddr: destAddr != "",
241242
Account: account,
242243
AccountAddrType: accountAddrType,
243244
MaxMinerFee: int64(limits.maxMinerFee),

interface.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ type OutRequest struct {
2020
// Destination address for the swap.
2121
DestAddr btcutil.Address
2222

23+
// IsExternalAddr indicates whether the provided destination address
24+
// does not belong to the underlying wallet. This helps indicate
25+
// whether the sweep of this swap can be batched or not.
26+
IsExternalAddr bool
27+
2328
// MaxSwapRoutingFee is the maximum off-chain fee in msat that may be
2429
// paid for payment to the server. This limit is applied during path
2530
// finding. Typically this value is taken from the response of the

liquidity/autoloop_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ func TestAutoloopAddress(t *testing.T) {
422422
Amount: amt,
423423
// Define the expected destination address.
424424
DestAddr: addr,
425+
IsExternalAddr: true,
425426
MaxSwapRoutingFee: maxRouteFee,
426427
MaxPrepayRoutingFee: ppmToSat(
427428
quote1.PrepayAmount, prepayFeePPM,
@@ -439,6 +440,7 @@ func TestAutoloopAddress(t *testing.T) {
439440
Amount: amt,
440441
// Define the expected destination address.
441442
DestAddr: addr,
443+
IsExternalAddr: true,
442444
MaxSwapRoutingFee: maxRouteFee,
443445
MaxPrepayRoutingFee: ppmToSat(
444446
quote2.PrepayAmount, routeFeePPM,

liquidity/liquidity.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ func (m *Manager) autoloop(ctx context.Context) error {
450450
// Create a copy of our range var so that we can reference it.
451451
swap := swap
452452

453+
// Check if the parameter for custom address is defined for loop
454+
// outs.
455+
if m.params.DestAddr != nil {
456+
swap.DestAddr = m.params.DestAddr
457+
swap.IsExternalAddr = true
458+
}
459+
453460
go m.dispatchStickyLoopOut(
454461
ctx, swap, defaultAmountBackoffRetry,
455462
defaultAmountBackoff,

liquidity/loopout_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
138138
// already validated them.
139139
request := loop.OutRequest{
140140
Amount: amount,
141+
IsExternalAddr: false,
141142
OutgoingChanSet: chanSet,
142143
MaxPrepayRoutingFee: prepayMaxFee,
143144
MaxSwapRoutingFee: routeMaxFee,
@@ -160,9 +161,11 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
160161
if len(params.Account) > 0 {
161162
account = params.Account
162163
addrType = params.AccountAddrType
164+
request.IsExternalAddr = true
163165
}
164166
if params.DestAddr != nil {
165167
request.DestAddr = params.DestAddr
168+
request.IsExternalAddr = true
166169
} else {
167170
addr, err := b.cfg.Lnd.WalletKit.NextAddr(
168171
ctx, account, addrType, false,

loopd/swapclient_server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
100100
log.Infof("Loop out request received")
101101

102102
var sweepAddr btcutil.Address
103+
var isExternalAddr bool
103104
var err error
104105
//nolint:lll
105106
switch {
@@ -117,6 +118,8 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
117118
return nil, fmt.Errorf("decode address: %v", err)
118119
}
119120

121+
isExternalAddr = true
122+
120123
case in.Account != "" && in.AccountAddrType == clientrpc.AddressType_ADDRESS_TYPE_UNKNOWN:
121124
return nil, liquidity.ErrAccountAndAddrType
122125

@@ -141,6 +144,8 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
141144
"%v", err)
142145
}
143146

147+
isExternalAddr = true
148+
144149
default:
145150
// Generate sweep address if none specified.
146151
sweepAddr, err = s.lnd.WalletKit.NextAddr(
@@ -166,6 +171,7 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
166171
req := &loop.OutRequest{
167172
Amount: btcutil.Amount(in.Amt),
168173
DestAddr: sweepAddr,
174+
IsExternalAddr: isExternalAddr,
169175
MaxMinerFee: btcutil.Amount(in.MaxMinerFee),
170176
MaxPrepayAmount: btcutil.Amount(in.MaxPrepayAmt),
171177
MaxPrepayRoutingFee: btcutil.Amount(in.MaxPrepayRoutingFee),

loopout.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
172172
contract := loopdb.LoopOutContract{
173173
SwapInvoice: swapResp.swapInvoice,
174174
DestAddr: request.DestAddr,
175+
IsExternalAddr: request.IsExternalAddr,
175176
MaxSwapRoutingFee: request.MaxSwapRoutingFee,
176177
SweepConfTarget: request.SweepConfTarget,
177178
HtlcConfirmations: confs,

0 commit comments

Comments
 (0)