From 23ce82f4e37d22171a8be79ee5a72999125e97db Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 4 Dec 2018 14:58:39 +0100 Subject: [PATCH] routing/router: don't apply channel policy updates for unknown channels --- routing/router.go | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/routing/router.go b/routing/router.go index c33f3ff1..cdb8d53a 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1125,8 +1125,6 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error { } r.rejectMtx.RUnlock() - channelID := lnwire.NewShortChanIDFromInt(msg.ChannelID) - // We make sure to hold the mutex for this channel ID, // such that no other goroutine is concurrently doing // database accesses for the same channel ID. @@ -1142,6 +1140,15 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error { } + // If the channel doesn't exist in our database, we cannot + // apply the updated policy. + if !exists { + return newErrf(ErrIgnored, "Ignoring update "+ + "(flags=%v|%v) for unknown chan_id=%v", + msg.MessageFlags, msg.ChannelFlags, + msg.ChannelID) + } + // As edges are directional edge node has a unique policy for // the direction of the edge they control. Therefore we first // check if we already have the most up to date information for @@ -1174,36 +1181,6 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error { } } - if !exists && !r.cfg.AssumeChannelValid { - // Before we can update the channel information, we'll - // ensure that the target channel is still open by - // querying the utxo-set for its existence. - chanPoint, fundingTxOut, err := r.fetchChanPoint( - &channelID, - ) - if err != nil { - r.rejectMtx.Lock() - r.rejectCache[msg.ChannelID] = struct{}{} - r.rejectMtx.Unlock() - - return errors.Errorf("unable to fetch chan "+ - "point for chan_id=%v: %v", - msg.ChannelID, err) - } - _, err = r.cfg.Chain.GetUtxo( - chanPoint, fundingTxOut.PkScript, - channelID.BlockHeight, - ) - if err != nil { - r.rejectMtx.Lock() - r.rejectCache[msg.ChannelID] = struct{}{} - r.rejectMtx.Unlock() - - return errors.Errorf("unable to fetch utxo for "+ - "chan_id=%v: %v", msg.ChannelID, err) - } - } - // Now that we know this isn't a stale update, we'll apply the // new edge policy to the proper directional edge within the // channel graph.