Skip to content

Commit 7dd30a7

Browse files
authored
Merge pull request #644 from bhandras/easy-autoloop-destaddr-fixup
liquidity: dest address support for easy autloop
2 parents 71c3e65 + 87c8ca0 commit 7dd30a7

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

liquidity/autoloop_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,14 @@ func TestAutoLoopRecurringBudget(t *testing.T) {
12561256
func TestEasyAutoloop(t *testing.T) {
12571257
defer test.Guard(t)
12581258

1259+
// Decode a dummy p2wkh address to use as the destination address for
1260+
// the swaps.
1261+
p2wkhAddr := "bcrt1qq68r6ff4k4pjx39efs44gcyccf7unqnu5qtjjz"
1262+
addr, err := btcutil.DecodeAddress(p2wkhAddr, nil)
1263+
if err != nil {
1264+
t.Error(err)
1265+
}
1266+
12591267
// We need to change the default channels we use for tests so that they
12601268
// have different local balances in order to know which one is going to
12611269
// be selected by easy autoloop.
@@ -1284,6 +1292,7 @@ func TestEasyAutoloop(t *testing.T) {
12841292

12851293
params = Parameters{
12861294
Autoloop: true,
1295+
DestAddr: addr,
12871296
AutoFeeBudget: 36000,
12881297
AutoFeeRefreshPeriod: time.Hour * 3,
12891298
AutoloopBudgetLastRefresh: testBudgetStart,
@@ -1305,6 +1314,7 @@ func TestEasyAutoloop(t *testing.T) {
13051314

13061315
chan1Swap = &loop.OutRequest{
13071316
Amount: btcutil.Amount(maxAmt),
1317+
DestAddr: addr,
13081318
OutgoingChanSet: loopdb.ChannelSet{easyChannel1.ChannelID},
13091319
Label: labels.AutoloopLabel(swap.TypeOut),
13101320
Initiator: autoloopSwapInitiator,
@@ -1352,6 +1362,9 @@ func TestEasyAutoloop(t *testing.T) {
13521362
easyChannel1, easyChannel2,
13531363
}
13541364

1365+
// Remove the custom dest address.
1366+
params.DestAddr = nil
1367+
13551368
c = newAutoloopTestCtx(t, params, channels, testRestrictions)
13561369
c.start()
13571370

liquidity/autoloop_testcontext_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ func (c *autoloopTestCtx) easyautoloop(step *easyAutoloopStep, noop bool) {
402402
c.t, expected.request.OutgoingChanSet,
403403
actual.OutgoingChanSet,
404404
)
405+
if expected.request.DestAddr != nil {
406+
require.Equal(
407+
c.t, expected.request.DestAddr, actual.DestAddr,
408+
)
409+
}
405410
}
406411

407412
// Since we're checking if any false-positive swaps were dispatched we

liquidity/liquidity.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,6 @@ 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-
}
458-
459453
go m.dispatchStickyLoopOut(
460454
ctx, swap, defaultAmountBackoffRetry,
461455
defaultAmountBackoff,

liquidity/loopout_builder.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,17 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
161161
account = params.Account
162162
addrType = params.AccountAddrType
163163
}
164-
165-
addr, err := b.cfg.Lnd.WalletKit.NextAddr(
166-
ctx, account, addrType, false,
167-
)
168-
if err != nil {
169-
return nil, err
164+
if params.DestAddr != nil {
165+
request.DestAddr = params.DestAddr
166+
} else {
167+
addr, err := b.cfg.Lnd.WalletKit.NextAddr(
168+
ctx, account, addrType, false,
169+
)
170+
if err != nil {
171+
return nil, err
172+
}
173+
request.DestAddr = addr
170174
}
171-
request.DestAddr = addr
172175
}
173176

174177
return &loopOutSwapSuggestion{

0 commit comments

Comments
 (0)