What changed, and why it matters
This commit is a routine code refactoring in the LND Lightning Network implementation. It introduces a new Go interface called NodeAnnouncement and makes the existing NodeAnnouncement1 and NodeAnnouncement2 message types implement it. There is no change to network behavior, no bug fix, and no security-related functionality added or removed.
No security action required. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds a NodeAnnouncement interface in lnwire/interfaces.go requiring NodePub(), NodeFeatures(), TimestampDesc(), and the embedded Message interface. It then adds the three required methods to NodeAnnouncement1 and NodeAnnouncement2, plus compile-time interface assertions. The methods are simple accessors: NodePub returns the 33-byte node ID, NodeFeatures wraps the feature bitvector, and TimestampDesc formats the timestamp or block height. No parsing, serialization, signature, or protocol logic is modified.
Changed components
lnwire/interfaces.golnwire/node_announcement.golnwire/node_announcement_2.goInspect captured patch +68 / −0
diff --git a/lnwire/interfaces.go b/lnwire/interfaces.go
index 3a8b7cb..975cd6c 100644
--- a/lnwire/interfaces.go
+++ b/lnwire/interfaces.go
@@ -91,6 +91,22 @@ type ChannelUpdate interface {
Message
}
+// NodeAnnouncement is an interface that must be satisfied by any message used
+// to announce the existence of a node.
+type NodeAnnouncement interface {
+ // NodePub returns the identity public key of the node.
+ NodePub() [33]byte
+
+ // NodeFeatures returns the set of features supported by the node.
+ NodeFeatures() *FeatureVector
+
+ // TimestampDesc returns a human-readable description of the
+ // timestamp of the announcement.
+ TimestampDesc() string
+
+ Message
+}
+
// ForwardingPolicy defines the set of forwarding constraints advertised in a
// ChannelUpdate message.
type ForwardingPolicy struct {
diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go
index 0a7c605..384327f 100644
--- a/lnwire/node_announcement.go
+++ b/lnwire/node_announcement.go
@@ -104,6 +104,10 @@ type NodeAnnouncement1 struct {
// lnwire.Message interface.
var _ Message = (*NodeAnnouncement1)(nil)
+// A compile time check to ensure NodeAnnouncement1 implements the
+// lnwire.NodeAnnouncement interface.
+var _ NodeAnnouncement = (*NodeAnnouncement1)(nil)
+
// A compile time check to ensure NodeAnnouncement1 implements the
// lnwire.SizeableMessage interface.
var _ SizeableMessage = (*NodeAnnouncement1)(nil)
@@ -217,3 +221,25 @@ func (a *NodeAnnouncement1) DataToSign() ([]byte, error) {
func (a *NodeAnnouncement1) SerializedSize() (uint32, error) {
return MessageSerializedSize(a)
}
+
+// NodePub returns the identity public key of the node.
+//
+// NOTE: part of the NodeAnnouncement interface.
+func (a *NodeAnnouncement1) NodePub() [33]byte {
+ return a.NodeID
+}
+
+// NodeFeatures returns the set of features supported by the node.
+//
+// NOTE: part of the NodeAnnouncement interface.
+func (a *NodeAnnouncement1) NodeFeatures() *FeatureVector {
+ return NewFeatureVector(a.Features, Features)
+}
+
+// TimestampDesc returns a human-readable description of the timestamp of the
+// announcement.
+//
+// NOTE: part of the NodeAnnouncement interface.
+func (a *NodeAnnouncement1) TimestampDesc() string {
+ return fmt.Sprintf("timestamp=%d", a.Timestamp)
+}
diff --git a/lnwire/node_announcement_2.go b/lnwire/node_announcement_2.go
index 23fcc50..0b7142d 100644
--- a/lnwire/node_announcement_2.go
+++ b/lnwire/node_announcement_2.go
@@ -199,10 +199,36 @@ func (n *NodeAnnouncement2) MsgType() MessageType {
return MsgNodeAnnouncement2
}
+// NodePub returns the identity public key of the node.
+//
+// NOTE: part of the NodeAnnouncement interface.
+func (n *NodeAnnouncement2) NodePub() [33]byte {
+ return n.NodeID.Val
+}
+
+// NodeFeatures returns the set of features supported by the node.
+//
+// NOTE: part of the NodeAnnouncement interface.
+func (n *NodeAnnouncement2) NodeFeatures() *FeatureVector {
+ return NewFeatureVector(&n.Features.Val, Features)
+}
+
+// TimestampDesc returns a human-readable description of the timestamp of the
+// announcement.
+//
+// NOTE: part of the NodeAnnouncement interface.
+func (n *NodeAnnouncement2) TimestampDesc() string {
+ return fmt.Sprintf("block_height=%d", n.BlockHeight.Val)
+}
+
// A compile-time check to ensure NodeAnnouncement2 implements the Message
// interface.
var _ Message = (*NodeAnnouncement2)(nil)
+// A compile time check to ensure NodeAnnouncement2 implements the
+// lnwire.NodeAnnouncement interface.
+var _ NodeAnnouncement = (*NodeAnnouncement2)(nil)
+
// A compile-time check to ensure NodeAnnouncement2 implements the
// PureTLVMessage interface.
var _ PureTLVMessage = (*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.