Skip to content

Commit f6b50e0

Browse files
committed
rpc: proper error code for GetChanInfo
When a channel edge is not found, return `NotFound` instead of the generic `Unknown` error code.
1 parent b0cba7d commit f6b50e0

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

docs/release-notes/release-notes-0.19.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ when running LND with an aux component injected (custom channels).
131131
* [Fix a bug](https://github.com/lightningnetwork/lnd/pull/9798) that could
132132
result in a new topology client missing a channel-close notifications.
133133

134+
* [Fix a bug](https://github.com/lightningnetwork/lnd/pull/9810) where the
135+
`GetChanInfo` RPC returned a bad status code for unknown channel edges.
136+
134137
# New Features
135138

136139
* Add support for [archiving channel backup](https://github.com/lightningnetwork/lnd/pull/9232)

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ var allTestCases = []*lntest.TestCase{
563563
Name: "query blinded route",
564564
TestFunc: testQueryBlindedRoutes,
565565
},
566+
{
567+
Name: "query not-found channel info",
568+
TestFunc: testGetChannelInfoNotFound,
569+
},
566570
{
567571
Name: "route blinding invoices",
568572
TestFunc: testBlindedRouteInvoices,

itest/lnd_channel_graph_test.go

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

33
import (
4+
"context"
45
"fmt"
56
"strings"
67
"testing"
@@ -15,7 +16,10 @@ import (
1516
"github.com/lightningnetwork/lnd/lntest/node"
1617
"github.com/lightningnetwork/lnd/lntest/wait"
1718
"github.com/lightningnetwork/lnd/lnwire"
19+
"github.com/stretchr/testify/assert"
1820
"github.com/stretchr/testify/require"
21+
"google.golang.org/grpc/codes"
22+
"google.golang.org/grpc/status"
1923
)
2024

2125
// testUpdateChanStatus checks that calls to the UpdateChanStatus RPC update
@@ -420,6 +424,22 @@ func testNodeAnnouncement(ht *lntest.HarnessTest) {
420424
assertAddrs(nodeUpdate.Addresses, advertisedAddrs...)
421425
}
422426

427+
func testGetChannelInfoNotFound(ht *lntest.HarnessTest) {
428+
ctx, cancel := context.WithTimeout(ht.Context(), lntest.DefaultTimeout)
429+
defer cancel()
430+
431+
alice := ht.NewNode("Alice", nil)
432+
_, err := alice.RPC.LN.GetChanInfo(ctx, &lnrpc.ChanInfoRequest{
433+
ChanId: 949807622323240961,
434+
})
435+
436+
ht.Logf("err: %s", err)
437+
assert.Equal(
438+
ht, codes.NotFound.String(), status.Code(err).String(),
439+
"unknown channels should return a proper status code",
440+
)
441+
}
442+
423443
// testUpdateNodeAnnouncement ensures that the RPC endpoint validates
424444
// the requests correctly and that the new node announcement is broadcast
425445
// with the right information after updating our node.

lntest/rpc/harness_rpc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ func NewHarnessRPC(ctxt context.Context, t *testing.T, c *grpc.ClientConn,
8484
return h
8585
}
8686

87+
// Context returns the context of the RPC harness.
88+
func (h *HarnessRPC) Context() context.Context {
89+
return h.runCtx
90+
}
91+
8792
// MakeOutpoint returns the outpoint of the channel's funding transaction.
8893
func (h *HarnessRPC) MakeOutpoint(cp *lnrpc.ChannelPoint) wire.OutPoint {
8994
fundingTxID, err := lnrpc.GetChanPointFundingTxid(cp)

rpcserver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6913,7 +6913,10 @@ func (r *rpcServer) GetChanInfo(_ context.Context,
69136913
default:
69146914
return nil, fmt.Errorf("specify either chan_id or chan_point")
69156915
}
6916-
if err != nil {
6916+
switch {
6917+
case errors.Is(err, graphdb.ErrEdgeNotFound):
6918+
return nil, status.Error(codes.NotFound, err.Error())
6919+
case err != nil:
69176920
return nil, err
69186921
}
69196922

0 commit comments

Comments
 (0)