• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15838907453

24 Jun 2025 01:26AM UTC coverage: 57.079% (-11.1%) from 68.172%
15838907453

Pull #9982

github

web-flow
Merge e42780be2 into 45c15646c
Pull Request #9982: lnwire+lnwallet: add LocalNonces field for splice nonce coordination w/ taproot channels

103 of 167 new or added lines in 5 files covered. (61.68%)

30191 existing lines in 463 files now uncovered.

96331 of 168768 relevant lines covered (57.08%)

0.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.57
/lnwire/node_announcement.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "image/color"
7
        "io"
8
        "net"
9
        "unicode/utf8"
10
)
11

12
// ErrUnknownAddrType is an error returned if we encounter an unknown address type
13
// when parsing addresses.
14
type ErrUnknownAddrType struct {
15
        addrType addressType
16
}
17

18
// Error returns a human readable string describing the error.
19
//
20
// NOTE: implements the error interface.
21
func (e ErrUnknownAddrType) Error() string {
×
22
        return fmt.Sprintf("unknown address type: %v", e.addrType)
×
23
}
×
24

25
// ErrInvalidNodeAlias is an error returned if a node alias we parse on the
26
// wire is invalid, as in it has non UTF-8 characters.
27
type ErrInvalidNodeAlias struct{}
28

29
// Error returns a human readable string describing the error.
30
//
31
// NOTE: implements the error interface.
32
func (e ErrInvalidNodeAlias) Error() string {
×
33
        return "node alias has non-utf8 characters"
×
34
}
×
35

36
// NodeAlias is a hex encoded UTF-8 string that may be displayed as an
37
// alternative to the node's ID. Notice that aliases are not unique and may be
38
// freely chosen by the node operators.
39
type NodeAlias [32]byte
40

41
// NewNodeAlias creates a new instance of a NodeAlias. Verification is
42
// performed on the passed string to ensure it meets the alias requirements.
43
func NewNodeAlias(s string) (NodeAlias, error) {
1✔
44
        var n NodeAlias
1✔
45

1✔
46
        if len(s) > 32 {
2✔
47
                return n, fmt.Errorf("alias too large: max is %v, got %v", 32,
1✔
48
                        len(s))
1✔
49
        }
1✔
50

51
        if !utf8.ValidString(s) {
1✔
UNCOV
52
                return n, &ErrInvalidNodeAlias{}
×
UNCOV
53
        }
×
54

55
        copy(n[:], []byte(s))
1✔
56
        return n, nil
1✔
57
}
58

59
// String returns a utf8 string representation of the alias bytes.
60
func (n NodeAlias) String() string {
1✔
61
        // Trim trailing zero-bytes for presentation
1✔
62
        return string(bytes.Trim(n[:], "\x00"))
1✔
63
}
1✔
64

65
// NodeAnnouncement message is used to announce the presence of a Lightning
66
// node and also to signal that the node is accepting incoming connections.
67
// Each NodeAnnouncement authenticating the advertised information within the
68
// announcement via a signature using the advertised node pubkey.
69
type NodeAnnouncement struct {
70
        // Signature is used to prove the ownership of node id.
71
        Signature Sig
72

73
        // Features is the list of protocol features this node supports.
74
        Features *RawFeatureVector
75

76
        // Timestamp allows ordering in the case of multiple announcements.
77
        Timestamp uint32
78

79
        // NodeID is a public key which is used as node identification.
80
        NodeID [33]byte
81

82
        // RGBColor is used to customize their node's appearance in maps and
83
        // graphs
84
        RGBColor color.RGBA
85

86
        // Alias is used to customize their node's appearance in maps and
87
        // graphs
88
        Alias NodeAlias
89

90
        // Address includes two specification fields: 'ipv6' and 'port' on
91
        // which the node is accepting incoming connections.
92
        Addresses []net.Addr
93

94
        // ExtraOpaqueData is the set of data that was appended to this
95
        // message, some of which we may not actually know how to iterate or
96
        // parse. By holding onto this data, we ensure that we're able to
97
        // properly validate the set of signatures that cover these new fields,
98
        // and ensure we're able to make upgrades to the network in a forwards
99
        // compatible manner.
100
        ExtraOpaqueData ExtraOpaqueData
101
}
102

103
// A compile time check to ensure NodeAnnouncement implements the
104
// lnwire.Message interface.
105
var _ Message = (*NodeAnnouncement)(nil)
106

107
// A compile time check to ensure NodeAnnouncement implements the
108
// lnwire.SizeableMessage interface.
109
var _ SizeableMessage = (*NodeAnnouncement)(nil)
110

111
// Decode deserializes a serialized NodeAnnouncement stored in the passed
112
// io.Reader observing the specified protocol version.
113
//
114
// This is part of the lnwire.Message interface.
115
func (a *NodeAnnouncement) Decode(r io.Reader, _ uint32) error {
1✔
116
        err := ReadElements(r,
1✔
117
                &a.Signature,
1✔
118
                &a.Features,
1✔
119
                &a.Timestamp,
1✔
120
                &a.NodeID,
1✔
121
                &a.RGBColor,
1✔
122
                &a.Alias,
1✔
123
                &a.Addresses,
1✔
124
                &a.ExtraOpaqueData,
1✔
125
        )
1✔
126
        if err != nil {
1✔
UNCOV
127
                return err
×
UNCOV
128
        }
×
129

130
        return a.ExtraOpaqueData.ValidateTLV()
1✔
131
}
132

133
// Encode serializes the target NodeAnnouncement into the passed io.Writer
134
// observing the protocol version specified.
135
//
136
// This is part of the lnwire.Message interface.
137
func (a *NodeAnnouncement) Encode(w *bytes.Buffer, pver uint32) error {
1✔
138
        if err := WriteSig(w, a.Signature); err != nil {
1✔
139
                return err
×
140
        }
×
141

142
        if err := WriteRawFeatureVector(w, a.Features); err != nil {
1✔
143
                return err
×
144
        }
×
145

146
        if err := WriteUint32(w, a.Timestamp); err != nil {
1✔
147
                return err
×
148
        }
×
149

150
        if err := WriteBytes(w, a.NodeID[:]); err != nil {
1✔
151
                return err
×
152
        }
×
153

154
        if err := WriteColorRGBA(w, a.RGBColor); err != nil {
1✔
155
                return err
×
156
        }
×
157

158
        if err := WriteNodeAlias(w, a.Alias); err != nil {
1✔
159
                return err
×
160
        }
×
161

162
        if err := WriteNetAddrs(w, a.Addresses); err != nil {
1✔
163
                return err
×
164
        }
×
165

166
        return WriteBytes(w, a.ExtraOpaqueData)
1✔
167
}
168

169
// MsgType returns the integer uniquely identifying this message type on the
170
// wire.
171
//
172
// This is part of the lnwire.Message interface.
173
func (a *NodeAnnouncement) MsgType() MessageType {
1✔
174
        return MsgNodeAnnouncement
1✔
175
}
1✔
176

177
// DataToSign returns the part of the message that should be signed.
178
func (a *NodeAnnouncement) DataToSign() ([]byte, error) {
1✔
179

1✔
180
        // We should not include the signatures itself.
1✔
181
        buffer := make([]byte, 0, MaxMsgBody)
1✔
182
        buf := bytes.NewBuffer(buffer)
1✔
183

1✔
184
        if err := WriteRawFeatureVector(buf, a.Features); err != nil {
1✔
UNCOV
185
                return nil, err
×
UNCOV
186
        }
×
187

188
        if err := WriteUint32(buf, a.Timestamp); err != nil {
1✔
189
                return nil, err
×
190
        }
×
191

192
        if err := WriteBytes(buf, a.NodeID[:]); err != nil {
1✔
193
                return nil, err
×
194
        }
×
195

196
        if err := WriteColorRGBA(buf, a.RGBColor); err != nil {
1✔
197
                return nil, err
×
198
        }
×
199

200
        if err := WriteNodeAlias(buf, a.Alias); err != nil {
1✔
201
                return nil, err
×
202
        }
×
203

204
        if err := WriteNetAddrs(buf, a.Addresses); err != nil {
1✔
205
                return nil, err
×
206
        }
×
207

208
        if err := WriteBytes(buf, a.ExtraOpaqueData); err != nil {
1✔
209
                return nil, err
×
210
        }
×
211

212
        return buf.Bytes(), nil
1✔
213
}
214

215
// SerializedSize returns the serialized size of the message in bytes.
216
//
217
// This is part of the lnwire.SizeableMessage interface.
218
func (a *NodeAnnouncement) SerializedSize() (uint32, error) {
1✔
219
        return MessageSerializedSize(a)
1✔
220
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc