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

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 hits per line

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

49.02
/lnwire/channel_announcement.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/chaincfg/chainhash"
8
)
9

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

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

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

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

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

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

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

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

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

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

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

92
        return a.ExtraOpaqueData.ValidateTLV()
3✔
93
}
94

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

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

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

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

116
        if err := WriteRawFeatureVector(w, a.Features); err != nil {
3✔
117
                return err
×
118
        }
×
119

120
        if err := WriteBytes(w, a.ChainHash[:]); err != nil {
3✔
121
                return err
×
122
        }
×
123

124
        if err := WriteShortChannelID(w, a.ShortChannelID); err != nil {
3✔
125
                return err
×
126
        }
×
127

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

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

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

140
        if err := WriteBytes(w, a.BitcoinKey2[:]); err != nil {
3✔
141
                return err
×
142
        }
×
143

144
        return WriteBytes(w, a.ExtraOpaqueData)
3✔
145
}
146

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

155
// SerializedSize returns the serialized size of the message in bytes.
156
//
157
// This is part of the lnwire.SizeableMessage interface.
158
func (a *ChannelAnnouncement1) SerializedSize() (uint32, error) {
3✔
159
        return MessageSerializedSize(a)
3✔
160
}
3✔
161

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

3✔
169
        if err := WriteRawFeatureVector(buf, a.Features); err != nil {
3✔
170
                return nil, err
×
171
        }
×
172

173
        if err := WriteBytes(buf, a.ChainHash[:]); err != nil {
3✔
174
                return nil, err
×
175
        }
×
176

177
        if err := WriteShortChannelID(buf, a.ShortChannelID); err != nil {
3✔
178
                return nil, err
×
179
        }
×
180

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

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

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

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

197
        if err := WriteBytes(buf, a.ExtraOpaqueData); err != nil {
3✔
198
                return nil, err
×
199
        }
×
200

201
        return buf.Bytes(), nil
3✔
202
}
203

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

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

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

228
// SCID returns the short channel ID of the channel.
229
//
230
// NOTE: This is part of the ChannelAnnouncement interface.
231
func (a *ChannelAnnouncement1) SCID() ShortChannelID {
×
232
        return a.ShortChannelID
×
233
}
×
234

235
// A compile-time check to ensure that ChannelAnnouncement1 implements the
236
// ChannelAnnouncement interface.
237
var _ ChannelAnnouncement = (*ChannelAnnouncement1)(nil)
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