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

lightningnetwork / lnd / 13982721865

21 Mar 2025 01:30AM UTC coverage: 58.587% (-0.5%) from 59.126%
13982721865

Pull #9623

github

web-flow
Merge 05a6b6838 into 5d921723b
Pull Request #9623: Size msg test msg

0 of 1572 new or added lines in 43 files covered. (0.0%)

17 existing lines in 5 files now uncovered.

96767 of 165169 relevant lines covered (58.59%)

1.82 hits per line

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

46.46
/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, pver uint32) error {
3✔
74
        return 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
}
3✔
89

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

230
// A compile-time check to ensure that ChannelAnnouncement1 implements the
231
// ChannelAnnouncement interface.
232
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