Merge pull request #4899 from halseth/ignore-local-ann-from-remote

[gossiper] Ignore received ChannelAnnouncements for own channels
This commit is contained in:
Johan T. Halseth authored and GitHub committed 2021-02-11 18:39:15 +01:00
commit b52e872878
3 files changed
+342 -221

No files matched your search

+18 -2
View File
@@ -542,6 +542,22 @@ func (d *AuthenticatedGossiper) ProcessRemoteAnnouncement(msg lnwire.Message,
errChan <- nil errChan <- nil
return errChan return errChan
// To avoid inserting edges in the graph for our own channels that we
// have already closed, we ignore such channel announcements coming
// from the remote.
case *lnwire.ChannelAnnouncement:
ownKey := d.selfKey.SerializeCompressed()
ownErr := fmt.Errorf("ignoring remote ChannelAnnouncement " +
"for own channel")
if bytes.Equal(m.NodeID1[:], ownKey) ||
bytes.Equal(m.NodeID2[:], ownKey) {
log.Warn(ownErr)
errChan <- ownErr
return errChan
}
} }
nMsg := &networkMsg{ nMsg := &networkMsg{
@@ -574,7 +590,7 @@ func (d *AuthenticatedGossiper) ProcessRemoteAnnouncement(msg lnwire.Message,
// entire channel announcement and update messages will be re-constructed and // entire channel announcement and update messages will be re-constructed and
// broadcast to the rest of the network. // broadcast to the rest of the network.
func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message, func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message,
source *btcec.PublicKey, optionalFields ...OptionalMsgField) chan error { optionalFields ...OptionalMsgField) chan error {
optionalMsgFields := &optionalMsgFields{} optionalMsgFields := &optionalMsgFields{}
optionalMsgFields.apply(optionalFields...) optionalMsgFields.apply(optionalFields...)
@@ -583,7 +599,7 @@ func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message,
msg: msg, msg: msg,
optionalMsgFields: optionalMsgFields, optionalMsgFields: optionalMsgFields,
isRemote: false, isRemote: false,
source: source, source: d.selfKey,
err: make(chan error, 1), err: make(chan error, 1),
} }
+319 -207
View File
File diff suppressed because it is too large. Load diff
+5 -12
View File
@@ -670,7 +670,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
// With the announcement generated, we'll sign it to properly // With the announcement generated, we'll sign it to properly
// authenticate the message on the network. // authenticate the message on the network.
authSig, err := netann.SignAnnouncement( authSig, err := netann.SignAnnouncement(
s.nodeSigner, s.identityECDH.PubKey(), nodeAnn, s.nodeSigner, nodeKeyECDH.PubKey(), nodeAnn,
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to generate signature for "+ return nil, fmt.Errorf("unable to generate signature for "+
@@ -824,7 +824,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
IgnoreHistoricalFilters: cfg.IgnoreHistoricalGossipFilters, IgnoreHistoricalFilters: cfg.IgnoreHistoricalGossipFilters,
PinnedSyncers: cfg.Gossip.PinnedSyncers, PinnedSyncers: cfg.Gossip.PinnedSyncers,
}, },
s.identityECDH.PubKey(), nodeKeyECDH.PubKey(),
) )
s.localChanMgr = &localchans.Manager{ s.localChanMgr = &localchans.Manager{
@@ -1026,13 +1026,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement, error) { CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement, error) {
return s.genNodeAnnouncement(true) return s.genNodeAnnouncement(true)
}, },
SendAnnouncement: func(msg lnwire.Message, SendAnnouncement: s.authGossiper.ProcessLocalAnnouncement,
optionalFields ...discovery.OptionalMsgField) chan error {
return s.authGossiper.ProcessLocalAnnouncement(
msg, nodeKeyECDH.PubKey(), optionalFields...,
)
},
NotifyWhenOnline: s.NotifyWhenOnline, NotifyWhenOnline: s.NotifyWhenOnline,
TempChanIDSeed: chanIDSeed, TempChanIDSeed: chanIDSeed,
FindChannel: func(chanID lnwire.ChannelID) ( FindChannel: func(chanID lnwire.ChannelID) (
@@ -1415,7 +1409,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
RetryDuration: time.Second * 5, RetryDuration: time.Second * 5,
TargetOutbound: 100, TargetOutbound: 100,
Dial: noiseDial( Dial: noiseDial(
s.identityECDH, s.cfg.net, s.cfg.ConnectionTimeout, nodeKeyECDH, s.cfg.net, s.cfg.ConnectionTimeout,
), ),
OnConnection: s.OutboundPeerConnected, OnConnection: s.OutboundPeerConnected,
}) })
@@ -3792,8 +3786,7 @@ func (s *server) fetchLastChanUpdate() func(lnwire.ShortChannelID) (
// applyChannelUpdate applies the channel update to the different sub-systems of // applyChannelUpdate applies the channel update to the different sub-systems of
// the server. // the server.
func (s *server) applyChannelUpdate(update *lnwire.ChannelUpdate) error { func (s *server) applyChannelUpdate(update *lnwire.ChannelUpdate) error {
pubKey := s.identityECDH.PubKey() errChan := s.authGossiper.ProcessLocalAnnouncement(update)
errChan := s.authGossiper.ProcessLocalAnnouncement(update, pubKey)
select { select {
case err := <-errChan: case err := <-errChan:
return err return err