Skip to content

Commit 72582d4

Browse files
ProofOfKeagsyyforyongyu
authored andcommitted
lnwire: add HtlcMinimum to DynPropose and DynCommit
1 parent f40530e commit 72582d4

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lnwire/dyn_commit.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ func (dc *DynCommit) Encode(w *bytes.Buffer, _ uint32) error {
6060
),
6161
)
6262
})
63+
dc.HtlcMinimum.WhenSome(func(min MilliSatoshi) {
64+
protoSats := uint64(min)
65+
tlvRecords = append(
66+
tlvRecords, tlv.MakePrimitiveRecord(
67+
DPHtlcMinimumMsat, &protoSats,
68+
),
69+
)
70+
})
6371
dc.ChannelReserve.WhenSome(func(min btcutil.Amount) {
6472
channelReserve := uint64(min)
6573
tlvRecords = append(
@@ -137,6 +145,11 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
137145
DPMaxHtlcValueInFlightMsat, &maxValueScratch,
138146
)
139147

148+
var htlcMinScratch uint64
149+
htlcMin := tlv.MakePrimitiveRecord(
150+
DPHtlcMinimumMsat, &htlcMinScratch,
151+
)
152+
140153
var reserveScratch uint64
141154
reserve := tlv.MakePrimitiveRecord(
142155
DPChannelReserveSatoshis, &reserveScratch,
@@ -158,7 +171,8 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
158171

159172
// Create set of Records to read TLV bytestream into.
160173
records := []tlv.Record{
161-
dustLimit, maxValue, reserve, csvDelay, maxHtlcs, chanType,
174+
dustLimit, maxValue, htlcMin, reserve, csvDelay, maxHtlcs,
175+
chanType,
162176
}
163177
tlv.SortRecords(records)
164178

@@ -181,6 +195,9 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
181195
if val, ok := typeMap[DPMaxHtlcValueInFlightMsat]; ok && val == nil {
182196
dc.MaxValueInFlight = fn.Some(MilliSatoshi(maxValueScratch))
183197
}
198+
if val, ok := typeMap[DPHtlcMinimumMsat]; ok && val == nil {
199+
dc.HtlcMinimum = fn.Some(MilliSatoshi(htlcMinScratch))
200+
}
184201
if val, ok := typeMap[DPChannelReserveSatoshis]; ok && val == nil {
185202
dc.ChannelReserve = fn.Some(btcutil.Amount(reserveScratch))
186203
}

lnwire/dyn_propose.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const (
1818
// record for DynPropose.MaxValueInFlight.
1919
DPMaxHtlcValueInFlightMsat tlv.Type = 1
2020

21+
// DPHtlcMinimumMsat is the TLV type number that identifies the record
22+
// for DynPropose.HtlcMinimum.
23+
DPHtlcMinimumMsat tlv.Type = 7
24+
2125
// DPChannelReserveSatoshis is the TLV type number that identifies the
2226
// for DynPropose.ChannelReserve.
2327
DPChannelReserveSatoshis tlv.Type = 2
@@ -50,6 +54,10 @@ type DynPropose struct {
5054
// max_htlc_value_in_flight_msat limit of the sender.
5155
MaxValueInFlight fn.Option[MilliSatoshi]
5256

57+
// HtlcMinimum, if not nil, proposes a change to the htlc_minimum_msat
58+
// floor of the sender.
59+
HtlcMinimum fn.Option[MilliSatoshi]
60+
5361
// ChannelReserve, if not nil, proposes a change to the
5462
// channel_reserve_satoshis requirement of the recipient.
5563
ChannelReserve fn.Option[btcutil.Amount]
@@ -106,6 +114,14 @@ func (dp *DynPropose) Encode(w *bytes.Buffer, _ uint32) error {
106114
),
107115
)
108116
})
117+
dp.HtlcMinimum.WhenSome(func(min MilliSatoshi) {
118+
protoSats := uint64(min)
119+
tlvRecords = append(
120+
tlvRecords, tlv.MakePrimitiveRecord(
121+
DPHtlcMinimumMsat, &protoSats,
122+
),
123+
)
124+
})
109125
dp.ChannelReserve.WhenSome(func(min btcutil.Amount) {
110126
channelReserve := uint64(min)
111127
tlvRecords = append(
@@ -185,6 +201,11 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
185201
DPMaxHtlcValueInFlightMsat, &maxValueScratch,
186202
)
187203

204+
var htlcMinScratch uint64
205+
htlcMin := tlv.MakePrimitiveRecord(
206+
DPHtlcMinimumMsat, &htlcMinScratch,
207+
)
208+
188209
var reserveScratch uint64
189210
reserve := tlv.MakePrimitiveRecord(
190211
DPChannelReserveSatoshis, &reserveScratch,
@@ -206,7 +227,8 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
206227

207228
// Create set of Records to read TLV bytestream into.
208229
records := []tlv.Record{
209-
dustLimit, maxValue, reserve, csvDelay, maxHtlcs, chanType,
230+
dustLimit, maxValue, htlcMin, reserve, csvDelay, maxHtlcs,
231+
chanType,
210232
}
211233
tlv.SortRecords(records)
212234

@@ -230,6 +252,9 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
230252
if val, ok := typeMap[DPMaxHtlcValueInFlightMsat]; ok && val == nil {
231253
dp.MaxValueInFlight = fn.Some(MilliSatoshi(maxValueScratch))
232254
}
255+
if val, ok := typeMap[DPHtlcMinimumMsat]; ok && val == nil {
256+
dp.HtlcMinimum = fn.Some(MilliSatoshi(htlcMinScratch))
257+
}
233258
if val, ok := typeMap[DPChannelReserveSatoshis]; ok && val == nil {
234259
dp.ChannelReserve = fn.Some(btcutil.Amount(reserveScratch))
235260
}
@@ -286,6 +311,14 @@ func (dp *DynPropose) SerializeTlvData() ([]byte, error) {
286311
),
287312
)
288313
})
314+
dp.HtlcMinimum.WhenSome(func(min MilliSatoshi) {
315+
protoSats := uint64(min)
316+
tlvRecords = append(
317+
tlvRecords, tlv.MakePrimitiveRecord(
318+
DPHtlcMinimumMsat, &protoSats,
319+
),
320+
)
321+
})
289322
dp.ChannelReserve.WhenSome(func(min btcutil.Amount) {
290323
channelReserve := uint64(min)
291324
tlvRecords = append(

0 commit comments

Comments
 (0)