mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 22:27:22 +01:00
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:
@@ -70,6 +70,11 @@ type ChannelUpdate2 struct {
|
|||||||
// millionth of a satoshi.
|
// millionth of a satoshi.
|
||||||
FeeProportionalMillionths tlv.RecordT[tlv.TlvType18, uint32]
|
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
|
// Signature is used to validate the announced data and prove the
|
||||||
// ownership of node id.
|
// ownership of node id.
|
||||||
Signature tlv.RecordT[tlv.TlvType160, Sig]
|
Signature tlv.RecordT[tlv.TlvType160, Sig]
|
||||||
@@ -102,12 +107,13 @@ func (c *ChannelUpdate2) Decode(r io.Reader, _ uint32) error {
|
|||||||
var (
|
var (
|
||||||
chainHash = tlv.ZeroRecordT[tlv.TlvType0, [32]byte]()
|
chainHash = tlv.ZeroRecordT[tlv.TlvType0, [32]byte]()
|
||||||
secondPeer = tlv.ZeroRecordT[tlv.TlvType8, TrueBoolean]()
|
secondPeer = tlv.ZeroRecordT[tlv.TlvType8, TrueBoolean]()
|
||||||
|
inboundFee = tlv.ZeroRecordT[tlv.TlvType55555, Fee]()
|
||||||
)
|
)
|
||||||
typeMap, err := tlvRecords.ExtractRecords(
|
typeMap, err := tlvRecords.ExtractRecords(
|
||||||
&chainHash, &c.ShortChannelID, &c.BlockHeight, &c.DisabledFlags,
|
&chainHash, &c.ShortChannelID, &c.BlockHeight, &c.DisabledFlags,
|
||||||
&secondPeer, &c.CLTVExpiryDelta, &c.HTLCMinimumMsat,
|
&secondPeer, &c.CLTVExpiryDelta, &c.HTLCMinimumMsat,
|
||||||
&c.HTLCMaximumMsat, &c.FeeBaseMsat,
|
&c.HTLCMaximumMsat, &c.FeeBaseMsat,
|
||||||
&c.FeeProportionalMillionths,
|
&c.FeeProportionalMillionths, &inboundFee,
|
||||||
&c.Signature,
|
&c.Signature,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -149,6 +155,11 @@ func (c *ChannelUpdate2) Decode(r io.Reader, _ uint32) error {
|
|||||||
c.FeeProportionalMillionths.Val = defaultFeeProportionalMillionths //nolint:ll
|
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)
|
c.ExtraSignedFields = ExtraSignedFieldsFromTypeMap(typeMap)
|
||||||
|
|
||||||
return nil
|
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(
|
recordProducers = append(recordProducers, RecordsAsProducers(
|
||||||
tlv.MapToRecords(c.ExtraSignedFields),
|
tlv.MapToRecords(c.ExtraSignedFields),
|
||||||
)...)
|
)...)
|
||||||
|
|||||||
@@ -569,6 +569,18 @@ func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
|
|||||||
ExtraSignedFields: make(map[uint64][]byte),
|
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 = RandSignature(t)
|
||||||
msg.Signature.Val.ForceSchnorr()
|
msg.Signature.Val.ForceSchnorr()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user