Merge pull request #9572 from yyforyongyu/fix-custom-msg

rpcserver: remove duplicate info from `RoutingPolicy`
This commit is contained in:
Oliver Gugger authored and GitHub committed 2025-07-02 09:16:17 +02:00
commit 1d2e5472b3
7 files changed
+51 -12

No files matched your search

@@ -94,6 +94,12 @@ circuit. The indices are only available for forwarding events saved after v0.20.
* [11](https://github.com/lightningnetwork/lnd/pull/9972)
## RPC Updates
* Previously the `RoutingPolicy` would return the inbound fee record in its
`CustomRecords` field, which is duplicated info as it's already presented in
fields `InboundFeeBaseMsat` and `InboundFeeRateMilliMsat`. This is now
[fixed](https://github.com/lightningnetwork/lnd/pull/9572), the affected RPCs
are `SubscribeChannelGraph`, `GetChanInfo`, `GetNodeInfo` and `DescribeGraph`.
## lncli Updates
+1 -1
View File
@@ -320,7 +320,7 @@
"type": "string",
"format": "byte"
},
"description": "Custom channel update tlv records."
"description": "Custom channel update tlv records. These are customized fields that are\nnot defined by LND and cannot be extracted."
},
"inbound_fee_base_msat": {
"type": "integer",
+2 -1
View File
@@ -10993,7 +10993,8 @@ type RoutingPolicy struct {
Disabled bool `protobuf:"varint,5,opt,name=disabled,proto3" json:"disabled,omitempty"`
MaxHtlcMsat uint64 `protobuf:"varint,6,opt,name=max_htlc_msat,json=maxHtlcMsat,proto3" json:"max_htlc_msat,omitempty"`
LastUpdate uint32 `protobuf:"varint,7,opt,name=last_update,json=lastUpdate,proto3" json:"last_update,omitempty"`
// Custom channel update tlv records.
// Custom channel update tlv records. These are customized fields that are
// not defined by LND and cannot be extracted.
CustomRecords map[uint64][]byte `protobuf:"bytes,8,rep,name=custom_records,json=customRecords,proto3" json:"custom_records,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
InboundFeeBaseMsat int32 `protobuf:"varint,9,opt,name=inbound_fee_base_msat,json=inboundFeeBaseMsat,proto3" json:"inbound_fee_base_msat,omitempty"`
InboundFeeRateMilliMsat int32 `protobuf:"varint,10,opt,name=inbound_fee_rate_milli_msat,json=inboundFeeRateMilliMsat,proto3" json:"inbound_fee_rate_milli_msat,omitempty"`
+2 -1
View File
@@ -3471,7 +3471,8 @@ message RoutingPolicy {
uint64 max_htlc_msat = 6;
uint32 last_update = 7;
// Custom channel update tlv records.
// Custom channel update tlv records. These are customized fields that are
// not defined by LND and cannot be extracted.
map<uint64, bytes> custom_records = 8;
int32 inbound_fee_base_msat = 9;
+1 -1
View File
@@ -7350,7 +7350,7 @@
"type": "string",
"format": "byte"
},
"description": "Custom channel update tlv records."
"description": "Custom channel update tlv records. These are customized fields that are\nnot defined by LND and cannot be extracted."
},
"inbound_fee_base_msat": {
"type": "integer",
+23
View File
@@ -1,6 +1,7 @@
package node
import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -725,5 +726,27 @@ func CheckChannelPolicy(policy, expectedPolicy *lnrpc.RoutingPolicy) error {
return errors.New("edge should be disabled but isn't")
}
// We now validate custom records.
records := policy.CustomRecords
if len(records) != len(expectedPolicy.CustomRecords) {
return fmt.Errorf("expected %v CustomRecords, got %v, "+
"records: %v", len(expectedPolicy.CustomRecords),
len(records), records)
}
expectedRecords := expectedPolicy.CustomRecords
for k, record := range records {
expected, found := expectedRecords[k]
if !found {
return fmt.Errorf("CustomRecords %v not found", k)
}
if !bytes.Equal(record, expected) {
return fmt.Errorf("want CustomRecords(%v) %s, got %s",
k, expected, record)
}
}
return nil
}
+16 -8
View File
@@ -6842,12 +6842,23 @@ func marshalDBEdge(edgeInfo *models.ChannelEdgeInfo,
return edge
}
// marshalPolicyExtraOpaqueData marshals the given tlv data and filters out
// inbound fee record.
func marshalPolicyExtraOpaqueData(data []byte) map[uint64][]byte {
records := marshalExtraOpaqueData(data)
// Remove the inbound fee record as we have dedicated fields for it.
delete(records, uint64(lnwire.FeeRecordType))
return records
}
func marshalDBRoutingPolicy(
policy *models.ChannelEdgePolicy) *lnrpc.RoutingPolicy {
disabled := policy.ChannelFlags&lnwire.ChanUpdateDisabled != 0
customRecords := marshalExtraOpaqueData(policy.ExtraOpaqueData)
customRecords := marshalPolicyExtraOpaqueData(policy.ExtraOpaqueData)
inboundFee := policy.InboundFee.UnwrapOr(lnwire.Fee{})
return &lnrpc.RoutingPolicy{
@@ -7361,7 +7372,7 @@ func marshallTopologyChange(
channelUpdates := make([]*lnrpc.ChannelEdgeUpdate, len(topChange.ChannelEdgeUpdates))
for i, channelUpdate := range topChange.ChannelEdgeUpdates {
customRecords := marshalExtraOpaqueData(
customRecords := marshalPolicyExtraOpaqueData(
channelUpdate.ExtraOpaqueData,
)
inboundFee := channelUpdate.InboundFee.UnwrapOr(lnwire.Fee{})
@@ -7954,12 +7965,9 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
MinHTLC: minHtlc,
}
rpcsLog.Debugf("[updatechanpolicy] updating channel policy "+
"base_fee=%v, rate_fixed=%v, time_lock_delta: %v, "+
"min_htlc=%v, max_htlc=%v, targets=%v",
req.BaseFeeMsat, feeRateFixed, req.TimeLockDelta,
minHtlc, maxHtlc,
spew.Sdump(targetChans))
rpcsLog.Debugf("[updatechanpolicy] updating channel policy, "+
"targets=%v, req=%v", lnutils.SpewLogClosure(targetChans),
lnutils.SpewLogClosure(req))
// With the scope resolved, we'll now send this to the local channel
// manager so it can propagate the new policy for our target channel(s).