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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

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

33.82
/lnwire/channel_announcement.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "io"
6

7
        "github.com/btcsuite/btcd/chaincfg/chainhash"
8
        "pgregory.net/rapid"
9
)
10

11
// ChannelAnnouncement1 message is used to announce the existence of a channel
12
// between two peers in the overlay, which is propagated by the discovery
13
// service over broadcast handler.
14
type ChannelAnnouncement1 struct {
15
        // This signatures are used by nodes in order to create cross
16
        // references between node's channel and node. Requiring both nodes
17
        // to sign indicates they are both willing to route other payments via
18
        // this node.
19
        NodeSig1 Sig
20
        NodeSig2 Sig
21

22
        // This signatures are used by nodes in order to create cross
23
        // references between node's channel and node. Requiring the bitcoin
24
        // signatures proves they control the channel.
25
        BitcoinSig1 Sig
26
        BitcoinSig2 Sig
27

28
        // Features is the feature vector that encodes the features supported
29
        // by the target node. This field can be used to signal the type of the
30
        // channel, or modifications to the fields that would normally follow
31
        // this vector.
32
        Features *RawFeatureVector
33

34
        // ChainHash denotes the target chain that this channel was opened
35
        // within. This value should be the genesis hash of the target chain.
36
        ChainHash chainhash.Hash
37

38
        // ShortChannelID is the unique description of the funding transaction,
39
        // or where exactly it's located within the target blockchain.
40
        ShortChannelID ShortChannelID
41

42
        // The public keys of the two nodes who are operating the channel, such
43
        // that is NodeID1 the numerically-lesser than NodeID2 (ascending
44
        // numerical order).
45
        NodeID1 [33]byte
46
        NodeID2 [33]byte
47

48
        // Public keys which corresponds to the keys which was declared in
49
        // multisig funding transaction output.
50
        BitcoinKey1 [33]byte
51
        BitcoinKey2 [33]byte
52

53
        // ExtraOpaqueData is the set of data that was appended to this
54
        // message, some of which we may not actually know how to iterate or
55
        // parse. By holding onto this data, we ensure that we're able to
56
        // properly validate the set of signatures that cover these new fields,
57
        // and ensure we're able to make upgrades to the network in a forwards
58
        // compatible manner.
59
        ExtraOpaqueData ExtraOpaqueData
60
}
61

62
// A compile time check to ensure ChannelAnnouncement implements the
63
// lnwire.Message interface.
64
var _ Message = (*ChannelAnnouncement1)(nil)
65

66
// A compile time check to ensure ChannelAnnouncement1 implements the
67
// lnwire.SizeableMessage interface.
68
var _ SizeableMessage = (*ChannelAnnouncement1)(nil)
69

70
// Decode deserializes a serialized ChannelAnnouncement stored in the passed
71
// io.Reader observing the specified protocol version.
72
//
73
// This is part of the lnwire.Message interface.
74
func (a *ChannelAnnouncement1) Decode(r io.Reader, pver uint32) error {
3✔
75
        return ReadElements(r,
3✔
76
                &a.NodeSig1,
3✔
77
                &a.NodeSig2,
3✔
78
                &a.BitcoinSig1,
3✔
79
                &a.BitcoinSig2,
3✔
80
                &a.Features,
3✔
81
                a.ChainHash[:],
3✔
82
                &a.ShortChannelID,
3✔
83
                &a.NodeID1,
3✔
84
                &a.NodeID2,
3✔
85
                &a.BitcoinKey1,
3✔
86
                &a.BitcoinKey2,
3✔
87
                &a.ExtraOpaqueData,
3✔
88
        )
3✔
89
}
3✔
90

91
// Encode serializes the target ChannelAnnouncement into the passed io.Writer
92
// observing the protocol version specified.
93
//
94
// This is part of the lnwire.Message interface.
95
func (a *ChannelAnnouncement1) Encode(w *bytes.Buffer, pver uint32) error {
3✔
96
        if err := WriteSig(w, a.NodeSig1); err != nil {
3✔
97
                return err
×
98
        }
×
99

100
        if err := WriteSig(w, a.NodeSig2); err != nil {
3✔
101
                return err
×
102
        }
×
103

104
        if err := WriteSig(w, a.BitcoinSig1); err != nil {
3✔
105
                return err
×
106
        }
×
107

108
        if err := WriteSig(w, a.BitcoinSig2); err != nil {
3✔
109
                return err
×
110
        }
×
111

112
        if err := WriteRawFeatureVector(w, a.Features); err != nil {
3✔
113
                return err
×
114
        }
×
115

116
        if err := WriteBytes(w, a.ChainHash[:]); err != nil {
3✔
117
                return err
×
118
        }
×
119

120
        if err := WriteShortChannelID(w, a.ShortChannelID); err != nil {
3✔
121
                return err
×
122
        }
×
123

124
        if err := WriteBytes(w, a.NodeID1[:]); err != nil {
3✔
125
                return err
×
126
        }
×
127

128
        if err := WriteBytes(w, a.NodeID2[:]); err != nil {
3✔
129
                return err
×
130
        }
×
131

132
        if err := WriteBytes(w, a.BitcoinKey1[:]); err != nil {
3✔
133
                return err
×
134
        }
×
135

136
        if err := WriteBytes(w, a.BitcoinKey2[:]); err != nil {
3✔
137
                return err
×
138
        }
×
139

140
        return WriteBytes(w, a.ExtraOpaqueData)
3✔
141
}
142

143
// MsgType returns the integer uniquely identifying this message type on the
144
// wire.
145
//
146
// This is part of the lnwire.Message interface.
147
func (a *ChannelAnnouncement1) MsgType() MessageType {
3✔
148
        return MsgChannelAnnouncement
3✔
149
}
3✔
150

151
// SerializedSize returns the serialized size of the message in bytes.
152
//
153
// This is part of the lnwire.SizeableMessage interface.
NEW
154
func (a *ChannelAnnouncement1) SerializedSize() (uint32, error) {
×
NEW
155
        return MessageSerializedSize(a)
×
NEW
156
}
×
157

158
// DataToSign is used to retrieve part of the announcement message which should
159
// be signed.
160
func (a *ChannelAnnouncement1) DataToSign() ([]byte, error) {
3✔
161
        // We should not include the signatures itself.
3✔
162
        b := make([]byte, 0, MaxMsgBody)
3✔
163
        buf := bytes.NewBuffer(b)
3✔
164

3✔
165
        if err := WriteRawFeatureVector(buf, a.Features); err != nil {
3✔
166
                return nil, err
×
167
        }
×
168

169
        if err := WriteBytes(buf, a.ChainHash[:]); err != nil {
3✔
170
                return nil, err
×
171
        }
×
172

173
        if err := WriteShortChannelID(buf, a.ShortChannelID); err != nil {
3✔
174
                return nil, err
×
175
        }
×
176

177
        if err := WriteBytes(buf, a.NodeID1[:]); err != nil {
3✔
178
                return nil, err
×
179
        }
×
180

181
        if err := WriteBytes(buf, a.NodeID2[:]); err != nil {
3✔
182
                return nil, err
×
183
        }
×
184

185
        if err := WriteBytes(buf, a.BitcoinKey1[:]); err != nil {
3✔
186
                return nil, err
×
187
        }
×
188

189
        if err := WriteBytes(buf, a.BitcoinKey2[:]); err != nil {
3✔
190
                return nil, err
×
191
        }
×
192

193
        if err := WriteBytes(buf, a.ExtraOpaqueData); err != nil {
3✔
194
                return nil, err
×
195
        }
×
196

197
        return buf.Bytes(), nil
3✔
198
}
199

200
// Node1KeyBytes returns the bytes representing the public key of node 1 in the
201
// channel.
202
//
203
// NOTE: This is part of the ChannelAnnouncement interface.
204
func (a *ChannelAnnouncement1) Node1KeyBytes() [33]byte {
×
205
        return a.NodeID1
×
206
}
×
207

208
// Node2KeyBytes returns the bytes representing the public key of node 2 in the
209
// channel.
210
//
211
// NOTE: This is part of the ChannelAnnouncement interface.
212
func (a *ChannelAnnouncement1) Node2KeyBytes() [33]byte {
×
213
        return a.NodeID2
×
214
}
×
215

216
// GetChainHash returns the hash of the chain which this channel's funding
217
// transaction is confirmed in.
218
//
219
// NOTE: This is part of the ChannelAnnouncement interface.
220
func (a *ChannelAnnouncement1) GetChainHash() chainhash.Hash {
×
221
        return a.ChainHash
×
222
}
×
223

224
// SCID returns the short channel ID of the channel.
225
//
226
// NOTE: This is part of the ChannelAnnouncement interface.
227
func (a *ChannelAnnouncement1) SCID() ShortChannelID {
×
228
        return a.ShortChannelID
×
229
}
×
230

231
// A compile-time check to ensure that ChannelAnnouncement1 implements the
232
// ChannelAnnouncement interface.
233
var _ ChannelAnnouncement = (*ChannelAnnouncement1)(nil)
234

235
// A compile time check to ensure ChannelAnnouncement1 implements the TestMessage interface.
236
var _ TestMessage = (*ChannelAnnouncement1)(nil)
237

238
// RandTestMessage populates the message with random data suitable for testing.
239
// It uses the rapid testing framework to generate random values.
240
//
241
// This is part of the TestMessage interface.
NEW
242
func (a *ChannelAnnouncement1) RandTestMessage(t *rapid.T) Message {
×
NEW
243
        // Generate Node IDs and Bitcoin keys (compressed public keys)
×
NEW
244
        node1PubKey := RandPubKey(t)
×
NEW
245
        node2PubKey := RandPubKey(t)
×
NEW
246
        bitcoin1PubKey := RandPubKey(t)
×
NEW
247
        bitcoin2PubKey := RandPubKey(t)
×
NEW
248

×
NEW
249
        // Convert to byte arrays
×
NEW
250
        var nodeID1, nodeID2, bitcoinKey1, bitcoinKey2 [33]byte
×
NEW
251
        copy(nodeID1[:], node1PubKey.SerializeCompressed())
×
NEW
252
        copy(nodeID2[:], node2PubKey.SerializeCompressed())
×
NEW
253
        copy(bitcoinKey1[:], bitcoin1PubKey.SerializeCompressed())
×
NEW
254
        copy(bitcoinKey2[:], bitcoin2PubKey.SerializeCompressed())
×
NEW
255

×
NEW
256
        // Ensure nodeID1 is numerically less than nodeID2
×
NEW
257
        // This is a requirement stated in the field description
×
NEW
258
        if bytes.Compare(nodeID1[:], nodeID2[:]) > 0 {
×
NEW
259
                nodeID1, nodeID2 = nodeID2, nodeID1
×
NEW
260
        }
×
261

262
        // Generate chain hash
NEW
263
        chainHash := RandChainHash(t)
×
NEW
264
        var hash chainhash.Hash
×
NEW
265
        copy(hash[:], chainHash[:])
×
NEW
266

×
NEW
267
        return &ChannelAnnouncement1{
×
NEW
268
                NodeSig1:        RandSignature(t),
×
NEW
269
                NodeSig2:        RandSignature(t),
×
NEW
270
                BitcoinSig1:     RandSignature(t),
×
NEW
271
                BitcoinSig2:     RandSignature(t),
×
NEW
272
                Features:        RandFeatureVector(t),
×
NEW
273
                ChainHash:       hash,
×
NEW
274
                ShortChannelID:  RandShortChannelID(t),
×
NEW
275
                NodeID1:         nodeID1,
×
NEW
276
                NodeID2:         nodeID2,
×
NEW
277
                BitcoinKey1:     bitcoinKey1,
×
NEW
278
                BitcoinKey2:     bitcoinKey2,
×
NEW
279
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
NEW
280
        }
×
281
}
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