lnwire: add HtlcMinimum to DynPropose and DynCommit

This commit is contained in:
Keagan McClelland
2024-10-15 20:34:17 -06:00
committed by yyforyongyu
parent f40530e4f4
commit 72582d4acc
2 changed files with 52 additions and 2 deletions

View File

@@ -60,6 +60,14 @@ func (dc *DynCommit) Encode(w *bytes.Buffer, _ uint32) error {
),
)
})
dc.HtlcMinimum.WhenSome(func(min MilliSatoshi) {
protoSats := uint64(min)
tlvRecords = append(
tlvRecords, tlv.MakePrimitiveRecord(
DPHtlcMinimumMsat, &protoSats,
),
)
})
dc.ChannelReserve.WhenSome(func(min btcutil.Amount) {
channelReserve := uint64(min)
tlvRecords = append(
@@ -137,6 +145,11 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
DPMaxHtlcValueInFlightMsat, &maxValueScratch,
)
var htlcMinScratch uint64
htlcMin := tlv.MakePrimitiveRecord(
DPHtlcMinimumMsat, &htlcMinScratch,
)
var reserveScratch uint64
reserve := tlv.MakePrimitiveRecord(
DPChannelReserveSatoshis, &reserveScratch,
@@ -158,7 +171,8 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
// Create set of Records to read TLV bytestream into.
records := []tlv.Record{
dustLimit, maxValue, reserve, csvDelay, maxHtlcs, chanType,
dustLimit, maxValue, htlcMin, reserve, csvDelay, maxHtlcs,
chanType,
}
tlv.SortRecords(records)
@@ -181,6 +195,9 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
if val, ok := typeMap[DPMaxHtlcValueInFlightMsat]; ok && val == nil {
dc.MaxValueInFlight = fn.Some(MilliSatoshi(maxValueScratch))
}
if val, ok := typeMap[DPHtlcMinimumMsat]; ok && val == nil {
dc.HtlcMinimum = fn.Some(MilliSatoshi(htlcMinScratch))
}
if val, ok := typeMap[DPChannelReserveSatoshis]; ok && val == nil {
dc.ChannelReserve = fn.Some(btcutil.Amount(reserveScratch))
}

View File

@@ -18,6 +18,10 @@ const (
// record for DynPropose.MaxValueInFlight.
DPMaxHtlcValueInFlightMsat tlv.Type = 1
// DPHtlcMinimumMsat is the TLV type number that identifies the record
// for DynPropose.HtlcMinimum.
DPHtlcMinimumMsat tlv.Type = 7
// DPChannelReserveSatoshis is the TLV type number that identifies the
// for DynPropose.ChannelReserve.
DPChannelReserveSatoshis tlv.Type = 2
@@ -50,6 +54,10 @@ type DynPropose struct {
// max_htlc_value_in_flight_msat limit of the sender.
MaxValueInFlight fn.Option[MilliSatoshi]
// HtlcMinimum, if not nil, proposes a change to the htlc_minimum_msat
// floor of the sender.
HtlcMinimum fn.Option[MilliSatoshi]
// ChannelReserve, if not nil, proposes a change to the
// channel_reserve_satoshis requirement of the recipient.
ChannelReserve fn.Option[btcutil.Amount]
@@ -106,6 +114,14 @@ func (dp *DynPropose) Encode(w *bytes.Buffer, _ uint32) error {
),
)
})
dp.HtlcMinimum.WhenSome(func(min MilliSatoshi) {
protoSats := uint64(min)
tlvRecords = append(
tlvRecords, tlv.MakePrimitiveRecord(
DPHtlcMinimumMsat, &protoSats,
),
)
})
dp.ChannelReserve.WhenSome(func(min btcutil.Amount) {
channelReserve := uint64(min)
tlvRecords = append(
@@ -185,6 +201,11 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
DPMaxHtlcValueInFlightMsat, &maxValueScratch,
)
var htlcMinScratch uint64
htlcMin := tlv.MakePrimitiveRecord(
DPHtlcMinimumMsat, &htlcMinScratch,
)
var reserveScratch uint64
reserve := tlv.MakePrimitiveRecord(
DPChannelReserveSatoshis, &reserveScratch,
@@ -206,7 +227,8 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
// Create set of Records to read TLV bytestream into.
records := []tlv.Record{
dustLimit, maxValue, reserve, csvDelay, maxHtlcs, chanType,
dustLimit, maxValue, htlcMin, reserve, csvDelay, maxHtlcs,
chanType,
}
tlv.SortRecords(records)
@@ -230,6 +252,9 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
if val, ok := typeMap[DPMaxHtlcValueInFlightMsat]; ok && val == nil {
dp.MaxValueInFlight = fn.Some(MilliSatoshi(maxValueScratch))
}
if val, ok := typeMap[DPHtlcMinimumMsat]; ok && val == nil {
dp.HtlcMinimum = fn.Some(MilliSatoshi(htlcMinScratch))
}
if val, ok := typeMap[DPChannelReserveSatoshis]; ok && val == nil {
dp.ChannelReserve = fn.Some(btcutil.Amount(reserveScratch))
}
@@ -286,6 +311,14 @@ func (dp *DynPropose) SerializeTlvData() ([]byte, error) {
),
)
})
dp.HtlcMinimum.WhenSome(func(min MilliSatoshi) {
protoSats := uint64(min)
tlvRecords = append(
tlvRecords, tlv.MakePrimitiveRecord(
DPHtlcMinimumMsat, &protoSats,
),
)
})
dp.ChannelReserve.WhenSome(func(min btcutil.Amount) {
channelReserve := uint64(min)
tlvRecords = append(