Skip to content

Commit

Permalink
routing: mark edges as zombies within index when pruning them
Browse files Browse the repository at this point in the history
We mark the edges as zombies when pruning them to ensure we don't
attempt to reprocess them later on.
  • Loading branch information
wpaulino committed Mar 20, 2019
1 parent 99bac67 commit 8d0d150
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
15 changes: 11 additions & 4 deletions routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func (r *ChannelRouter) syncGraphWithChain() error {
// usually signals that a channel has been closed on-chain. We do this
// periodically to keep a health, lively routing table.
func (r *ChannelRouter) pruneZombieChans() error {
var chansToPrune []wire.OutPoint
var chansToPrune []*channeldb.ChannelEdgeInfo
chanExpiry := r.cfg.ChannelPruneExpiry

log.Infof("Examining channel graph for zombie channels")
Expand Down Expand Up @@ -707,7 +707,7 @@ func (r *ChannelRouter) pruneZombieChans() error {
info.ChannelPoint)

// TODO(roasbeef): add ability to delete single directional edge
chansToPrune = append(chansToPrune, info.ChannelPoint)
chansToPrune = append(chansToPrune, info)

// As we're detecting this as a zombie channel, we'll add this
// to the set of recently rejected items so we don't re-accept
Expand All @@ -734,10 +734,17 @@ func (r *ChannelRouter) pruneZombieChans() error {
log.Tracef("Pruning zombie channel with ChannelPoint(%v)",
chanToPrune)

err := r.cfg.Graph.DeleteChannelEdge(&chanToPrune)
err := r.cfg.Graph.MarkEdgeZombie(chanToPrune.ChannelID)
if err != nil {
return fmt.Errorf("unable to mark ChannelPoint(%v) "+
"as zombie: %v", chanToPrune.ChannelPoint, err)
}

err = r.cfg.Graph.DeleteChannelEdge(&chanToPrune.ChannelPoint)
if err != nil {
return fmt.Errorf("unable to prune zombie with "+
"ChannelPoint(%v): %v", chanToPrune, err)
"ChannelPoint(%v): %v",
chanToPrune.ChannelPoint, err)
}
}

Expand Down
12 changes: 10 additions & 2 deletions routing/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ func TestPruneChannelGraphDoubleDisabled(t *testing.T) {
defer cleanUp()

// assertChannelExistence is a helper closure that ensures channels are
// properly pruned from the graph.
// properly pruned from the graph marked as zombies.
assertChannelExistence := func(channels ...uint64) {
t.Helper()

Expand All @@ -2020,7 +2020,7 @@ func TestPruneChannelGraphDoubleDisabled(t *testing.T) {
for _, channel := range testChannels {
_, shouldExist := s[channel.ChannelID]

_, _, exist, _, err := ctx.router.cfg.Graph.HasChannelEdge(
_, _, exist, isZombie, err := ctx.router.cfg.Graph.HasChannelEdge(
channel.ChannelID,
)
if err != nil {
Expand All @@ -2036,6 +2036,14 @@ func TestPruneChannelGraphDoubleDisabled(t *testing.T) {
t.Fatalf("expected channel=%v to not exist "+
"within the graph", channel.ChannelID)
}
if shouldExist && isZombie {
t.Fatalf("expected existent channel=%v to not "+
"be a zombie", channel.ChannelID)
}
if !shouldExist && !isZombie {
t.Fatalf("expected non-existent channel=%v to "+
"be a zombie", channel.ChannelID)
}
}
}

Expand Down

0 comments on commit 8d0d150

Please sign in to comment.