mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 14:40:51 +02:00
lnwire: fix encoding ExtraData
in DynPropose
Previously we encode all the fields plus extra data to the field `ExtraData`, this is now fixed by encoding only unknown data to extra data. For known records, they are already encoded into the message fields.
This commit is contained in:
@@ -74,14 +74,23 @@ func (dp *DynPropose) Encode(w *bytes.Buffer, _ uint32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
producers := dynProposeRecords(dp)
|
||||
|
||||
err := EncodeMessageExtraData(&dp.ExtraData, producers...)
|
||||
// Create extra data records.
|
||||
producers, err := dp.ExtraData.RecordProducers()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return WriteBytes(w, dp.ExtraData)
|
||||
// Append the known records.
|
||||
producers = append(producers, dynProposeRecords(dp)...)
|
||||
|
||||
// Encode all records.
|
||||
var tlvData ExtraOpaqueData
|
||||
err = tlvData.PackRecords(producers...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return WriteBytes(w, tlvData)
|
||||
}
|
||||
|
||||
// Decode deserializes the serialized DynPropose stored in the passed io.Reader
|
||||
@@ -124,34 +133,52 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
|
||||
var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
|
||||
rec.Val = dustLimit.Val
|
||||
dp.DustLimit = tlv.SomeRecordT(rec)
|
||||
delete(typeMap, dp.DustLimit.TlvType())
|
||||
}
|
||||
if val, ok := typeMap[dp.MaxValueInFlight.TlvType()]; ok && val == nil {
|
||||
var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
|
||||
rec.Val = MilliSatoshi(maxValue.Val)
|
||||
dp.MaxValueInFlight = tlv.SomeRecordT(rec)
|
||||
|
||||
delete(typeMap, dp.MaxValueInFlight.TlvType())
|
||||
}
|
||||
if val, ok := typeMap[dp.HtlcMinimum.TlvType()]; ok && val == nil {
|
||||
var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi]
|
||||
rec.Val = MilliSatoshi(htlcMin.Val)
|
||||
dp.HtlcMinimum = tlv.SomeRecordT(rec)
|
||||
|
||||
delete(typeMap, dp.HtlcMinimum.TlvType())
|
||||
}
|
||||
if val, ok := typeMap[dp.ChannelReserve.TlvType()]; ok && val == nil {
|
||||
var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
|
||||
rec.Val = reserve.Val
|
||||
dp.ChannelReserve = tlv.SomeRecordT(rec)
|
||||
|
||||
delete(typeMap, dp.ChannelReserve.TlvType())
|
||||
}
|
||||
if val, ok := typeMap[dp.CsvDelay.TlvType()]; ok && val == nil {
|
||||
dp.CsvDelay = tlv.SomeRecordT(csvDelay)
|
||||
|
||||
delete(typeMap, dp.CsvDelay.TlvType())
|
||||
}
|
||||
if val, ok := typeMap[dp.MaxAcceptedHTLCs.TlvType()]; ok && val == nil {
|
||||
dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
|
||||
|
||||
delete(typeMap, dp.MaxAcceptedHTLCs.TlvType())
|
||||
}
|
||||
if val, ok := typeMap[dp.ChannelType.TlvType()]; ok && val == nil {
|
||||
dp.ChannelType = tlv.SomeRecordT(chanType)
|
||||
|
||||
delete(typeMap, dp.ChannelType.TlvType())
|
||||
}
|
||||
|
||||
if len(tlvRecords) != 0 {
|
||||
dp.ExtraData = tlvRecords
|
||||
if len(typeMap) != 0 {
|
||||
extraData, err := NewExtraOpaqueData(typeMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dp.ExtraData = extraData
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user