lnwire: add inbound fee to ChannelUpdate2

We leave a TODO that should be addressed after a discussion at the spec
meeting. For now, having the incorrect TLV type is not a problem since
this ChannelUpdate2 type is not used in production.
This commit is contained in:
Elle Mouton
2025-09-22 11:18:20 +02:00
parent b8abe130a5
commit e9a4f22dd6
2 changed files with 28 additions and 1 deletions

View File

@@ -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),
)...)

View File

@@ -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()