diff --git a/lnwire/channel_update_2.go b/lnwire/channel_update_2.go index b832bc58d..7fe7670ed 100644 --- a/lnwire/channel_update_2.go +++ b/lnwire/channel_update_2.go @@ -70,6 +70,11 @@ type ChannelUpdate2 struct { // millionth of a satoshi. FeeProportionalMillionths tlv.RecordT[tlv.TlvType18, uint32] + // InboundFee is an optional TLV record that contains the fee + // information for incoming HTLCs. + // TODO(elle): assign normal tlv type? + InboundFee tlv.OptionalRecordT[tlv.TlvType55555, Fee] + // Signature is used to validate the announced data and prove the // ownership of node id. Signature tlv.RecordT[tlv.TlvType160, Sig] @@ -102,12 +107,13 @@ func (c *ChannelUpdate2) Decode(r io.Reader, _ uint32) error { var ( chainHash = tlv.ZeroRecordT[tlv.TlvType0, [32]byte]() secondPeer = tlv.ZeroRecordT[tlv.TlvType8, TrueBoolean]() + inboundFee = tlv.ZeroRecordT[tlv.TlvType55555, Fee]() ) typeMap, err := tlvRecords.ExtractRecords( &chainHash, &c.ShortChannelID, &c.BlockHeight, &c.DisabledFlags, &secondPeer, &c.CLTVExpiryDelta, &c.HTLCMinimumMsat, &c.HTLCMaximumMsat, &c.FeeBaseMsat, - &c.FeeProportionalMillionths, + &c.FeeProportionalMillionths, &inboundFee, &c.Signature, ) if err != nil { @@ -149,6 +155,11 @@ func (c *ChannelUpdate2) Decode(r io.Reader, _ uint32) error { c.FeeProportionalMillionths.Val = defaultFeeProportionalMillionths //nolint:ll } + // If the inbound fee was encoded, set it. + if _, ok := typeMap[c.InboundFee.TlvType()]; ok { + c.InboundFee = tlv.SomeRecordT(inboundFee) + } + c.ExtraSignedFields = ExtraSignedFieldsFromTypeMap(typeMap) return nil @@ -207,6 +218,10 @@ func (c *ChannelUpdate2) AllRecords() []tlv.Record { ) } + c.InboundFee.WhenSome(func(r tlv.RecordT[tlv.TlvType55555, Fee]) { + recordProducers = append(recordProducers, &r) + }) + recordProducers = append(recordProducers, RecordsAsProducers( tlv.MapToRecords(c.ExtraSignedFields), )...) diff --git a/lnwire/test_message.go b/lnwire/test_message.go index dc55ef5c1..fd0d1d66a 100644 --- a/lnwire/test_message.go +++ b/lnwire/test_message.go @@ -569,6 +569,18 @@ func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message { ExtraSignedFields: make(map[uint64][]byte), } + if rapid.Bool().Draw(t, "includeInboundFee") { + base := rapid.IntRange(-1000, 1000).Draw(t, "inFeeBase") + rate := rapid.IntRange(-1000, 1000).Draw(t, "inFeeProp") + fee := Fee{ + BaseFee: int32(base), + FeeRate: int32(rate), + } + msg.InboundFee = tlv.SomeRecordT( + tlv.NewRecordT[tlv.TlvType55555](fee), + ) + } + msg.Signature.Val = RandSignature(t) msg.Signature.Val.ForceSchnorr()