routing: reject any new announcements which were pruned as zombies

This commit is contained in:
Olaoluwa Osuntokun 2018-01-30 20:35:19 -08:00
parent 6d05cb5aae
commit b54b8dd7f1
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -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,