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

lightningnetwork / lnd / 16651762882

31 Jul 2025 02:26PM UTC coverage: 67.045% (-0.002%) from 67.047%
16651762882

Pull #9993

github

web-flow
Merge d00c6f917 into 37523b6cb
Pull Request #9993: Validate UTF-8 description and empty route hints when parsing BOLT-11 invoices

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

82 existing lines in 17 files now uncovered.

135566 of 202201 relevant lines covered (67.05%)

21685.17 hits per line

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

82.76
/lnwire/dyn_propose.go
1
package lnwire
2

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

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

11
// DynPropose is a message that is sent during a dynamic commitments negotiation
12
// process. It is sent by both parties to propose new channel parameters.
13
type DynPropose struct {
14
        // ChanID identifies the channel whose parameters we are trying to
15
        // re-negotiate.
16
        ChanID ChannelID
17

18
        // DustLimit, if not nil, proposes a change to the dust_limit_satoshis
19
        // for the sender's commitment transaction.
20
        DustLimit tlv.OptionalRecordT[
21
                tlv.TlvType0, tlv.BigSizeT[btcutil.Amount],
22
        ]
23

24
        // MaxValueInFlight, if not nil, proposes a change to the
25
        // max_htlc_value_in_flight_msat limit of the sender.
26
        MaxValueInFlight tlv.OptionalRecordT[tlv.TlvType2, MilliSatoshi]
27

28
        // HtlcMinimum, if not nil, proposes a change to the htlc_minimum_msat
29
        // floor of the sender.
30
        HtlcMinimum tlv.OptionalRecordT[tlv.TlvType4, MilliSatoshi]
31

32
        // ChannelReserve, if not nil, proposes a change to the
33
        // channel_reserve_satoshis requirement of the recipient.
34
        ChannelReserve tlv.OptionalRecordT[
35
                tlv.TlvType6, tlv.BigSizeT[btcutil.Amount],
36
        ]
37

38
        // CsvDelay, if not nil, proposes a change to the to_self_delay
39
        // requirement of the recipient.
40
        CsvDelay tlv.OptionalRecordT[tlv.TlvType8, uint16]
41

42
        // MaxAcceptedHTLCs, if not nil, proposes a change to the
43
        // max_accepted_htlcs limit of the sender.
44
        MaxAcceptedHTLCs tlv.OptionalRecordT[tlv.TlvType10, uint16]
45

46
        // ChannelType, if not nil, proposes a change to the channel_type
47
        // parameter.
48
        ChannelType tlv.OptionalRecordT[tlv.TlvType12, ChannelType]
49

50
        // ExtraData is the set of data that was appended to this message to
51
        // fill out the full maximum transport message size. These fields can
52
        // be used to specify optional data such as custom TLV fields.
53
        //
54
        // NOTE: Since the fields in this structure are part of the TLV stream,
55
        // ExtraData will contain all TLV records _except_ the ones that are
56
        // present in earlier parts of this structure.
57
        ExtraData ExtraOpaqueData
58
}
59

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

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

68
// Encode serializes the target DynPropose into the passed io.Writer.
69
// Serialization will observe the rules defined by the passed protocol version.
70
//
71
// This is a part of the lnwire.Message interface.
72
func (dp *DynPropose) Encode(w *bytes.Buffer, _ uint32) error {
104✔
73
        if err := WriteChannelID(w, dp.ChanID); err != nil {
104✔
74
                return err
×
75
        }
×
76

77
        // Create extra data records.
78
        producers, err := dp.ExtraData.RecordProducers()
104✔
79
        if err != nil {
104✔
80
                return err
×
81
        }
×
82

83
        // Append the known records.
84
        producers = append(producers, dynProposeRecords(dp)...)
104✔
85

104✔
86
        // Encode all records.
104✔
87
        var tlvData ExtraOpaqueData
104✔
88
        err = tlvData.PackRecords(producers...)
104✔
89
        if err != nil {
104✔
90
                return err
×
91
        }
×
92

93
        return WriteBytes(w, tlvData)
104✔
94
}
95

96
// Decode deserializes the serialized DynPropose stored in the passed io.Reader
97
// into the target DynPropose using the deserialization rules defined by the
98
// passed protocol version.
99
//
100
// This is a part of the lnwire.Message interface.
101
func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
209✔
102
        // Parse out the only required field.
209✔
103
        if err := ReadElements(r, &dp.ChanID); err != nil {
211✔
104
                return err
2✔
105
        }
2✔
106

107
        // Parse out TLV stream.
108
        var tlvRecords ExtraOpaqueData
207✔
109
        if err := ReadElements(r, &tlvRecords); err != nil {
207✔
110
                return err
×
111
        }
×
112

113
        // Prepare receiving buffers to be filled by TLV extraction.
114
        var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
207✔
115
        var maxValue tlv.RecordT[tlv.TlvType2, MilliSatoshi]
207✔
116
        var htlcMin tlv.RecordT[tlv.TlvType4, MilliSatoshi]
207✔
117
        var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
207✔
118
        csvDelay := dp.CsvDelay.Zero()
207✔
119
        maxHtlcs := dp.MaxAcceptedHTLCs.Zero()
207✔
120
        chanType := dp.ChannelType.Zero()
207✔
121

207✔
122
        knownRecords, extraData, err := ParseAndExtractExtraData(
207✔
123
                tlvRecords, &dustLimit, &maxValue, &htlcMin, &reserve,
207✔
124
                &csvDelay, &maxHtlcs, &chanType,
207✔
125
        )
207✔
126
        if err != nil {
307✔
127
                return err
100✔
128
        }
100✔
129

130
        // Check the results of the TLV Stream decoding and appropriately set
131
        // message fields.
132
        if _, ok := knownRecords[dp.DustLimit.TlvType()]; ok {
158✔
133
                dp.DustLimit = tlv.SomeRecordT(dustLimit)
51✔
134
        }
51✔
135

136
        if _, ok := knownRecords[dp.MaxValueInFlight.TlvType()]; ok {
149✔
137
                dp.MaxValueInFlight = tlv.SomeRecordT(maxValue)
42✔
138
        }
42✔
139

140
        if _, ok := knownRecords[dp.HtlcMinimum.TlvType()]; ok {
108✔
141
                dp.HtlcMinimum = tlv.SomeRecordT(htlcMin)
1✔
142
        }
1✔
143

144
        if _, ok := knownRecords[dp.ChannelReserve.TlvType()]; ok {
158✔
145
                dp.ChannelReserve = tlv.SomeRecordT(reserve)
51✔
146
        }
51✔
147

148
        if _, ok := knownRecords[dp.CsvDelay.TlvType()]; ok {
162✔
149
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
55✔
150
        }
55✔
151

152
        if _, ok := knownRecords[dp.MaxAcceptedHTLCs.TlvType()]; ok {
159✔
153
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
52✔
154
        }
52✔
155

156
        if _, ok := knownRecords[dp.ChannelType.TlvType()]; ok {
161✔
157
                dp.ChannelType = tlv.SomeRecordT(chanType)
54✔
158
        }
54✔
159

160
        dp.ExtraData = extraData
107✔
161

107✔
162
        return nil
107✔
163
}
164

165
// MsgType returns the MessageType code which uniquely identifies this message
166
// as a DynPropose on the wire.
167
//
168
// This is part of the lnwire.Message interface.
169
func (dp *DynPropose) MsgType() MessageType {
103✔
170
        return MsgDynPropose
103✔
171
}
103✔
172

173
// SerializedSize returns the serialized size of the message in bytes.
174
//
175
// This is part of the lnwire.SizeableMessage interface.
UNCOV
176
func (dp *DynPropose) SerializedSize() (uint32, error) {
×
UNCOV
177
        return MessageSerializedSize(dp)
×
UNCOV
178
}
×
179

180
// SerializeTlvData takes just the TLV data of DynPropose (which covers all of
181
// the parameters on deck for changing) and serializes just this component. The
182
// main purpose of this is to make it easier to validate the DynAck signature.
183
func (dp *DynPropose) SerializeTlvData() ([]byte, error) {
×
184
        producers := dynProposeRecords(dp)
×
185

×
186
        var extra ExtraOpaqueData
×
187
        err := extra.PackRecords(producers...)
×
188
        if err != nil {
×
189
                return nil, err
×
190
        }
×
191

192
        return extra, nil
×
193
}
194

195
func dynProposeRecords(dp *DynPropose) []tlv.RecordProducer {
205✔
196
        recordProducers := make([]tlv.RecordProducer, 0, 7)
205✔
197

205✔
198
        dp.DustLimit.WhenSome(
205✔
199
                func(dl tlv.RecordT[tlv.TlvType0,
205✔
200
                        tlv.BigSizeT[btcutil.Amount]]) {
310✔
201

105✔
202
                        recordProducers = append(recordProducers, &dl)
105✔
203
                },
105✔
204
        )
205
        dp.MaxValueInFlight.WhenSome(
205✔
206
                func(mvif tlv.RecordT[tlv.TlvType2, MilliSatoshi]) {
301✔
207
                        recordProducers = append(recordProducers, &mvif)
96✔
208
                },
96✔
209
        )
210
        dp.HtlcMinimum.WhenSome(
205✔
211
                func(hm tlv.RecordT[tlv.TlvType4, MilliSatoshi]) {
207✔
212
                        recordProducers = append(recordProducers, &hm)
2✔
213
                },
2✔
214
        )
215
        dp.ChannelReserve.WhenSome(
205✔
216
                func(reserve tlv.RecordT[tlv.TlvType6,
205✔
217
                        tlv.BigSizeT[btcutil.Amount]]) {
302✔
218

97✔
219
                        recordProducers = append(recordProducers, &reserve)
97✔
220
                },
97✔
221
        )
222
        dp.CsvDelay.WhenSome(
205✔
223
                func(wait tlv.RecordT[tlv.TlvType8, uint16]) {
302✔
224
                        recordProducers = append(recordProducers, &wait)
97✔
225
                },
97✔
226
        )
227
        dp.MaxAcceptedHTLCs.WhenSome(
205✔
228
                func(mah tlv.RecordT[tlv.TlvType10, uint16]) {
311✔
229
                        recordProducers = append(recordProducers, &mah)
106✔
230
                },
106✔
231
        )
232
        dp.ChannelType.WhenSome(
205✔
233
                func(ty tlv.RecordT[tlv.TlvType12, ChannelType]) {
315✔
234
                        recordProducers = append(recordProducers, &ty)
110✔
235
                },
110✔
236
        )
237

238
        return recordProducers
205✔
239
}
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