From 0d28bb14cb5fa7805923a7b8b3c9dadcaf5f9435 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 4 Oct 2017 20:31:24 -0700 Subject: [PATCH] discovery: also return latest ChannelAnnouncement from updateChannel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds an additional return value to the updateChannel method. We also now return the original ChannelAnnouncement, this can be useful as it let’s the caller ensure that the channel announcement will be broadcast along side the new channel update. --- discovery/gossiper.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index c0da5f53..b4ef3590 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1195,7 +1195,7 @@ func (d *AuthenticatedGossiper) synchronizeWithNode(syncReq *syncRequest) error // updateChannel creates a new fully signed update for the channel, and updates // the underlying graph with the new state. func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo, - edge *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) { + edge *channeldb.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement, *lnwire.ChannelUpdate, error) { edge.LastUpdate = time.Now() chanUpdate := &lnwire.ChannelUpdate{ @@ -1214,7 +1214,7 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo, // digest of the channel announcement itself. sig, err := SignAnnouncement(d.cfg.AnnSigner, d.selfKey, chanUpdate) if err != nil { - return nil, err + return nil, nil, err } // Next, we'll set the new signature in place, and update the reference @@ -1226,15 +1226,36 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo, // before committing it to the slice returned. err = d.validateChannelUpdateAnn(d.selfKey, chanUpdate) if err != nil { - return nil, fmt.Errorf("generated invalid channel update "+ - "sig: %v", err) + return nil, nil, fmt.Errorf("generated invalid channel "+ + "update sig: %v", err) } // Finally, we'll write the new edge policy to disk. edge.Node.PubKey.Curve = nil if err := d.cfg.Router.UpdateEdge(edge); err != nil { - return nil, err + return nil, nil, err } - return chanUpdate, err + // We'll also create the original channel announcement so the two can + // be broadcast along side each other (if necessary), but only if we + // have a full channel announcement for this channel. + var chanAnn *lnwire.ChannelAnnouncement + if info.AuthProof != nil { + chanID := lnwire.NewShortChanIDFromInt(info.ChannelID) + chanAnn = &lnwire.ChannelAnnouncement{ + NodeSig1: info.AuthProof.NodeSig1, + NodeSig2: info.AuthProof.NodeSig2, + ShortChannelID: chanID, + BitcoinSig1: info.AuthProof.BitcoinSig1, + BitcoinSig2: info.AuthProof.BitcoinSig2, + NodeID1: info.NodeKey1, + NodeID2: info.NodeKey2, + ChainHash: info.ChainHash, + BitcoinKey1: info.BitcoinKey1, + Features: lnwire.NewFeatureVector([]lnwire.Feature{}), + BitcoinKey2: info.BitcoinKey2, + } + } + + return chanAnn, chanUpdate, err }