routing/router: don't apply channel policy updates for unknown channels

This commit is contained in:
Johan T. Halseth 2018-12-04 14:58:39 +01:00
parent e10fe91f10
commit 23ce82f4e3
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

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