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

lightningnetwork / lnd / 13408822928

19 Feb 2025 08:59AM UTC coverage: 41.123% (-17.7%) from 58.794%
13408822928

Pull #9521

github

web-flow
Merge d2f397b3c into 0e8786348
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

92496 of 224923 relevant lines covered (41.12%)

18825.83 hits per line

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

33.33
/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
// Decode deserializes a serialized ChannelAnnouncement stored in the passed
66
// io.Reader observing the specified protocol version.
67
//
68
// This is part of the lnwire.Message interface.
69
func (a *ChannelAnnouncement1) Decode(r io.Reader, pver uint32) error {
157✔
70
        return ReadElements(r,
157✔
71
                &a.NodeSig1,
157✔
72
                &a.NodeSig2,
157✔
73
                &a.BitcoinSig1,
157✔
74
                &a.BitcoinSig2,
157✔
75
                &a.Features,
157✔
76
                a.ChainHash[:],
157✔
77
                &a.ShortChannelID,
157✔
78
                &a.NodeID1,
157✔
79
                &a.NodeID2,
157✔
80
                &a.BitcoinKey1,
157✔
81
                &a.BitcoinKey2,
157✔
82
                &a.ExtraOpaqueData,
157✔
83
        )
157✔
84
}
157✔
85

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

95
        if err := WriteSig(w, a.NodeSig2); err != nil {
117✔
96
                return err
×
97
        }
×
98

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

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

107
        if err := WriteRawFeatureVector(w, a.Features); err != nil {
117✔
108
                return err
×
109
        }
×
110

111
        if err := WriteBytes(w, a.ChainHash[:]); err != nil {
117✔
112
                return err
×
113
        }
×
114

115
        if err := WriteShortChannelID(w, a.ShortChannelID); err != nil {
117✔
116
                return err
×
117
        }
×
118

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

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

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

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

135
        return WriteBytes(w, a.ExtraOpaqueData)
117✔
136
}
137

138
// MsgType returns the integer uniquely identifying this message type on the
139
// wire.
140
//
141
// This is part of the lnwire.Message interface.
142
func (a *ChannelAnnouncement1) MsgType() MessageType {
117✔
143
        return MsgChannelAnnouncement
117✔
144
}
117✔
145

146
// DataToSign is used to retrieve part of the announcement message which should
147
// be signed.
148
func (a *ChannelAnnouncement1) DataToSign() ([]byte, error) {
×
149
        // We should not include the signatures itself.
×
150
        b := make([]byte, 0, MaxMsgBody)
×
151
        buf := bytes.NewBuffer(b)
×
152

×
153
        if err := WriteRawFeatureVector(buf, a.Features); err != nil {
×
154
                return nil, err
×
155
        }
×
156

157
        if err := WriteBytes(buf, a.ChainHash[:]); err != nil {
×
158
                return nil, err
×
159
        }
×
160

161
        if err := WriteShortChannelID(buf, a.ShortChannelID); err != nil {
×
162
                return nil, err
×
163
        }
×
164

165
        if err := WriteBytes(buf, a.NodeID1[:]); err != nil {
×
166
                return nil, err
×
167
        }
×
168

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

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

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

181
        if err := WriteBytes(buf, a.ExtraOpaqueData); err != nil {
×
182
                return nil, err
×
183
        }
×
184

185
        return buf.Bytes(), nil
×
186
}
187

188
// Node1KeyBytes returns the bytes representing the public key of node 1 in the
189
// channel.
190
//
191
// NOTE: This is part of the ChannelAnnouncement interface.
192
func (a *ChannelAnnouncement1) Node1KeyBytes() [33]byte {
×
193
        return a.NodeID1
×
194
}
×
195

196
// Node2KeyBytes returns the bytes representing the public key of node 2 in the
197
// channel.
198
//
199
// NOTE: This is part of the ChannelAnnouncement interface.
200
func (a *ChannelAnnouncement1) Node2KeyBytes() [33]byte {
×
201
        return a.NodeID2
×
202
}
×
203

204
// GetChainHash returns the hash of the chain which this channel's funding
205
// transaction is confirmed in.
206
//
207
// NOTE: This is part of the ChannelAnnouncement interface.
208
func (a *ChannelAnnouncement1) GetChainHash() chainhash.Hash {
×
209
        return a.ChainHash
×
210
}
×
211

212
// SCID returns the short channel ID of the channel.
213
//
214
// NOTE: This is part of the ChannelAnnouncement interface.
215
func (a *ChannelAnnouncement1) SCID() ShortChannelID {
×
216
        return a.ShortChannelID
×
217
}
×
218

219
// A compile-time check to ensure that ChannelAnnouncement1 implements the
220
// ChannelAnnouncement interface.
221
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