lnwire: let gossip messages implement GossipMessage
What changed, and why it matters
This commit is a straightforward code organization change. It adds a GossipVersion() method to several existing Lightning network gossip message types and updates their interfaces to require it. There is no bug fix, behavior change, or security patch visible in the diff.
No security action required. Treat as normal refactoring/development.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds GossipVersion() implementations returning GossipVersion1 or GossipVersion2 to AnnounceSignatures1/2, ChannelAnnouncement1/2, ChannelUpdate1/2, and NodeAnnouncement1/2. It also embeds the GossipMessage interface into AnnounceSignatures, ChannelAnnouncement, ChannelUpdate, and NodeAnnouncement interfaces. This is purely an interface/API refactor with no functional or security-relevant logic changes.
Changed components
lnwire/announcement_signatures.golnwire/announcement_signatures_2.golnwire/channel_announcement.golnwire/channel_announcement_2.golnwire/channel_update.golnwire/channel_update_2.golnwire/interfaces.golnwire/node_announcement.golnwire/node_announcement_2.goInspect captured patch +60 / −0
diff --git a/lnwire/announcement_signatures.go b/lnwire/announcement_signatures.go
index cf8f68b..29ada70 100644
--- a/lnwire/announcement_signatures.go
+++ b/lnwire/announcement_signatures.go
@@ -121,3 +121,10 @@ func (a *AnnounceSignatures1) SCID() ShortChannelID {
func (a *AnnounceSignatures1) ChanID() ChannelID {
return a.ChannelID
}
+
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (a *AnnounceSignatures1) GossipVersion() GossipVersion {
+ return GossipVersion1
+}
diff --git a/lnwire/announcement_signatures_2.go b/lnwire/announcement_signatures_2.go
index 04e4c0a..a2806f1 100644
--- a/lnwire/announcement_signatures_2.go
+++ b/lnwire/announcement_signatures_2.go
@@ -102,6 +102,13 @@ func (a *AnnounceSignatures2) MsgType() MessageType {
return MsgAnnounceSignatures2
}
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (a *AnnounceSignatures2) GossipVersion() GossipVersion {
+ return GossipVersion2
+}
+
// SerializedSize returns the serialized size of the message in bytes.
//
// This is part of the lnwire.SizeableMessage interface.
diff --git a/lnwire/channel_announcement.go b/lnwire/channel_announcement.go
index 05161cc..cab8407 100644
--- a/lnwire/channel_announcement.go
+++ b/lnwire/channel_announcement.go
@@ -232,6 +232,13 @@ func (a *ChannelAnnouncement1) SCID() ShortChannelID {
return a.ShortChannelID
}
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (a *ChannelAnnouncement1) GossipVersion() GossipVersion {
+ return GossipVersion1
+}
+
// A compile-time check to ensure that ChannelAnnouncement1 implements the
// ChannelAnnouncement interface.
var _ ChannelAnnouncement = (*ChannelAnnouncement1)(nil)
diff --git a/lnwire/channel_announcement_2.go b/lnwire/channel_announcement_2.go
index a82624a..9227584 100644
--- a/lnwire/channel_announcement_2.go
+++ b/lnwire/channel_announcement_2.go
@@ -307,6 +307,13 @@ func (c *ChannelAnnouncement2) SCID() ShortChannelID {
return c.ShortChannelID.Val
}
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (c *ChannelAnnouncement2) GossipVersion() GossipVersion {
+ return GossipVersion2
+}
+
// A compile-time check to ensure that ChannelAnnouncement2 implements the
// ChannelAnnouncement interface.
var _ ChannelAnnouncement = (*ChannelAnnouncement2)(nil)
diff --git a/lnwire/channel_update.go b/lnwire/channel_update.go
index 2dc4a11..09b8044 100644
--- a/lnwire/channel_update.go
+++ b/lnwire/channel_update.go
@@ -363,6 +363,13 @@ func (a *ChannelUpdate1) ForwardingPolicy() *ForwardingPolicy {
}
}
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (a *ChannelUpdate1) GossipVersion() GossipVersion {
+ return GossipVersion1
+}
+
// CmpAge can be used to determine if the update is older or newer than the
// passed update. It returns 1 if this update is newer, -1 if it is older, and
// 0 if they are the same age.
diff --git a/lnwire/channel_update_2.go b/lnwire/channel_update_2.go
index 7fe7670..8e82fe9 100644
--- a/lnwire/channel_update_2.go
+++ b/lnwire/channel_update_2.go
@@ -85,6 +85,13 @@ type ChannelUpdate2 struct {
ExtraSignedFields
}
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (c *ChannelUpdate2) GossipVersion() GossipVersion {
+ return GossipVersion2
+}
+
// Encode serializes the target ChannelUpdate2 into the passed io.Writer
// observing the protocol version specified.
//
diff --git a/lnwire/interfaces.go b/lnwire/interfaces.go
index 64d87f7..115b07d 100644
--- a/lnwire/interfaces.go
+++ b/lnwire/interfaces.go
@@ -45,6 +45,7 @@ type AnnounceSignatures interface {
ChanID() ChannelID
Message
+ GossipMessage
}
// ChannelAnnouncement is an interface that must be satisfied by any message
@@ -66,6 +67,7 @@ type ChannelAnnouncement interface {
Node2KeyBytes() [33]byte
Message
+ GossipMessage
}
// CompareResult represents the result after comparing two things.
@@ -122,6 +124,7 @@ type ChannelUpdate interface {
SetSCID(scid ShortChannelID)
Message
+ GossipMessage
}
// NodeAnnouncement is an interface that must be satisfied by any message used
@@ -138,6 +141,7 @@ type NodeAnnouncement interface {
TimestampDesc() string
Message
+ GossipMessage
}
// ForwardingPolicy defines the set of forwarding constraints advertised in a
diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go
index 384327f..468ac79 100644
--- a/lnwire/node_announcement.go
+++ b/lnwire/node_announcement.go
@@ -243,3 +243,10 @@ func (a *NodeAnnouncement1) NodeFeatures() *FeatureVector {
func (a *NodeAnnouncement1) TimestampDesc() string {
return fmt.Sprintf("timestamp=%d", a.Timestamp)
}
+
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (a *NodeAnnouncement1) GossipVersion() GossipVersion {
+ return GossipVersion1
+}
diff --git a/lnwire/node_announcement_2.go b/lnwire/node_announcement_2.go
index 0b7142d..93a3792 100644
--- a/lnwire/node_announcement_2.go
+++ b/lnwire/node_announcement_2.go
@@ -221,6 +221,13 @@ func (n *NodeAnnouncement2) TimestampDesc() string {
return fmt.Sprintf("block_height=%d", n.BlockHeight.Val)
}
+// GossipVersion returns the gossip version that this message is part of.
+//
+// NOTE: this is part of the GossipMessage interface.
+func (n *NodeAnnouncement2) GossipVersion() GossipVersion {
+ return GossipVersion2
+}
+
// A compile-time check to ensure NodeAnnouncement2 implements the Message
// interface.
var _ Message = (*NodeAnnouncement2)(nil)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.