From b54b8dd7f1f8f24f1af4983f90b09d57eb8a8786 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 30 Jan 2018 20:35:19 -0800 Subject: [PATCH] routing: reject any new announcements which were pruned as zombies --- routing/router.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/routing/router.go b/routing/router.go index 0ea7ed7b..2663755a 100644 --- a/routing/router.go +++ b/routing/router.go @@ -237,6 +237,9 @@ type ChannelRouter struct { // consistency between the various database accesses. channelEdgeMtx *multimutex.Mutex + rejectMtx sync.RWMutex + rejectCache map[uint64]struct{} + sync.RWMutex quit chan struct{} @@ -268,6 +271,7 @@ func New(cfg Config) (*ChannelRouter, error) { channelEdgeMtx: multimutex.NewMutex(), selfNode: selfNode, routeCache: make(map[routeTuple][]*Route), + rejectCache: make(map[uint64]struct{}), quit: make(chan struct{}), }, nil } @@ -566,9 +570,10 @@ func (r *ChannelRouter) pruneZombieChans() error { } r.rejectMtx.Lock() + defer r.rejectMtx.Unlock() + err := r.cfg.Graph.ForEachChannel(filterPruneChans) if err != nil { - r.rejectMtx.Unlock() return fmt.Errorf("Unable to filter local zombie "+ "chans: %v", err) } @@ -582,12 +587,10 @@ func (r *ChannelRouter) pruneZombieChans() error { err := r.cfg.Graph.DeleteChannelEdge(&chanToPrune) if err != nil { - r.rejectMtx.Unlock() return fmt.Errorf("Unable to prune zombie "+ "chans: %v", err) } } - r.rejectMtx.Unlock() return nil } @@ -861,6 +864,16 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error { log.Infof("Updated vertex data for node=%x", msg.PubKeyBytes) case *channeldb.ChannelEdgeInfo: + // If we recently rejected this channel edge, then we won't + // attempt to re-process it. + r.rejectMtx.RLock() + if _, ok := r.rejectCache[msg.ChannelID]; ok { + r.rejectMtx.RUnlock() + return newErrf(ErrIgnored, "recently rejected "+ + "chan_id=%v", msg.ChannelID) + } + r.rejectMtx.RUnlock() + // Prior to processing the announcement we first check if we // already know of this channel, if so, then we can exit early. _, _, exists, err := r.cfg.Graph.HasChannelEdge(msg.ChannelID) @@ -972,6 +985,16 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error { } case *channeldb.ChannelEdgePolicy: + // If we recently rejected this channel edge, then we won't + // attempt to re-process it. + r.rejectMtx.RLock() + if _, ok := r.rejectCache[msg.ChannelID]; ok { + r.rejectMtx.RUnlock() + return newErrf(ErrIgnored, "recently rejected "+ + "chan_id=%v", msg.ChannelID) + } + r.rejectMtx.RUnlock() + channelID := lnwire.NewShortChanIDFromInt(msg.ChannelID) // We make sure to hold the mutex for this channel ID,