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

lightningnetwork / lnd / 16466354971

23 Jul 2025 09:05AM UTC coverage: 57.54% (-9.7%) from 67.201%
16466354971

Pull #9455

github

web-flow
Merge f914ae23c into 90e211684
Pull Request #9455: discovery+lnwire: add support for DNS host name in NodeAnnouncement msg

151 of 291 new or added lines in 7 files covered. (51.89%)

28441 existing lines in 456 files now uncovered.

98864 of 171817 relevant lines covered (57.54%)

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.
UNCOV
72
func (dp *DynPropose) Encode(w *bytes.Buffer, _ uint32) error {
×
UNCOV
73
        if err := WriteChannelID(w, dp.ChanID); err != nil {
×
74
                return err
×
75
        }
×
76

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

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

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

UNCOV
93
        return WriteBytes(w, tlvData)
×
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.
UNCOV
101
func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
×
UNCOV
102
        // Parse out the only required field.
×
UNCOV
103
        if err := ReadElements(r, &dp.ChanID); err != nil {
×
UNCOV
104
                return err
×
UNCOV
105
        }
×
106

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

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

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

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

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

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

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

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

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

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

UNCOV
160
        dp.ExtraData = extraData
×
UNCOV
161

×
UNCOV
162
        return nil
×
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.
UNCOV
169
func (dp *DynPropose) MsgType() MessageType {
×
UNCOV
170
        return MsgDynPropose
×
UNCOV
171
}
×
172

173
// SerializedSize returns the serialized size of the message in bytes.
174
//
175
// This is part of the lnwire.SizeableMessage interface.
176
func (dp *DynPropose) SerializedSize() (uint32, error) {
×
177
        return MessageSerializedSize(dp)
×
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

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

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

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

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

UNCOV
238
        return recordProducers
×
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