Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcserver: remove duplicate info from RoutingPolicy #9572

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/release-notes/release-notes-0.20.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
## Functional Updates

## 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

Expand Down
23 changes: 23 additions & 0 deletions lntest/node/watcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package node

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -697,5 +698,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
}
24 changes: 16 additions & 8 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6669,12 +6669,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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we then maybe add to the CustomRecords proto field that it only includes records that we were not able to extract?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense! Will add!


return records
}

func marshalDBRoutingPolicy(
policy *models.ChannelEdgePolicy) *lnrpc.RoutingPolicy {

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

customRecords := marshalExtraOpaqueData(policy.ExtraOpaqueData)
customRecords := marshalPolicyExtraOpaqueData(policy.ExtraOpaqueData)
inboundFee := extractInboundFeeSafe(policy.ExtraOpaqueData)

return &lnrpc.RoutingPolicy{
Expand Down Expand Up @@ -7179,7 +7190,7 @@ func marshallTopologyChange(
channelUpdates := make([]*lnrpc.ChannelEdgeUpdate, len(topChange.ChannelEdgeUpdates))
for i, channelUpdate := range topChange.ChannelEdgeUpdates {

customRecords := marshalExtraOpaqueData(
customRecords := marshalPolicyExtraOpaqueData(
channelUpdate.ExtraOpaqueData,
)
inboundFee := extractInboundFeeSafe(
Expand Down Expand Up @@ -7779,12 +7790,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).
Expand Down
Loading