From b01437d24e919c4705ded47db1267fe59c95f3b1 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 12 May 2021 16:10:05 -0700 Subject: [PATCH] rpc: fix policy order for GetNodeInfo GetNodeInfo retrieves the policies for every edge the node belongs to. When these policies are retrieved from the database, they're returned in the following order: the first policy is the outgoing policy from the node, and the second is the incoming policy to the node. This ordering is not consistent with the ordering we have within our other RPCs like GetChanInfo and DescribeGraph, where policies are sorted based on the smaller public key of the nodes within an edge. We fix this by maintaining the same order as our other RPCs. --- rpcserver.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index 6338bb7b..e1a19140 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -5155,6 +5155,12 @@ func (r *rpcServer) DescribeGraph(ctx context.Context, func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo, c1, c2 *channeldb.ChannelEdgePolicy) *lnrpc.ChannelEdge { + // Make sure the policies match the node they belong to. c1 should point + // to the policy for NodeKey1, and c2 for NodeKey2. + if c1.ChannelFlags&lnwire.ChanUpdateDirection == 1 { + c2, c1 = c1, c2 + } + // Order the edges by increasing pubkey. if bytes.Compare(edgeInfo.NodeKey2Bytes[:], edgeInfo.NodeKey1Bytes[:]) < 0 {