From 0b4ff2aabbbb62bc886ff27bfa3b993729369e2a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 3 Sep 2017 16:41:01 -0700 Subject: [PATCH] discovery: ignore any incoming channel ann's for an unknown chain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an existing bug in the announcement processing of the authenticated gossiper. We will now only examine an incoming announcement for validity if it targets the chain that we’re currently active on. --- discovery/gossiper.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index a81afb02..bcc482fd 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -15,6 +15,7 @@ import ( "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing" "github.com/roasbeef/btcd/btcec" + "github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/wire" ) @@ -49,6 +50,15 @@ type feeUpdateRequest struct { // Config defines the configuration for the service. ALL elements within the // configuration MUST be non-nil for the service to carry out its duties. type Config struct { + // ChainHash is a hash that indicates which resident chain of the + // AuthenticatedGossiper. Any announcements that don't match this + // chain hash will be ignored. + // + // TODO(roasbeef): eventually make into map so can de-multiplex + // incoming announcements + // * also need to do same for Notifier + ChainHash chainhash.Hash + // Router is the subsystem which is responsible for managing the // topology of lightning network. After incoming channel, node, channel // updates announcements are validated they are sent to the router in @@ -678,6 +688,15 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(nMsg *networkMsg) []l // the existence of a channel and not yet the routing policies in // either direction of the channel. case *lnwire.ChannelAnnouncement: + // We'll ignore any channel announcements that target any chain + // other than the set of chains we know of. + if !bytes.Equal(msg.ChainHash[:], d.cfg.ChainHash[:]) { + log.Error("Ignoring ChannelAnnouncement from "+ + "chain=%v, gossiper on chain=%v", msg.ChainHash, + d.cfg.ChainHash) + return nil + } + // If the advertised inclusionary block is beyond our knowledge // of the chain tip, then we'll put the announcement in limbo // to be fully verified once we advance forward in the chain. @@ -771,6 +790,15 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(nMsg *networkMsg) []l // that the directional information for an already known channel has // been updated. case *lnwire.ChannelUpdate: + // We'll ignore any channel announcements that target any chain + // other than the set of chains we know of. + if !bytes.Equal(msg.ChainHash[:], d.cfg.ChainHash[:]) { + log.Error("Ignoring ChannelUpdate from "+ + "chain=%v, gossiper on chain=%v", msg.ChainHash, + d.cfg.ChainHash) + return nil + } + blockHeight := msg.ShortChannelID.BlockHeight shortChanID := msg.ShortChannelID.ToUint64()