Skip to content

Commit b6200a4

Browse files
committed
liquidity: exclude peers for easy autoloop
1 parent 3b819d3 commit b6200a4

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

liquidity/liquidity.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,9 +1666,27 @@ func (m *Manager) pickEasyAutoloopChannel(channels []lndclient.ChannelInfo,
16661666
return channels[i].LocalBalance > channels[j].LocalBalance
16671667
})
16681668

1669-
// Check each channel, since channels are already sorted we return the
1669+
// Build a set of excluded peers for a quick lookup.
1670+
excluded := make(
1671+
map[route.Vertex]struct{},
1672+
len(m.params.EasyAutoloopExcludedPeers),
1673+
)
1674+
for _, v := range m.params.EasyAutoloopExcludedPeers {
1675+
excluded[v] = struct{}{}
1676+
}
1677+
1678+
// Check each channel, since channels are already sorted, we return the
16701679
// first channel that passes all checks.
16711680
for _, channel := range channels {
1681+
// Skip channels whose remote peer is excluded for easy autoloop.
1682+
if _, ok := excluded[channel.PubKeyBytes]; ok {
1683+
log.Debugf("Channel %v cannot be used for easy "+
1684+
"autoloop: peer %v manually excluded",
1685+
channel.ChannelID, channel.PubKeyBytes)
1686+
1687+
continue
1688+
}
1689+
16721690
shortChanID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
16731691

16741692
if !channel.Active {

liquidity/parameters.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ type Parameters struct {
116116
// maintain in our channels.
117117
EasyAutoloopTarget btcutil.Amount
118118

119+
// EasyAutoloopExcludedPeers is an optional list of peers that should be
120+
// excluded from being selected for easy autoloop swaps.
121+
EasyAutoloopExcludedPeers []route.Vertex
122+
119123
// AssetAutoloopParams maps an asset id hex encoded string to its
120124
// easy autoloop parameters.
121125
AssetAutoloopParams map[string]AssetParams
@@ -481,6 +485,21 @@ func RpcToParameters(req *clientrpc.LiquidityParameters) (*Parameters,
481485
time.Second
482486
}
483487

488+
// Map excluded peers for easy autoloop, if any.
489+
excludedPeersRPC := req.GetEasyAutoloopExcludedPeers()
490+
params.EasyAutoloopExcludedPeers = make(
491+
[]route.Vertex, 0, len(excludedPeersRPC),
492+
)
493+
for _, p := range excludedPeersRPC {
494+
v, err := route.NewVertexFromBytes(p)
495+
if err != nil {
496+
return nil, err
497+
}
498+
params.EasyAutoloopExcludedPeers = append(
499+
params.EasyAutoloopExcludedPeers, v,
500+
)
501+
}
502+
484503
// If an old-style budget was written to storage then express it by
485504
// using the new auto budget parameters. If the newly added parameters
486505
// have the 0 default value, but a budget was defined that means the
@@ -603,6 +622,15 @@ func ParametersToRpc(cfg Parameters) (*clientrpc.LiquidityParameters,
603622
EasyAssetParams: easyAssetMap,
604623
FastSwapPublication: cfg.FastSwapPublication,
605624
}
625+
// Set excluded peers for easy autoloop.
626+
rpcCfg.EasyAutoloopExcludedPeers = make(
627+
[][]byte, 0, len(cfg.EasyAutoloopExcludedPeers),
628+
)
629+
for _, v := range cfg.EasyAutoloopExcludedPeers {
630+
rpcCfg.EasyAutoloopExcludedPeers = append(
631+
rpcCfg.EasyAutoloopExcludedPeers, v[:],
632+
)
633+
}
606634

607635
switch f := cfg.FeeLimit.(type) {
608636
case *FeeCategoryLimit:

0 commit comments

Comments
 (0)