Skip to content

Commit 0eaf89c

Browse files
committed
autoloop: ignore asset channels
1 parent 1f07c37 commit 0eaf89c

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

liquidity/autoloop_test.go

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

1290+
// The custom channel should be ignored.
1291+
easyChannelCustom := lndclient.ChannelInfo{
1292+
Active: true,
1293+
ChannelID: chanID1.ToUint64(),
1294+
PubKeyBytes: peer1,
1295+
LocalBalance: 50000,
1296+
RemoteBalance: 0,
1297+
Capacity: 100000,
1298+
CustomChannelData: []byte("foo"),
1299+
}
1300+
12901301
var (
12911302
channels = []lndclient.ChannelInfo{
1292-
easyChannel1, easyChannel2,
1303+
easyChannel1, easyChannel2, easyChannelCustom,
12931304
}
12941305

12951306
params = Parameters{
@@ -1361,7 +1372,7 @@ func TestEasyAutoloop(t *testing.T) {
13611372
// new context and restart the autolooper.
13621373
easyChannel1.LocalBalance -= chan1Swap.Amount
13631374
channels = []lndclient.ChannelInfo{
1364-
easyChannel1, easyChannel2,
1375+
easyChannel1, easyChannel2, easyChannelCustom,
13651376
}
13661377

13671378
// Remove the custom dest address.
@@ -1419,7 +1430,7 @@ func TestEasyAutoloop(t *testing.T) {
14191430
// new context and restart the autolooper.
14201431
easyChannel2.LocalBalance -= btcutil.Amount(amt2)
14211432
channels = []lndclient.ChannelInfo{
1422-
easyChannel1, easyChannel2,
1433+
easyChannel1, easyChannel2, easyChannelCustom,
14231434
}
14241435

14251436
c = newAutoloopTestCtx(t, params, channels, testRestrictions)
@@ -1438,7 +1449,7 @@ func TestEasyAutoloop(t *testing.T) {
14381449
// Restore the local balance to a higher value that will trigger a swap.
14391450
easyChannel2.LocalBalance = btcutil.Amount(95000)
14401451
channels = []lndclient.ChannelInfo{
1441-
easyChannel1, easyChannel2,
1452+
easyChannel1, easyChannel2, easyChannelCustom,
14421453
}
14431454

14441455
// Override the feeppm with a lower one.

liquidity/liquidity.go

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

557557
localTotal := btcutil.Amount(0)
558558
for _, channel := range channels {
559+
if channelIsCustom(channel) {
560+
continue
561+
}
559562
localTotal += channel.LocalBalance
560563
}
561564

@@ -781,6 +784,10 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
781784
channelPeers := make(map[uint64]route.Vertex)
782785
peerChannels := make(map[route.Vertex]*balances)
783786
for _, channel := range channels {
787+
if channelIsCustom(channel) {
788+
continue
789+
}
790+
784791
channelPeers[channel.ChannelID] = channel.PubKeyBytes
785792

786793
bal, ok := peerChannels[channel.PubKeyBytes]
@@ -834,6 +841,10 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
834841
balance := newBalances(channel)
835842

836843
channelID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
844+
if channelIsCustom(channel) {
845+
continue
846+
}
847+
837848
rule, ok := m.params.ChannelRules[channelID]
838849
if !ok {
839850
continue
@@ -1424,6 +1435,10 @@ func (m *Manager) pickEasyAutoloopChannel(channels []lndclient.ChannelInfo,
14241435
// Check each channel, since channels are already sorted we return the
14251436
// first channel that passes all checks.
14261437
for _, channel := range channels {
1438+
if channelIsCustom(channel) {
1439+
continue
1440+
}
1441+
14271442
shortChanID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
14281443

14291444
if !channel.Active {
@@ -1548,3 +1563,12 @@ func satPerKwToSatPerVByte(satPerKw chainfee.SatPerKWeight) int64 {
15481563
func ppmToSat(amount btcutil.Amount, ppm uint64) btcutil.Amount {
15491564
return btcutil.Amount(uint64(amount) * ppm / FeeBase)
15501565
}
1566+
1567+
// channelIsCustom returns true if the channel has custom channel data.
1568+
// we'll want to ignore these channels for autoloop recommendations.
1569+
func channelIsCustom(channel lndclient.ChannelInfo) bool {
1570+
// If the channel has custom channel data, the channel is a
1571+
// non-standard channel, such as an asset channel and we
1572+
// don't want to consider it for swaps.
1573+
return channel.CustomChannelData != nil
1574+
}

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)