discovery: also return latest ChannelAnnouncement from updateChannel

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-10-04 20:31:24 -07:00
parent 4be2e95a78
commit 0d28bb14cb
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1195,7 +1195,7 @@ func (d *AuthenticatedGossiper) synchronizeWithNode(syncReq *syncRequest) error
// updateChannel creates a new fully signed update for the channel, and updates // updateChannel creates a new fully signed update for the channel, and updates
// the underlying graph with the new state. // the underlying graph with the new state.
func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo, 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() edge.LastUpdate = time.Now()
chanUpdate := &lnwire.ChannelUpdate{ chanUpdate := &lnwire.ChannelUpdate{
@ -1214,7 +1214,7 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
// digest of the channel announcement itself. // digest of the channel announcement itself.
sig, err := SignAnnouncement(d.cfg.AnnSigner, d.selfKey, chanUpdate) sig, err := SignAnnouncement(d.cfg.AnnSigner, d.selfKey, chanUpdate)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
// Next, we'll set the new signature in place, and update the reference // 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. // before committing it to the slice returned.
err = d.validateChannelUpdateAnn(d.selfKey, chanUpdate) err = d.validateChannelUpdateAnn(d.selfKey, chanUpdate)
if err != nil { if err != nil {
return nil, fmt.Errorf("generated invalid channel update "+ return nil, nil, fmt.Errorf("generated invalid channel "+
"sig: %v", err) "update sig: %v", err)
} }
// Finally, we'll write the new edge policy to disk. // Finally, we'll write the new edge policy to disk.
edge.Node.PubKey.Curve = nil edge.Node.PubKey.Curve = nil
if err := d.cfg.Router.UpdateEdge(edge); err != 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
} }