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

lightningnetwork / lnd / 14035127674

24 Mar 2025 12:21PM UTC coverage: 68.999% (+0.01%) from 68.989%
14035127674

Pull #9631

github

web-flow
Merge 06c7cd82e into 5235f3b24
Pull Request #9631: rpcserver: warn if sendcoins default conf target is used

1 of 1 new or added line in 1 file covered. (100.0%)

79 existing lines in 23 files now uncovered.

132917 of 192637 relevant lines covered (69.0%)

22283.53 hits per line

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

69.03
/lnwire/accept_channel.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/btcec/v2"
8
        "github.com/btcsuite/btcd/btcutil"
9
        "github.com/lightningnetwork/lnd/tlv"
10
)
11

12
// AcceptChannel is the message Bob sends to Alice after she initiates the
13
// single funder channel workflow via an AcceptChannel message. Once Alice
14
// receives Bob's response, then she has all the items necessary to construct
15
// the funding transaction, and both commitment transactions.
16
type AcceptChannel struct {
17
        // PendingChannelID serves to uniquely identify the future channel
18
        // created by the initiated single funder workflow.
19
        PendingChannelID [32]byte
20

21
        // DustLimit is the specific dust limit the sender of this message
22
        // would like enforced on their version of the commitment transaction.
23
        // Any output below this value will be "trimmed" from the commitment
24
        // transaction, with the amount of the HTLC going to dust.
25
        DustLimit btcutil.Amount
26

27
        // MaxValueInFlight represents the maximum amount of coins that can be
28
        // pending within the channel at any given time. If the amount of funds
29
        // in limbo exceeds this amount, then the channel will be failed.
30
        MaxValueInFlight MilliSatoshi
31

32
        // ChannelReserve is the amount of BTC that the receiving party MUST
33
        // maintain a balance above at all times. This is a safety mechanism to
34
        // ensure that both sides always have skin in the game during the
35
        // channel's lifetime.
36
        ChannelReserve btcutil.Amount
37

38
        // HtlcMinimum is the smallest HTLC that the sender of this message
39
        // will accept.
40
        HtlcMinimum MilliSatoshi
41

42
        // MinAcceptDepth is the minimum depth that the initiator of the
43
        // channel should wait before considering the channel open.
44
        MinAcceptDepth uint32
45

46
        // CsvDelay is the number of blocks to use for the relative time lock
47
        // in the pay-to-self output of both commitment transactions.
48
        CsvDelay uint16
49

50
        // MaxAcceptedHTLCs is the total number of incoming HTLC's that the
51
        // sender of this channel will accept.
52
        //
53
        // TODO(roasbeef): acks the initiator's, same with max in flight?
54
        MaxAcceptedHTLCs uint16
55

56
        // FundingKey is the key that should be used on behalf of the sender
57
        // within the 2-of-2 multi-sig output that it contained within the
58
        // funding transaction.
59
        FundingKey *btcec.PublicKey
60

61
        // RevocationPoint is the base revocation point for the sending party.
62
        // Any commitment transaction belonging to the receiver of this message
63
        // should use this key and their per-commitment point to derive the
64
        // revocation key for the commitment transaction.
65
        RevocationPoint *btcec.PublicKey
66

67
        // PaymentPoint is the base payment point for the sending party. This
68
        // key should be combined with the per commitment point for a
69
        // particular commitment state in order to create the key that should
70
        // be used in any output that pays directly to the sending party, and
71
        // also within the HTLC covenant transactions.
72
        PaymentPoint *btcec.PublicKey
73

74
        // DelayedPaymentPoint is the delay point for the sending party. This
75
        // key should be combined with the per commitment point to derive the
76
        // keys that are used in outputs of the sender's commitment transaction
77
        // where they claim funds.
78
        DelayedPaymentPoint *btcec.PublicKey
79

80
        // HtlcPoint is the base point used to derive the set of keys for this
81
        // party that will be used within the HTLC public key scripts.  This
82
        // value is combined with the receiver's revocation base point in order
83
        // to derive the keys that are used within HTLC scripts.
84
        HtlcPoint *btcec.PublicKey
85

86
        // FirstCommitmentPoint is the first commitment point for the sending
87
        // party. This value should be combined with the receiver's revocation
88
        // base point in order to derive the revocation keys that are placed
89
        // within the commitment transaction of the sender.
90
        FirstCommitmentPoint *btcec.PublicKey
91

92
        // UpfrontShutdownScript is the script to which the channel funds should
93
        // be paid when mutually closing the channel. This field is optional, and
94
        // and has a length prefix, so a zero will be written if it is not set
95
        // and its length followed by the script will be written if it is set.
96
        UpfrontShutdownScript DeliveryAddress
97

98
        // ChannelType is the explicit channel type the initiator wishes to
99
        // open.
100
        ChannelType *ChannelType
101

102
        // LeaseExpiry represents the absolute expiration height of a channel
103
        // lease. This is a custom TLV record that will only apply when a leased
104
        // channel is being opened using the script enforced lease commitment
105
        // type.
106
        LeaseExpiry *LeaseExpiry
107

108
        // LocalNonce is an optional field that transmits the
109
        // local/verification nonce for a party. This nonce will be used to
110
        // verify the very first commitment transaction signature.
111
        // This will only be populated if the simple taproot channels type was
112
        // negotiated.
113
        LocalNonce OptMusig2NonceTLV
114

115
        // ExtraData is the set of data that was appended to this message to
116
        // fill out the full maximum transport message size. These fields can
117
        // be used to specify optional data such as custom TLV fields.
118
        //
119
        // NOTE: Since the upfront shutdown script MUST be present (though can
120
        // be zero-length) if any TLV data is available, the script will be
121
        // extracted and removed from this blob when decoding. ExtraData will
122
        // contain all TLV records _except_ the DeliveryAddress record in that
123
        // case.
124
        ExtraData ExtraOpaqueData
125
}
126

127
// A compile time check to ensure AcceptChannel implements the lnwire.Message
128
// interface.
129
var _ Message = (*AcceptChannel)(nil)
130

131
// A compile time check to ensure AcceptChannel implements the
132
// lnwire.SizeableMessage interface.
133
var _ SizeableMessage = (*AcceptChannel)(nil)
134

135
// Encode serializes the target AcceptChannel into the passed io.Writer
136
// implementation. Serialization will observe the rules defined by the passed
137
// protocol version.
138
//
139
// This is part of the lnwire.Message interface.
140
func (a *AcceptChannel) Encode(w *bytes.Buffer, pver uint32) error {
140✔
141
        recordProducers := []tlv.RecordProducer{&a.UpfrontShutdownScript}
140✔
142
        if a.ChannelType != nil {
217✔
143
                recordProducers = append(recordProducers, a.ChannelType)
77✔
144
        }
77✔
145
        if a.LeaseExpiry != nil {
205✔
146
                recordProducers = append(recordProducers, a.LeaseExpiry)
65✔
147
        }
65✔
148
        a.LocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
196✔
149
                recordProducers = append(recordProducers, &localNonce)
56✔
150
        })
56✔
151
        err := EncodeMessageExtraData(&a.ExtraData, recordProducers...)
140✔
152
        if err != nil {
140✔
153
                return err
×
154
        }
×
155

156
        if err := WriteBytes(w, a.PendingChannelID[:]); err != nil {
140✔
157
                return err
×
158
        }
×
159

160
        if err := WriteSatoshi(w, a.DustLimit); err != nil {
140✔
161
                return err
×
162
        }
×
163

164
        if err := WriteMilliSatoshi(w, a.MaxValueInFlight); err != nil {
140✔
165
                return err
×
166
        }
×
167

168
        if err := WriteSatoshi(w, a.ChannelReserve); err != nil {
140✔
169
                return err
×
170
        }
×
171

172
        if err := WriteMilliSatoshi(w, a.HtlcMinimum); err != nil {
140✔
173
                return err
×
174
        }
×
175

176
        if err := WriteUint32(w, a.MinAcceptDepth); err != nil {
140✔
177
                return err
×
178
        }
×
179

180
        if err := WriteUint16(w, a.CsvDelay); err != nil {
140✔
181
                return err
×
182
        }
×
183

184
        if err := WriteUint16(w, a.MaxAcceptedHTLCs); err != nil {
140✔
185
                return err
×
186
        }
×
187

188
        if err := WritePublicKey(w, a.FundingKey); err != nil {
140✔
189
                return err
×
190
        }
×
191

192
        if err := WritePublicKey(w, a.RevocationPoint); err != nil {
140✔
193
                return err
×
194
        }
×
195

196
        if err := WritePublicKey(w, a.PaymentPoint); err != nil {
140✔
197
                return err
×
198
        }
×
199

200
        if err := WritePublicKey(w, a.DelayedPaymentPoint); err != nil {
140✔
201
                return err
×
202
        }
×
203

204
        if err := WritePublicKey(w, a.HtlcPoint); err != nil {
140✔
205
                return err
×
206
        }
×
207

208
        if err := WritePublicKey(w, a.FirstCommitmentPoint); err != nil {
140✔
209
                return err
×
210
        }
×
211

212
        return WriteBytes(w, a.ExtraData)
140✔
213
}
214

215
// Decode deserializes the serialized AcceptChannel stored in the passed
216
// io.Reader into the target AcceptChannel using the deserialization rules
217
// defined by the passed protocol version.
218
//
219
// This is part of the lnwire.Message interface.
220
func (a *AcceptChannel) Decode(r io.Reader, pver uint32) error {
236✔
221
        // Read all the mandatory fields in the accept message.
236✔
222
        err := ReadElements(r,
236✔
223
                a.PendingChannelID[:],
236✔
224
                &a.DustLimit,
236✔
225
                &a.MaxValueInFlight,
236✔
226
                &a.ChannelReserve,
236✔
227
                &a.HtlcMinimum,
236✔
228
                &a.MinAcceptDepth,
236✔
229
                &a.CsvDelay,
236✔
230
                &a.MaxAcceptedHTLCs,
236✔
231
                &a.FundingKey,
236✔
232
                &a.RevocationPoint,
236✔
233
                &a.PaymentPoint,
236✔
234
                &a.DelayedPaymentPoint,
236✔
235
                &a.HtlcPoint,
236✔
236
                &a.FirstCommitmentPoint,
236✔
237
        )
236✔
238
        if err != nil {
254✔
239
                return err
18✔
240
        }
18✔
241

242
        // For backwards compatibility, the optional extra data blob for
243
        // AcceptChannel must contain an entry for the upfront shutdown script.
244
        // We'll read it out and attempt to parse it.
245
        var tlvRecords ExtraOpaqueData
218✔
246
        if err := ReadElements(r, &tlvRecords); err != nil {
218✔
247
                return err
×
248
        }
×
249

250
        // Next we'll parse out the set of known records, keeping the raw tlv
251
        // bytes untouched to ensure we don't drop any bytes erroneously.
252
        var (
218✔
253
                chanType    ChannelType
218✔
254
                leaseExpiry LeaseExpiry
218✔
255
                localNonce  = a.LocalNonce.Zero()
218✔
256
        )
218✔
257
        typeMap, err := tlvRecords.ExtractRecords(
218✔
258
                &a.UpfrontShutdownScript, &chanType, &leaseExpiry,
218✔
259
                &localNonce,
218✔
260
        )
218✔
261
        if err != nil {
262✔
262
                return err
44✔
263
        }
44✔
264

265
        // Set the corresponding TLV types if they were included in the stream.
266
        if val, ok := typeMap[ChannelTypeRecordType]; ok && val == nil {
269✔
267
                a.ChannelType = &chanType
95✔
268
        }
95✔
269
        if val, ok := typeMap[LeaseExpiryRecordType]; ok && val == nil {
241✔
270
                a.LeaseExpiry = &leaseExpiry
67✔
271
        }
67✔
272
        if val, ok := typeMap[a.LocalNonce.TlvType()]; ok && val == nil {
231✔
273
                a.LocalNonce = tlv.SomeRecordT(localNonce)
57✔
274
        }
57✔
275

276
        a.ExtraData = tlvRecords
174✔
277

174✔
278
        return nil
174✔
279
}
280

281
// MsgType returns the MessageType code which uniquely identifies this message
282
// as an AcceptChannel on the wire.
283
//
284
// This is part of the lnwire.Message interface.
285
func (a *AcceptChannel) MsgType() MessageType {
140✔
286
        return MsgAcceptChannel
140✔
287
}
140✔
288

289
// SerializedSize returns the serialized size of the message in bytes.
290
//
291
// This is part of the lnwire.SizeableMessage interface.
UNCOV
292
func (a *AcceptChannel) SerializedSize() (uint32, error) {
×
UNCOV
293
        return MessageSerializedSize(a)
×
UNCOV
294
}
×
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