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

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

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

0.0
/lnwire/dyn_propose.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/fn/v2"
10
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
11
        "github.com/lightningnetwork/lnd/tlv"
12
)
13

14
const (
15
        // DPDustLimitSatoshis is the TLV type number that identifies the record
16
        // for DynPropose.DustLimit.
17
        DPDustLimitSatoshis tlv.Type = 0
18

19
        // DPMaxHtlcValueInFlightMsat is the TLV type number that identifies the
20
        // record for DynPropose.MaxValueInFlight.
21
        DPMaxHtlcValueInFlightMsat tlv.Type = 1
22

23
        // DPChannelReserveSatoshis is the TLV type number that identifies the
24
        // for DynPropose.ChannelReserve.
25
        DPChannelReserveSatoshis tlv.Type = 2
26

27
        // DPToSelfDelay is the TLV type number that identifies the record for
28
        // DynPropose.CsvDelay.
29
        DPToSelfDelay tlv.Type = 3
30

31
        // DPMaxAcceptedHtlcs is the TLV type number that identifies the record
32
        // for DynPropose.MaxAcceptedHTLCs.
33
        DPMaxAcceptedHtlcs tlv.Type = 4
34

35
        // DPFundingPubkey is the TLV type number that identifies the record for
36
        // DynPropose.FundingKey.
37
        DPFundingPubkey tlv.Type = 5
38

39
        // DPChannelType is the TLV type number that identifies the record for
40
        // DynPropose.ChannelType.
41
        DPChannelType tlv.Type = 6
42

43
        // DPKickoffFeerate is the TLV type number that identifies the record
44
        // for DynPropose.KickoffFeerate.
45
        DPKickoffFeerate tlv.Type = 7
46
)
47

48
// DynPropose is a message that is sent during a dynamic commitments negotiation
49
// process. It is sent by both parties to propose new channel parameters.
50
type DynPropose struct {
51
        // ChanID identifies the channel whose parameters we are trying to
52
        // re-negotiate.
53
        ChanID ChannelID
54

55
        // Initiator is a byte that identifies whether this message was sent as
56
        // the initiator of a dynamic commitment negotiation or the responder
57
        // of a dynamic commitment negotiation. bool true indicates it is the
58
        // initiator
59
        Initiator bool
60

61
        // DustLimit, if not nil, proposes a change to the dust_limit_satoshis
62
        // for the sender's commitment transaction.
63
        DustLimit fn.Option[btcutil.Amount]
64

65
        // MaxValueInFlight, if not nil, proposes a change to the
66
        // max_htlc_value_in_flight_msat limit of the sender.
67
        MaxValueInFlight fn.Option[MilliSatoshi]
68

69
        // ChannelReserve, if not nil, proposes a change to the
70
        // channel_reserve_satoshis requirement of the recipient.
71
        ChannelReserve fn.Option[btcutil.Amount]
72

73
        // CsvDelay, if not nil, proposes a change to the to_self_delay
74
        // requirement of the recipient.
75
        CsvDelay fn.Option[uint16]
76

77
        // MaxAcceptedHTLCs, if not nil, proposes a change to the
78
        // max_accepted_htlcs limit of the sender.
79
        MaxAcceptedHTLCs fn.Option[uint16]
80

81
        // FundingKey, if not nil, proposes a change to the funding_pubkey
82
        // parameter of the sender.
83
        FundingKey fn.Option[btcec.PublicKey]
84

85
        // ChannelType, if not nil, proposes a change to the channel_type
86
        // parameter.
87
        ChannelType fn.Option[ChannelType]
88

89
        // KickoffFeerate proposes the fee rate in satoshis per kw that it
90
        // is offering for a ChannelType conversion that requires a kickoff
91
        // transaction.
92
        KickoffFeerate fn.Option[chainfee.SatPerKWeight]
93

94
        // ExtraData is the set of data that was appended to this message to
95
        // fill out the full maximum transport message size. These fields can
96
        // be used to specify optional data such as custom TLV fields.
97
        //
98
        // NOTE: Since the fields in this structure are part of the TLV stream,
99
        // ExtraData will contain all TLV records _except_ the ones that are
100
        // present in earlier parts of this structure.
101
        ExtraData ExtraOpaqueData
102
}
103

104
// A compile time check to ensure DynPropose implements the lnwire.Message
105
// interface.
106
var _ Message = (*DynPropose)(nil)
107

108
// Encode serializes the target DynPropose into the passed io.Writer.
109
// Serialization will observe the rules defined by the passed protocol version.
110
//
111
// This is a part of the lnwire.Message interface.
112
func (dp *DynPropose) Encode(w *bytes.Buffer, _ uint32) error {
×
113
        var tlvRecords []tlv.Record
×
114
        dp.DustLimit.WhenSome(func(dl btcutil.Amount) {
×
115
                protoSats := uint64(dl)
×
116
                tlvRecords = append(
×
117
                        tlvRecords, tlv.MakePrimitiveRecord(
×
118
                                DPDustLimitSatoshis, &protoSats,
×
119
                        ),
×
120
                )
×
121
        })
×
122
        dp.MaxValueInFlight.WhenSome(func(max MilliSatoshi) {
×
123
                protoSats := uint64(max)
×
124
                tlvRecords = append(
×
125
                        tlvRecords, tlv.MakePrimitiveRecord(
×
126
                                DPMaxHtlcValueInFlightMsat, &protoSats,
×
127
                        ),
×
128
                )
×
129
        })
×
130
        dp.ChannelReserve.WhenSome(func(min btcutil.Amount) {
×
131
                channelReserve := uint64(min)
×
132
                tlvRecords = append(
×
133
                        tlvRecords, tlv.MakePrimitiveRecord(
×
134
                                DPChannelReserveSatoshis, &channelReserve,
×
135
                        ),
×
136
                )
×
137
        })
×
138
        dp.CsvDelay.WhenSome(func(wait uint16) {
×
139
                tlvRecords = append(
×
140
                        tlvRecords, tlv.MakePrimitiveRecord(
×
141
                                DPToSelfDelay, &wait,
×
142
                        ),
×
143
                )
×
144
        })
×
145
        dp.MaxAcceptedHTLCs.WhenSome(func(max uint16) {
×
146
                tlvRecords = append(
×
147
                        tlvRecords, tlv.MakePrimitiveRecord(
×
148
                                DPMaxAcceptedHtlcs, &max,
×
149
                        ),
×
150
                )
×
151
        })
×
152
        dp.FundingKey.WhenSome(func(key btcec.PublicKey) {
×
153
                keyScratch := &key
×
154
                tlvRecords = append(
×
155
                        tlvRecords, tlv.MakePrimitiveRecord(
×
156
                                DPFundingPubkey, &keyScratch,
×
157
                        ),
×
158
                )
×
159
        })
×
160
        dp.ChannelType.WhenSome(func(ty ChannelType) {
×
161
                tlvRecords = append(
×
162
                        tlvRecords, tlv.MakeDynamicRecord(
×
163
                                DPChannelType, &ty,
×
164
                                ty.featureBitLen,
×
165
                                channelTypeEncoder, channelTypeDecoder,
×
166
                        ),
×
167
                )
×
168
        })
×
169
        dp.KickoffFeerate.WhenSome(func(kickoffFeerate chainfee.SatPerKWeight) {
×
170
                protoSats := uint32(kickoffFeerate)
×
171
                tlvRecords = append(
×
172
                        tlvRecords, tlv.MakePrimitiveRecord(
×
173
                                DPKickoffFeerate, &protoSats,
×
174
                        ),
×
175
                )
×
176
        })
×
177
        tlv.SortRecords(tlvRecords)
×
178

×
179
        tlvStream, err := tlv.NewStream(tlvRecords...)
×
180
        if err != nil {
×
181
                return err
×
182
        }
×
183

184
        var extraBytesWriter bytes.Buffer
×
185
        if err := tlvStream.Encode(&extraBytesWriter); err != nil {
×
186
                return err
×
187
        }
×
188
        dp.ExtraData = ExtraOpaqueData(extraBytesWriter.Bytes())
×
189

×
190
        if err := WriteChannelID(w, dp.ChanID); err != nil {
×
191
                return err
×
192
        }
×
193

194
        if err := WriteBool(w, dp.Initiator); err != nil {
×
195
                return err
×
196
        }
×
197

198
        return WriteBytes(w, dp.ExtraData)
×
199
}
200

201
// Decode deserializes the serialized DynPropose stored in the passed io.Reader
202
// into the target DynPropose using the deserialization rules defined by the
203
// passed protocol version.
204
//
205
// This is a part of the lnwire.Message interface.
206
func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
×
207
        // Parse out the only required field.
×
208
        if err := ReadElements(r, &dp.ChanID, &dp.Initiator); err != nil {
×
209
                return err
×
210
        }
×
211

212
        // Parse out TLV stream.
213
        var tlvRecords ExtraOpaqueData
×
214
        if err := ReadElements(r, &tlvRecords); err != nil {
×
215
                return err
×
216
        }
×
217

218
        // Prepare receiving buffers to be filled by TLV extraction.
219
        var dustLimitScratch uint64
×
220
        dustLimit := tlv.MakePrimitiveRecord(
×
221
                DPDustLimitSatoshis, &dustLimitScratch,
×
222
        )
×
223

×
224
        var maxValueScratch uint64
×
225
        maxValue := tlv.MakePrimitiveRecord(
×
226
                DPMaxHtlcValueInFlightMsat, &maxValueScratch,
×
227
        )
×
228

×
229
        var reserveScratch uint64
×
230
        reserve := tlv.MakePrimitiveRecord(
×
231
                DPChannelReserveSatoshis, &reserveScratch,
×
232
        )
×
233

×
234
        var csvDelayScratch uint16
×
235
        csvDelay := tlv.MakePrimitiveRecord(DPToSelfDelay, &csvDelayScratch)
×
236

×
237
        var maxHtlcsScratch uint16
×
238
        maxHtlcs := tlv.MakePrimitiveRecord(
×
239
                DPMaxAcceptedHtlcs, &maxHtlcsScratch,
×
240
        )
×
241

×
242
        var fundingKeyScratch *btcec.PublicKey
×
243
        fundingKey := tlv.MakePrimitiveRecord(
×
244
                DPFundingPubkey, &fundingKeyScratch,
×
245
        )
×
246

×
247
        var chanTypeScratch ChannelType
×
248
        chanType := tlv.MakeDynamicRecord(
×
249
                DPChannelType, &chanTypeScratch, chanTypeScratch.featureBitLen,
×
250
                channelTypeEncoder, channelTypeDecoder,
×
251
        )
×
252

×
253
        var kickoffFeerateScratch uint32
×
254
        kickoffFeerate := tlv.MakePrimitiveRecord(
×
255
                DPKickoffFeerate, &kickoffFeerateScratch,
×
256
        )
×
257

×
258
        // Create set of Records to read TLV bytestream into.
×
259
        records := []tlv.Record{
×
260
                dustLimit, maxValue, reserve, csvDelay, maxHtlcs, fundingKey,
×
261
                chanType, kickoffFeerate,
×
262
        }
×
263
        tlv.SortRecords(records)
×
264

×
265
        // Read TLV stream into record set.
×
266
        extraBytesReader := bytes.NewReader(tlvRecords)
×
267
        tlvStream, err := tlv.NewStream(records...)
×
268
        if err != nil {
×
269
                return err
×
270
        }
×
271

272
        typeMap, err := tlvStream.DecodeWithParsedTypesP2P(extraBytesReader)
×
273
        if err != nil {
×
274
                return err
×
275
        }
×
276

277
        // Check the results of the TLV Stream decoding and appropriately set
278
        // message fields.
279
        if val, ok := typeMap[DPDustLimitSatoshis]; ok && val == nil {
×
280
                dp.DustLimit = fn.Some(btcutil.Amount(dustLimitScratch))
×
281
        }
×
282
        if val, ok := typeMap[DPMaxHtlcValueInFlightMsat]; ok && val == nil {
×
283
                dp.MaxValueInFlight = fn.Some(MilliSatoshi(maxValueScratch))
×
284
        }
×
285
        if val, ok := typeMap[DPChannelReserveSatoshis]; ok && val == nil {
×
286
                dp.ChannelReserve = fn.Some(btcutil.Amount(reserveScratch))
×
287
        }
×
288
        if val, ok := typeMap[DPToSelfDelay]; ok && val == nil {
×
289
                dp.CsvDelay = fn.Some(csvDelayScratch)
×
290
        }
×
291
        if val, ok := typeMap[DPMaxAcceptedHtlcs]; ok && val == nil {
×
292
                dp.MaxAcceptedHTLCs = fn.Some(maxHtlcsScratch)
×
293
        }
×
294
        if val, ok := typeMap[DPFundingPubkey]; ok && val == nil {
×
295
                dp.FundingKey = fn.Some(*fundingKeyScratch)
×
296
        }
×
297
        if val, ok := typeMap[DPChannelType]; ok && val == nil {
×
298
                dp.ChannelType = fn.Some(chanTypeScratch)
×
299
        }
×
300
        if val, ok := typeMap[DPKickoffFeerate]; ok && val == nil {
×
301
                dp.KickoffFeerate = fn.Some(
×
302
                        chainfee.SatPerKWeight(kickoffFeerateScratch),
×
303
                )
×
304
        }
×
305

306
        if len(tlvRecords) != 0 {
×
307
                dp.ExtraData = tlvRecords
×
308
        }
×
309

310
        return nil
×
311
}
312

313
// MsgType returns the MessageType code which uniquely identifies this message
314
// as a DynPropose on the wire.
315
//
316
// This is part of the lnwire.Message interface.
317
func (dp *DynPropose) MsgType() MessageType {
×
318
        return MsgDynPropose
×
319
}
×
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