Skip to content

Commit 992884c

Browse files
authored
Merge pull request #881 from sputn1ck/autoloop_ignore_asset_chans
autoloop: ignore asset channels
2 parents 1f07c37 + 4dd3074 commit 992884c

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

liquidity/autoloop_test.go

+15-4
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

+28
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,14 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
834841
balance := newBalances(channel)
835842

836843
channelID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
844+
845+
if channelIsCustom(channel) {
846+
resp.DisqualifiedChans[channelID] =
847+
ReasonCustomChannelData
848+
849+
continue
850+
}
851+
837852
rule, ok := m.params.ChannelRules[channelID]
838853
if !ok {
839854
continue
@@ -1424,6 +1439,10 @@ func (m *Manager) pickEasyAutoloopChannel(channels []lndclient.ChannelInfo,
14241439
// Check each channel, since channels are already sorted we return the
14251440
// first channel that passes all checks.
14261441
for _, channel := range channels {
1442+
if channelIsCustom(channel) {
1443+
continue
1444+
}
1445+
14271446
shortChanID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
14281447

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

liquidity/liquidity_test.go

+23
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

+4
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)