Skip to content

Commit

Permalink
Merge pull request #644 from bhandras/easy-autoloop-destaddr-fixup
Browse files Browse the repository at this point in the history
liquidity: dest address support for easy autloop
  • Loading branch information
bhandras committed Oct 4, 2023
2 parents 71c3e65 + 87c8ca0 commit 7dd30a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
13 changes: 13 additions & 0 deletions liquidity/autoloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1284,6 +1292,7 @@ func TestEasyAutoloop(t *testing.T) {

params = Parameters{
Autoloop: true,
DestAddr: addr,
AutoFeeBudget: 36000,
AutoFeeRefreshPeriod: time.Hour * 3,
AutoloopBudgetLastRefresh: testBudgetStart,
Expand All @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions liquidity/autoloop_testcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions liquidity/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions liquidity/loopout_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 7dd30a7

Please sign in to comment.