Skip to content

Commit d971381

Browse files
committed
autoloop: ignore asset channels
1 parent 7b8ce15 commit d971381

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

liquidity/autoloop_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,9 +1287,19 @@ func TestEasyAutoloop(t *testing.T) {
12871287
Capacity: 100000,
12881288
}
12891289

1290+
easyChannelCustom := lndclient.ChannelInfo{
1291+
Active: true,
1292+
ChannelID: chanID1.ToUint64(),
1293+
PubKeyBytes: peer1,
1294+
LocalBalance: 50000,
1295+
RemoteBalance: 0,
1296+
Capacity: 100000,
1297+
CustomChannelData: []byte("foo"),
1298+
}
1299+
12901300
var (
12911301
channels = []lndclient.ChannelInfo{
1292-
easyChannel1, easyChannel2,
1302+
easyChannel1, easyChannel2, easyChannelCustom,
12931303
}
12941304

12951305
params = Parameters{
@@ -1361,7 +1371,7 @@ func TestEasyAutoloop(t *testing.T) {
13611371
// new context and restart the autolooper.
13621372
easyChannel1.LocalBalance -= chan1Swap.Amount
13631373
channels = []lndclient.ChannelInfo{
1364-
easyChannel1, easyChannel2,
1374+
easyChannel1, easyChannel2, easyChannelCustom,
13651375
}
13661376

13671377
// Remove the custom dest address.
@@ -1419,7 +1429,7 @@ func TestEasyAutoloop(t *testing.T) {
14191429
// new context and restart the autolooper.
14201430
easyChannel2.LocalBalance -= btcutil.Amount(amt2)
14211431
channels = []lndclient.ChannelInfo{
1422-
easyChannel1, easyChannel2,
1432+
easyChannel1, easyChannel2, easyChannelCustom,
14231433
}
14241434

14251435
c = newAutoloopTestCtx(t, params, channels, testRestrictions)
@@ -1438,7 +1448,7 @@ func TestEasyAutoloop(t *testing.T) {
14381448
// Restore the local balance to a higher value that will trigger a swap.
14391449
easyChannel2.LocalBalance = btcutil.Amount(95000)
14401450
channels = []lndclient.ChannelInfo{
1441-
easyChannel1, easyChannel2,
1451+
easyChannel1, easyChannel2, easyChannelCustom,
14421452
}
14431453

14441454
// Override the feeppm with a lower one.

liquidity/liquidity.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,12 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
556556

557557
localTotal := btcutil.Amount(0)
558558
for _, channel := range channels {
559+
// If the channel has custom channel data, the channel is a
560+
// non-standard channel, such as an asset channel and we
561+
// don't want to consider it for swaps.
562+
if channel.CustomChannelData != nil {
563+
continue
564+
}
559565
localTotal += channel.LocalBalance
560566
}
561567

@@ -781,6 +787,12 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
781787
channelPeers := make(map[uint64]route.Vertex)
782788
peerChannels := make(map[route.Vertex]*balances)
783789
for _, channel := range channels {
790+
// If the channel has custom channel data, the channel is a
791+
// non-standard channel, such as an asset channel and we
792+
// don't want to consider it for swaps.
793+
if channel.CustomChannelData != nil {
794+
continue
795+
}
784796
channelPeers[channel.ChannelID] = channel.PubKeyBytes
785797

786798
bal, ok := peerChannels[channel.PubKeyBytes]
@@ -834,6 +846,13 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
834846
balance := newBalances(channel)
835847

836848
channelID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
849+
// If the channel has custom channel data, the channel is a
850+
// non-standard channel, such as an asset channel and we
851+
// don't want to consider it for swaps.
852+
if channel.CustomChannelData != nil {
853+
resp.DisqualifiedChans[channelID] = ReasonCustomChannelData
854+
continue
855+
}
837856
rule, ok := m.params.ChannelRules[channelID]
838857
if !ok {
839858
continue
@@ -1424,6 +1443,13 @@ func (m *Manager) pickEasyAutoloopChannel(channels []lndclient.ChannelInfo,
14241443
// Check each channel, since channels are already sorted we return the
14251444
// first channel that passes all checks.
14261445
for _, channel := range channels {
1446+
// If the channel has custom channel data, the channel is a
1447+
// non-standard channel, such as an asset channel and we
1448+
// don't want to consider it for swaps.
1449+
if channel.CustomChannelData != nil {
1450+
continue
1451+
}
1452+
14271453
shortChanID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
14281454

14291455
if !channel.Active {

liquidity/liquidity_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,29 @@ func TestSuggestSwaps(t *testing.T) {
794794
},
795795
},
796796
},
797+
{
798+
799+
name: "don't consider asset channel",
800+
channels: []lndclient.ChannelInfo{
801+
{
802+
ChannelID: chanID1.ToUint64(),
803+
PubKeyBytes: peer1,
804+
LocalBalance: 10000,
805+
RemoteBalance: 0,
806+
Capacity: 10000,
807+
CustomChannelData: []byte("foo"),
808+
},
809+
},
810+
rules: map[lnwire.ShortChannelID]*SwapRule{
811+
chanID1: chanRule,
812+
},
813+
suggestions: &Suggestions{
814+
DisqualifiedChans: map[lnwire.ShortChannelID]Reason{ // nolint: lll
815+
chanID1: ReasonCustomChannelData,
816+
},
817+
DisqualifiedPeers: noPeersDisqualified,
818+
},
819+
},
797820
}
798821

799822
for _, testCase := range tests {

liquidity/reasons.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ const (
6969
// ReasonLoopInUnreachable indicates that the server does not have a
7070
// path to the client, so cannot perform a loop in swap at this time.
7171
ReasonLoopInUnreachable
72+
73+
// ReasonCustomChannelData indicates that the channel is not standard
74+
// and should not be used for swaps.
75+
ReasonCustomChannelData
7276
)
7377

7478
// String returns a string representation of a reason.

0 commit comments

Comments
 (0)