gossiper: private channel cleanup + comments

This commit adds some comments and does some cleanup
of the logic that makes sure non-public channels
(channels with no AuthProof) are not broadcasted
to the network.
This commit is contained in:
Johan T. Halseth 2017-11-13 17:12:57 -08:00 committed by Olaoluwa Osuntokun
parent 48e22219c0
commit 10b838e9b4

@ -729,6 +729,17 @@ func (d *AuthenticatedGossiper) retransmitStaleChannels() error {
info *channeldb.ChannelEdgeInfo, info *channeldb.ChannelEdgeInfo,
edge *channeldb.ChannelEdgePolicy) error { edge *channeldb.ChannelEdgePolicy) error {
// If there's no auth proof attaced to this edge, it
// means that it is a private channel not meant to be
// announced to the greater network, so avoid sending
// channel updates for this channel to not leak its
// existence.
if info.AuthProof == nil {
log.Debugf("Skipping retransmission of channel "+
"without AuthProof: %v", info)
return nil
}
const broadcastInterval = time.Hour * 24 const broadcastInterval = time.Hour * 24
timeElapsed := time.Since(edge.LastUpdate) timeElapsed := time.Since(edge.LastUpdate)
@ -736,7 +747,7 @@ func (d *AuthenticatedGossiper) retransmitStaleChannels() error {
// If it's been a full day since we've re-broadcasted the // If it's been a full day since we've re-broadcasted the
// channel, add the channel to the set of edges we need to // channel, add the channel to the set of edges we need to
// update. // update.
if timeElapsed >= broadcastInterval && info.AuthProof != nil { if timeElapsed >= broadcastInterval {
edgesToUpdate = append(edgesToUpdate, updateTuple{ edgesToUpdate = append(edgesToUpdate, updateTuple{
info: info, info: info,
edge: edge, edge: edge,
@ -1106,23 +1117,27 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(nMsg *networkMsg) []l
return nil return nil
} }
// If this is a local ChannelUpdate announcement, send it to // If this is a local ChannelUpdate without an AuthProof, it means
// our peer. // it is an update to a channel that is not (yet) supposed to be
if !nMsg.isRemote { // announced to the greater network. However, our channel counter
// Get our peer's public key // party will need to be given the update, so we'll try sending
// the update directly to the remote peer.
if !nMsg.isRemote && chanInfo.AuthProof == nil {
// Get our peer's public key.
var remotePeer *btcec.PublicKey var remotePeer *btcec.PublicKey
switch msg.Flags { switch {
case 0: case msg.Flags&lnwire.ChanUpdateDirection == 0:
remotePeer = chanInfo.NodeKey2 remotePeer = chanInfo.NodeKey2
case 1: case msg.Flags&lnwire.ChanUpdateDirection == 1:
remotePeer = chanInfo.NodeKey1 remotePeer = chanInfo.NodeKey1
} }
// Send ChannelUpdate to remotePeer // Send ChannelUpdate directly to remotePeer.
// TODO(halseth): make reliable send?
if err = d.cfg.SendToPeer(remotePeer, msg); err != nil { if err = d.cfg.SendToPeer(remotePeer, msg); err != nil {
log.Errorf("unable to send channel update "+ log.Errorf("unable to send channel update "+
"message to peer: %x", "message to peer %x: %v",
remotePeer.SerializeCompressed()) remotePeer.SerializeCompressed(), err)
} }
} }
@ -1149,7 +1164,8 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(nMsg *networkMsg) []l
prefix = "remote" prefix = "remote"
} }
log.Infof("Received new channel announcement: %v", spew.Sdump(msg)) log.Infof("Received new %v channel announcement: %v", prefix,
spew.Sdump(msg))
// By the specification, channel announcement proofs should be // By the specification, channel announcement proofs should be
// sent after some number of confirmations after channel was // sent after some number of confirmations after channel was
@ -1351,6 +1367,8 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(nMsg *networkMsg) []l
remotePeer = chanInfo.NodeKey1 remotePeer = chanInfo.NodeKey1
} }
log.Debugf("Sending local AnnounceSignatures message "+
"to peer(%x)", remotePeer.SerializeCompressed())
if err = d.cfg.SendToPeer(remotePeer, msg); err != nil { if err = d.cfg.SendToPeer(remotePeer, msg); err != nil {
log.Errorf("unable to send announcement "+ log.Errorf("unable to send announcement "+
"message to peer: %x", "message to peer: %x",