multi: add ToChannelAnnouncement helper on ChannelEdgeInfo

So that we have one place that converts from our `models` struct to the
`lnwire.ChannelAnnouncement` struct.

The commit also refactors netann.CreateChanAnnouncement to only take a
ChannelEdgeInfo and get the proof from there instead of needing the
proof to be passed in separately.

Add ToChannelAnnouncement() method to ChannelEdgeInfo that converts
the model struct to a lnwire.ChannelAnnouncement1 message. This:

- Centralizes the conversion logic in one place instead of scattered
  across multiple call sites
- Validates that AuthProof is present (can't create announcement
  without proof)
- Currently only supports v1 channels, returning error for v2

Refactor netann.CreateChanAnnouncement to use this helper and remove
the separate chanProof parameter since proof is now accessed from
within ChannelEdgeInfo. This improves encapsulation and reduces
parameter count.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:22 +02:00
1 parent ba6222b521
commit 830b9db69c
5 files changed
+82 -80

No files matched your search

+13 -36
View File
@@ -2096,10 +2096,14 @@ func (d *AuthenticatedGossiper) processRejectedEdge(_ context.Context,
return nil, nil
}
// Attach the proof to the channel info before creating the
// announcement.
chanInfo.AuthProof = proof
// We'll then create then validate the new fully assembled
// announcement.
chanAnn, e1Ann, e2Ann, err := netann.CreateChanAnnouncement(
proof, chanInfo, e1, e2,
chanInfo, e1, e2,
)
if err != nil {
return nil, err
@@ -2492,44 +2496,13 @@ func (d *AuthenticatedGossiper) updateChannel(ctx context.Context,
// have a full channel announcement for this channel.
var chanAnn *lnwire.ChannelAnnouncement1
if info.AuthProof != nil {
chanID := lnwire.NewShortChanIDFromInt(info.ChannelID)
chanAnn = &lnwire.ChannelAnnouncement1{
ShortChannelID: chanID,
NodeID1: info.NodeKey1Bytes,
NodeID2: info.NodeKey2Bytes,
ChainHash: info.ChainHash,
BitcoinKey1: info.BitcoinKey1Bytes,
Features: lnwire.NewRawFeatureVector(),
BitcoinKey2: info.BitcoinKey2Bytes,
ExtraOpaqueData: info.ExtraOpaqueData,
}
chanAnn.NodeSig1, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.NodeSig1(),
)
if err != nil {
return nil, nil, err
}
chanAnn.NodeSig2, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.NodeSig2(),
)
if err != nil {
return nil, nil, err
}
chanAnn.BitcoinSig1, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.BitcoinSig1(),
)
if err != nil {
return nil, nil, err
}
chanAnn.BitcoinSig2, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.BitcoinSig2(),
)
chanAnn, err = info.ToChannelAnnouncement()
if err != nil {
return nil, nil, err
}
}
return chanAnn, chanUpdate, err
return chanAnn, chanUpdate, nil
}
// SyncManager returns the gossiper's SyncManager instance.
@@ -3703,7 +3676,7 @@ func (d *AuthenticatedGossiper) handleAnnSig(ctx context.Context,
ann.ChannelID, peerID)
ca, _, _, err := netann.CreateChanAnnouncement(
chanInfo.AuthProof, chanInfo, e1, e2,
chanInfo, e1, e2,
)
if err != nil {
log.Errorf("unable to gen ann: %v",
@@ -3782,8 +3755,12 @@ func (d *AuthenticatedGossiper) handleAnnSig(ctx context.Context,
)
}
// Attach the proof to the channel info before creating the
// announcement.
chanInfo.AuthProof = dbProof
chanAnn, e1Ann, e2Ann, err := netann.CreateChanAnnouncement(
dbProof, chanInfo, e1, e2,
chanInfo, e1, e2,
)
if err != nil {
log.Error(err)