Skip to content

Commit db2b27c

Browse files
committed
liquidity: exclude peers for easy autoloop
1 parent c11d5cd commit db2b27c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

liquidity/liquidity.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,9 +1666,24 @@ 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(map[route.Vertex]struct{})
1671+
for _, v := range m.params.EasyAutoloopExcludedPeers {
1672+
excluded[v] = struct{}{}
1673+
}
1674+
1675+
// Check each channel, since channels are already sorted, we return the
16701676
// first channel that passes all checks.
16711677
for _, channel := range channels {
1678+
// Skip channels whose remote peer is excluded for easy autoloop.
1679+
if _, ok := excluded[channel.PubKeyBytes]; ok {
1680+
log.Debugf("Channel %v cannot be used for easy "+
1681+
"autoloop: peer %x excluded", channel.ChannelID,
1682+
channel.PubKeyBytes)
1683+
1684+
continue
1685+
}
1686+
16721687
shortChanID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
16731688

16741689
if !channel.Active {

liquidity/parameters.go

Lines changed: 22 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,17 @@ func RpcToParameters(req *clientrpc.LiquidityParameters) (*Parameters,
481485
time.Second
482486
}
483487

488+
// Map excluded peers for easy autoloop, if any.
489+
for _, p := range req.GetEasyAutoloopExcludedPeers() {
490+
v, err := route.NewVertexFromBytes(p)
491+
if err != nil {
492+
return nil, err
493+
}
494+
params.EasyAutoloopExcludedPeers = append(
495+
params.EasyAutoloopExcludedPeers, v,
496+
)
497+
}
498+
484499
// If an old-style budget was written to storage then express it by
485500
// using the new auto budget parameters. If the newly added parameters
486501
// have the 0 default value, but a budget was defined that means the
@@ -603,6 +618,13 @@ func ParametersToRpc(cfg Parameters) (*clientrpc.LiquidityParameters,
603618
EasyAssetParams: easyAssetMap,
604619
FastSwapPublication: cfg.FastSwapPublication,
605620
}
621+
// Set excluded peers for easy autoloop.
622+
for _, v := range cfg.EasyAutoloopExcludedPeers {
623+
b := v[:]
624+
rpcCfg.EasyAutoloopExcludedPeers = append(
625+
rpcCfg.EasyAutoloopExcludedPeers, b,
626+
)
627+
}
606628

607629
switch f := cfg.FeeLimit.(type) {
608630
case *FeeCategoryLimit:

0 commit comments

Comments
 (0)