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

lightningnetwork / lnd / 16169173104

09 Jul 2025 12:21PM UTC coverage: 57.595% (-0.03%) from 57.62%
16169173104

Pull #10027

github

web-flow
Merge f44a19534 into ea32aac77
Pull Request #10027: Fix `ExtraData` field and use `BigSize` encodine

0 of 159 new or added lines in 5 files covered. (0.0%)

57 existing lines in 12 files now uncovered.

98477 of 170982 relevant lines covered (57.59%)

1.79 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/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 {
×
73
        if err := WriteChannelID(w, dp.ChanID); err != nil {
×
74
                return err
×
75
        }
×
76

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

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

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

93
        // Write the records.
NEW
94
        return WriteBytes(w, tlvData)
×
95
}
96

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

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

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

×
NEW
123
        knownRecords, extraData, err := ParseAndExtractExtraData(
×
NEW
124
                tlvRecords, &dustLimit, &maxValue, &htlcMin, &reserve,
×
NEW
125
                &csvDelay, &maxHtlcs, &chanType,
×
126
        )
×
127
        if err != nil {
×
128
                return err
×
129
        }
×
130

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

NEW
137
        if _, ok := knownRecords[dp.MaxValueInFlight.TlvType()]; ok {
×
NEW
138
                dp.MaxValueInFlight = tlv.SomeRecordT(maxValue)
×
139
        }
×
140

NEW
141
        if _, ok := knownRecords[dp.HtlcMinimum.TlvType()]; ok {
×
NEW
142
                dp.HtlcMinimum = tlv.SomeRecordT(htlcMin)
×
143
        }
×
144

NEW
145
        if _, ok := knownRecords[dp.ChannelReserve.TlvType()]; ok {
×
NEW
146
                dp.ChannelReserve = tlv.SomeRecordT(reserve)
×
147
        }
×
148

NEW
149
        if _, ok := knownRecords[dp.CsvDelay.TlvType()]; ok {
×
150
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
×
151
        }
×
152

NEW
153
        if _, ok := knownRecords[dp.MaxAcceptedHTLCs.TlvType()]; ok {
×
154
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
155
        }
×
156

NEW
157
        if _, ok := knownRecords[dp.ChannelType.TlvType()]; ok {
×
158
                dp.ChannelType = tlv.SomeRecordT(chanType)
×
159
        }
×
160

NEW
161
        dp.ExtraData = extraData
×
162

×
163
        return nil
×
164
}
165

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

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

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

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

193
        return extra, nil
×
194
}
195

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

×
199
        dp.DustLimit.WhenSome(
×
NEW
200
                func(dl tlv.RecordT[tlv.TlvType0,
×
NEW
201
                        tlv.BigSizeT[btcutil.Amount]]) {
×
NEW
202

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

×
NEW
220
                        recordProducers = append(recordProducers, &reserve)
×
UNCOV
221
                },
×
222
        )
223
        dp.CsvDelay.WhenSome(
×
224
                func(wait tlv.RecordT[tlv.TlvType8, uint16]) {
×
225
                        recordProducers = append(recordProducers, &wait)
×
226
                },
×
227
        )
228
        dp.MaxAcceptedHTLCs.WhenSome(
×
229
                func(mah tlv.RecordT[tlv.TlvType10, uint16]) {
×
230
                        recordProducers = append(recordProducers, &mah)
×
231
                },
×
232
        )
233
        dp.ChannelType.WhenSome(
×
234
                func(ty tlv.RecordT[tlv.TlvType12, ChannelType]) {
×
235
                        recordProducers = append(recordProducers, &ty)
×
236
                },
×
237
        )
238

239
        return recordProducers
×
240
}
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