diff --git a/liquidity/autoloop_test.go b/liquidity/autoloop_test.go index 4c63ead..44041b9 100644 --- a/liquidity/autoloop_test.go +++ b/liquidity/autoloop_test.go @@ -1256,6 +1256,14 @@ func TestAutoLoopRecurringBudget(t *testing.T) { func TestEasyAutoloop(t *testing.T) { defer test.Guard(t) + // Decode a dummy p2wkh address to use as the destination address for + // the swaps. + p2wkhAddr := "bcrt1qq68r6ff4k4pjx39efs44gcyccf7unqnu5qtjjz" + addr, err := btcutil.DecodeAddress(p2wkhAddr, nil) + if err != nil { + t.Error(err) + } + // We need to change the default channels we use for tests so that they // have different local balances in order to know which one is going to // be selected by easy autoloop. @@ -1284,6 +1292,7 @@ func TestEasyAutoloop(t *testing.T) { params = Parameters{ Autoloop: true, + DestAddr: addr, AutoFeeBudget: 36000, AutoFeeRefreshPeriod: time.Hour * 3, AutoloopBudgetLastRefresh: testBudgetStart, @@ -1305,6 +1314,7 @@ func TestEasyAutoloop(t *testing.T) { chan1Swap = &loop.OutRequest{ Amount: btcutil.Amount(maxAmt), + DestAddr: addr, OutgoingChanSet: loopdb.ChannelSet{easyChannel1.ChannelID}, Label: labels.AutoloopLabel(swap.TypeOut), Initiator: autoloopSwapInitiator, @@ -1352,6 +1362,9 @@ func TestEasyAutoloop(t *testing.T) { easyChannel1, easyChannel2, } + // Remove the custom dest address. + params.DestAddr = nil + c = newAutoloopTestCtx(t, params, channels, testRestrictions) c.start() diff --git a/liquidity/autoloop_testcontext_test.go b/liquidity/autoloop_testcontext_test.go index 81430a4..35e49ee 100644 --- a/liquidity/autoloop_testcontext_test.go +++ b/liquidity/autoloop_testcontext_test.go @@ -402,6 +402,11 @@ func (c *autoloopTestCtx) easyautoloop(step *easyAutoloopStep, noop bool) { c.t, expected.request.OutgoingChanSet, actual.OutgoingChanSet, ) + if expected.request.DestAddr != nil { + require.Equal( + c.t, expected.request.DestAddr, actual.DestAddr, + ) + } } // Since we're checking if any false-positive swaps were dispatched we diff --git a/liquidity/liquidity.go b/liquidity/liquidity.go index 64b0a6a..36a5b00 100644 --- a/liquidity/liquidity.go +++ b/liquidity/liquidity.go @@ -450,12 +450,6 @@ func (m *Manager) autoloop(ctx context.Context) error { // Create a copy of our range var so that we can reference it. swap := swap - // Check if the parameter for custom address is defined for loop - // outs. - if m.params.DestAddr != nil { - swap.DestAddr = m.params.DestAddr - } - go m.dispatchStickyLoopOut( ctx, swap, defaultAmountBackoffRetry, defaultAmountBackoff, diff --git a/liquidity/loopout_builder.go b/liquidity/loopout_builder.go index 658c940..8048aea 100644 --- a/liquidity/loopout_builder.go +++ b/liquidity/loopout_builder.go @@ -161,14 +161,17 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex, account = params.Account addrType = params.AccountAddrType } - - addr, err := b.cfg.Lnd.WalletKit.NextAddr( - ctx, account, addrType, false, - ) - if err != nil { - return nil, err + if params.DestAddr != nil { + request.DestAddr = params.DestAddr + } else { + addr, err := b.cfg.Lnd.WalletKit.NextAddr( + ctx, account, addrType, false, + ) + if err != nil { + return nil, err + } + request.DestAddr = addr } - request.DestAddr = addr } return &loopOutSwapSuggestion{