routing: add strict zombie pruning as a config level param
In this commit, we add strict zombie pruning as a config level param. This allow us to add the option for those that want a tighter graph, and not change the default composition of the channel graph for most users over night. In addition, we expand the test case slightly by testing that the self node won't be pruned, but also that if there's a node with only a single known stale edge, then both variants will prune that edge.
This commit is contained in:
5 files changed
+134
-77
No files matched your search
+27
-3
@@ -342,6 +342,13 @@ type Config struct {
|
||||
|
||||
// Clock is mockable time provider.
|
||||
Clock clock.Clock
|
||||
|
||||
// StrictZombiePruning determines if we attempt to prune zombie
|
||||
// channels according to a stricter criteria. If true, then we'll prune
|
||||
// a channel if only *one* of the edges is considered a zombie.
|
||||
// Otherwise, we'll only prune the channel when both edges have a very
|
||||
// dated last update.
|
||||
StrictZombiePruning bool
|
||||
}
|
||||
|
||||
// EdgeLocator is a struct used to identify a specific edge.
|
||||
@@ -839,8 +846,24 @@ func (r *ChannelRouter) pruneZombieChans() error {
|
||||
info.NodeKey2Bytes, info.ChannelID)
|
||||
}
|
||||
|
||||
// Return early if both sides have a recent update.
|
||||
if !e1Zombie && !e2Zombie {
|
||||
// If we're using strict zombie pruning, then a channel is only
|
||||
// considered live if both edges have a recent update we know
|
||||
// of.
|
||||
var channelIsLive bool
|
||||
switch {
|
||||
case r.cfg.StrictZombiePruning:
|
||||
channelIsLive = !e1Zombie && !e2Zombie
|
||||
|
||||
// Otherwise, if we're using the less strict variant, then a
|
||||
// channel is considered live if either of the edges have a
|
||||
// recent update.
|
||||
default:
|
||||
channelIsLive = !e1Zombie || !e2Zombie
|
||||
}
|
||||
|
||||
// Return early if the channel is still considered to be live
|
||||
// with the current set of configuration parameters.
|
||||
if channelIsLive {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -901,7 +924,8 @@ func (r *ChannelRouter) pruneZombieChans() error {
|
||||
toPrune = append(toPrune, chanID)
|
||||
log.Tracef("Pruning zombie channel with ChannelID(%v)", chanID)
|
||||
}
|
||||
if err := r.cfg.Graph.DeleteChannelEdges(toPrune...); err != nil {
|
||||
err = r.cfg.Graph.DeleteChannelEdges(r.cfg.StrictZombiePruning, toPrune...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to delete zombie channels: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user