Skip to content

Commit 1d2e547

Browse files
authored
Merge pull request #9572 from yyforyongyu/fix-custom-msg
rpcserver: remove duplicate info from `RoutingPolicy`
2 parents 7be45c3 + 43ea309 commit 1d2e547

File tree

7 files changed

+51
-12
lines changed

7 files changed

+51
-12
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ circuit. The indices are only available for forwarding events saved after v0.20.
9494
* [11](https://github.com/lightningnetwork/lnd/pull/9972)
9595

9696
## RPC Updates
97+
* Previously the `RoutingPolicy` would return the inbound fee record in its
98+
`CustomRecords` field, which is duplicated info as it's already presented in
99+
fields `InboundFeeBaseMsat` and `InboundFeeRateMilliMsat`. This is now
100+
[fixed](https://github.com/lightningnetwork/lnd/pull/9572), the affected RPCs
101+
are `SubscribeChannelGraph`, `GetChanInfo`, `GetNodeInfo` and `DescribeGraph`.
102+
97103

98104
## lncli Updates
99105

lnrpc/devrpc/dev.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
"type": "string",
321321
"format": "byte"
322322
},
323-
"description": "Custom channel update tlv records."
323+
"description": "Custom channel update tlv records. These are customized fields that are\nnot defined by LND and cannot be extracted."
324324
},
325325
"inbound_fee_base_msat": {
326326
"type": "integer",

lnrpc/lightning.pb.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/lightning.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3471,7 +3471,8 @@ message RoutingPolicy {
34713471
uint64 max_htlc_msat = 6;
34723472
uint32 last_update = 7;
34733473

3474-
// Custom channel update tlv records.
3474+
// Custom channel update tlv records. These are customized fields that are
3475+
// not defined by LND and cannot be extracted.
34753476
map<uint64, bytes> custom_records = 8;
34763477

34773478
int32 inbound_fee_base_msat = 9;

lnrpc/lightning.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7350,7 +7350,7 @@
73507350
"type": "string",
73517351
"format": "byte"
73527352
},
7353-
"description": "Custom channel update tlv records."
7353+
"description": "Custom channel update tlv records. These are customized fields that are\nnot defined by LND and cannot be extracted."
73547354
},
73557355
"inbound_fee_base_msat": {
73567356
"type": "integer",

lntest/node/watcher.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package node
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"errors"
@@ -725,5 +726,27 @@ func CheckChannelPolicy(policy, expectedPolicy *lnrpc.RoutingPolicy) error {
725726
return errors.New("edge should be disabled but isn't")
726727
}
727728

729+
// We now validate custom records.
730+
records := policy.CustomRecords
731+
732+
if len(records) != len(expectedPolicy.CustomRecords) {
733+
return fmt.Errorf("expected %v CustomRecords, got %v, "+
734+
"records: %v", len(expectedPolicy.CustomRecords),
735+
len(records), records)
736+
}
737+
738+
expectedRecords := expectedPolicy.CustomRecords
739+
for k, record := range records {
740+
expected, found := expectedRecords[k]
741+
if !found {
742+
return fmt.Errorf("CustomRecords %v not found", k)
743+
}
744+
745+
if !bytes.Equal(record, expected) {
746+
return fmt.Errorf("want CustomRecords(%v) %s, got %s",
747+
k, expected, record)
748+
}
749+
}
750+
728751
return nil
729752
}

rpcserver.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6842,12 +6842,23 @@ func marshalDBEdge(edgeInfo *models.ChannelEdgeInfo,
68426842
return edge
68436843
}
68446844

6845+
// marshalPolicyExtraOpaqueData marshals the given tlv data and filters out
6846+
// inbound fee record.
6847+
func marshalPolicyExtraOpaqueData(data []byte) map[uint64][]byte {
6848+
records := marshalExtraOpaqueData(data)
6849+
6850+
// Remove the inbound fee record as we have dedicated fields for it.
6851+
delete(records, uint64(lnwire.FeeRecordType))
6852+
6853+
return records
6854+
}
6855+
68456856
func marshalDBRoutingPolicy(
68466857
policy *models.ChannelEdgePolicy) *lnrpc.RoutingPolicy {
68476858

68486859
disabled := policy.ChannelFlags&lnwire.ChanUpdateDisabled != 0
68496860

6850-
customRecords := marshalExtraOpaqueData(policy.ExtraOpaqueData)
6861+
customRecords := marshalPolicyExtraOpaqueData(policy.ExtraOpaqueData)
68516862
inboundFee := policy.InboundFee.UnwrapOr(lnwire.Fee{})
68526863

68536864
return &lnrpc.RoutingPolicy{
@@ -7361,7 +7372,7 @@ func marshallTopologyChange(
73617372
channelUpdates := make([]*lnrpc.ChannelEdgeUpdate, len(topChange.ChannelEdgeUpdates))
73627373
for i, channelUpdate := range topChange.ChannelEdgeUpdates {
73637374

7364-
customRecords := marshalExtraOpaqueData(
7375+
customRecords := marshalPolicyExtraOpaqueData(
73657376
channelUpdate.ExtraOpaqueData,
73667377
)
73677378
inboundFee := channelUpdate.InboundFee.UnwrapOr(lnwire.Fee{})
@@ -7954,12 +7965,9 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
79547965
MinHTLC: minHtlc,
79557966
}
79567967

7957-
rpcsLog.Debugf("[updatechanpolicy] updating channel policy "+
7958-
"base_fee=%v, rate_fixed=%v, time_lock_delta: %v, "+
7959-
"min_htlc=%v, max_htlc=%v, targets=%v",
7960-
req.BaseFeeMsat, feeRateFixed, req.TimeLockDelta,
7961-
minHtlc, maxHtlc,
7962-
spew.Sdump(targetChans))
7968+
rpcsLog.Debugf("[updatechanpolicy] updating channel policy, "+
7969+
"targets=%v, req=%v", lnutils.SpewLogClosure(targetChans),
7970+
lnutils.SpewLogClosure(req))
79637971

79647972
// With the scope resolved, we'll now send this to the local channel
79657973
// manager so it can propagate the new policy for our target channel(s).

0 commit comments

Comments
 (0)