Merge pull request #881 from sputn1ck/autoloop_ignore_asset_chans

autoloop: ignore asset channels
This commit is contained in:
Konstantin Nick 2025-02-07 10:34:36 +01:00 committed by GitHub
commit 992884cc47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 4 deletions

View file

@ -1287,9 +1287,20 @@ func TestEasyAutoloop(t *testing.T) {
Capacity: 100000,
}
// The custom channel should be ignored.
easyChannelCustom := lndclient.ChannelInfo{
Active: true,
ChannelID: chanID1.ToUint64(),
PubKeyBytes: peer1,
LocalBalance: 50000,
RemoteBalance: 0,
Capacity: 100000,
CustomChannelData: []byte("foo"),
}
var (
channels = []lndclient.ChannelInfo{
easyChannel1, easyChannel2,
easyChannel1, easyChannel2, easyChannelCustom,
}
params = Parameters{
@ -1361,7 +1372,7 @@ func TestEasyAutoloop(t *testing.T) {
// new context and restart the autolooper.
easyChannel1.LocalBalance -= chan1Swap.Amount
channels = []lndclient.ChannelInfo{
easyChannel1, easyChannel2,
easyChannel1, easyChannel2, easyChannelCustom,
}
// Remove the custom dest address.
@ -1419,7 +1430,7 @@ func TestEasyAutoloop(t *testing.T) {
// new context and restart the autolooper.
easyChannel2.LocalBalance -= btcutil.Amount(amt2)
channels = []lndclient.ChannelInfo{
easyChannel1, easyChannel2,
easyChannel1, easyChannel2, easyChannelCustom,
}
c = newAutoloopTestCtx(t, params, channels, testRestrictions)
@ -1438,7 +1449,7 @@ func TestEasyAutoloop(t *testing.T) {
// Restore the local balance to a higher value that will trigger a swap.
easyChannel2.LocalBalance = btcutil.Amount(95000)
channels = []lndclient.ChannelInfo{
easyChannel1, easyChannel2,
easyChannel1, easyChannel2, easyChannelCustom,
}
// Override the feeppm with a lower one.

View file

@ -556,6 +556,9 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
localTotal := btcutil.Amount(0)
for _, channel := range channels {
if channelIsCustom(channel) {
continue
}
localTotal += channel.LocalBalance
}
@ -781,6 +784,10 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
channelPeers := make(map[uint64]route.Vertex)
peerChannels := make(map[route.Vertex]*balances)
for _, channel := range channels {
if channelIsCustom(channel) {
continue
}
channelPeers[channel.ChannelID] = channel.PubKeyBytes
bal, ok := peerChannels[channel.PubKeyBytes]
@ -834,6 +841,14 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
balance := newBalances(channel)
channelID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
if channelIsCustom(channel) {
resp.DisqualifiedChans[channelID] =
ReasonCustomChannelData
continue
}
rule, ok := m.params.ChannelRules[channelID]
if !ok {
continue
@ -1424,6 +1439,10 @@ func (m *Manager) pickEasyAutoloopChannel(channels []lndclient.ChannelInfo,
// Check each channel, since channels are already sorted we return the
// first channel that passes all checks.
for _, channel := range channels {
if channelIsCustom(channel) {
continue
}
shortChanID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
if !channel.Active {
@ -1548,3 +1567,12 @@ func satPerKwToSatPerVByte(satPerKw chainfee.SatPerKWeight) int64 {
func ppmToSat(amount btcutil.Amount, ppm uint64) btcutil.Amount {
return btcutil.Amount(uint64(amount) * ppm / FeeBase)
}
// channelIsCustom returns true if the channel has custom channel data.
// we'll want to ignore these channels for autoloop recommendations.
func channelIsCustom(channel lndclient.ChannelInfo) bool {
// If the channel has custom channel data, the channel is a
// non-standard channel, such as an asset channel and we
// don't want to consider it for swaps.
return channel.CustomChannelData != nil
}

View file

@ -794,6 +794,29 @@ func TestSuggestSwaps(t *testing.T) {
},
},
},
{
name: "don't consider asset channel",
channels: []lndclient.ChannelInfo{
{
ChannelID: chanID1.ToUint64(),
PubKeyBytes: peer1,
LocalBalance: 10000,
RemoteBalance: 0,
Capacity: 10000,
CustomChannelData: []byte("foo"),
},
},
rules: map[lnwire.ShortChannelID]*SwapRule{
chanID1: chanRule,
},
suggestions: &Suggestions{
DisqualifiedChans: map[lnwire.ShortChannelID]Reason{ // nolint: lll
chanID1: ReasonCustomChannelData,
},
DisqualifiedPeers: noPeersDisqualified,
},
},
}
for _, testCase := range tests {

View file

@ -69,6 +69,10 @@ const (
// ReasonLoopInUnreachable indicates that the server does not have a
// path to the client, so cannot perform a loop in swap at this time.
ReasonLoopInUnreachable
// ReasonCustomChannelData indicates that the channel is not standard
// and should not be used for swaps.
ReasonCustomChannelData
)
// String returns a string representation of a reason.