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

lncli: remote peer alias in listchannels #7322

Merged
merged 5 commits into from
Feb 24, 2023
Merged
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
20 changes: 15 additions & 5 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,11 @@ var listChannelsCommand = cli.Command{
"particular peer, accepts 66-byte, " +
"hex-encoded pubkeys",
},
cli.BoolFlag{
Name: "skip_peer_alias_lookup",
Usage: "skip the peer alias lookup per channel in " +
"order to improve performance",
},
},
Action: actionDecorator(listChannels),
}
Expand Down Expand Up @@ -1463,12 +1468,17 @@ func listChannels(ctx *cli.Context) error {
peerKey = pk[:]
}

// By default we will look up the peers' alias information unless the
// skip_peer_alias_lookup flag indicates otherwise.
lookupPeerAlias := !ctx.Bool("skip_peer_alias_lookup")

req := &lnrpc.ListChannelsRequest{
ActiveOnly: ctx.Bool("active_only"),
InactiveOnly: ctx.Bool("inactive_only"),
PublicOnly: ctx.Bool("public_only"),
PrivateOnly: ctx.Bool("private_only"),
Peer: peerKey,
ActiveOnly: ctx.Bool("active_only"),
InactiveOnly: ctx.Bool("inactive_only"),
PublicOnly: ctx.Bool("public_only"),
PrivateOnly: ctx.Bool("private_only"),
Peer: peerKey,
PeerAliasLookup: lookupPeerAlias,
}

resp, err := client.ListChannels(ctxc, req)
Expand Down
7 changes: 7 additions & 0 deletions docs/release-notes/release-notes-0.16.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ of order is also [fixed](https://github.com/lightningnetwork/lnd/pull/7264).
`updatenodeannouncement` peers cli which did not allow setting/
unsetting of feature bits also has been fixed.

* [Enrich the `Channel` message with a peers' alias in order to retrieve it
in `ListChannels`.](https://github.com/lightningnetwork/lnd/pull/7322) This
behavior is opt-in for users of the rpc interface through a new parameter in
`ListChannelsRequest` called `PeerAliasLookup`. For users of lncli this
parameter is enabled by default but can be disabled with a new flag
`--skip_peer_alias_lookup`.

## Wallet

* [Allows Taproot public keys and tap scripts to be imported as watch-only
Expand Down
18 changes: 18 additions & 0 deletions itest/lnd_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,20 @@ func testListChannels(ht *lntest.HarnessTest) {
// Check the returned response is correct.
aliceChannel := ht.QueryChannelByChanPoint(alice, chanPoint)

// Query the channel again, this time with peer alias lookup.
aliceChannelWithAlias := ht.QueryChannelByChanPoint(
alice, chanPoint, lntest.WithPeerAliasLookup(),
)

// Since Alice is the initiator, she pays the commit fee.
aliceBalance := int64(chanAmt) - aliceChannel.CommitFee - int64(pushAmt)

bobAlias := bob.RPC.GetInfo().Alias

// Check the balance related fields are correct.
require.Equal(ht, aliceBalance, aliceChannel.LocalBalance)
require.Empty(ht, aliceChannel.PeerAlias)
require.Equal(ht, bobAlias, aliceChannelWithAlias.PeerAlias)
require.EqualValues(ht, pushAmt, aliceChannel.RemoteBalance)
require.EqualValues(ht, pushAmt, aliceChannel.PushAmountSat)

Expand Down Expand Up @@ -318,8 +327,17 @@ func testListChannels(ht *lntest.HarnessTest) {
require.Equal(ht, aliceChannel.ChannelPoint, bobChannel.ChannelPoint,
"Bob's channel point mismatched")

// Query the channel again, this time with node alias lookup.
bobChannelWithAlias := ht.QueryChannelByChanPoint(
bob, chanPoint, lntest.WithPeerAliasLookup(),
)

aliceAlias := alice.RPC.GetInfo().Alias

// Check the balance related fields are correct.
require.Equal(ht, aliceBalance, bobChannel.RemoteBalance)
require.Empty(ht, bobChannel.PeerAlias)
require.Equal(ht, aliceAlias, bobChannelWithAlias.PeerAlias)
require.EqualValues(ht, pushAmt, bobChannel.LocalBalance)
require.EqualValues(ht, pushAmt, bobChannel.PushAmountSat)

Expand Down
4,689 changes: 2,357 additions & 2,332 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,9 @@ message Channel {

// This is the confirmed / on-chain zero-conf SCID.
uint64 zero_conf_confirmed_scid = 33;

// The configured alias name of our peer.
string peer_alias = 34;
}

message ListChannelsRequest {
Expand All @@ -1544,6 +1547,11 @@ message ListChannelsRequest {
empty, all channels will be returned.
*/
bytes peer = 5;

// Informs the server if the peer alias lookup per channel should be
// enabled. It is turned off by default in order to avoid degradation of
// performance for existing clients.
bool peer_alias_lookup = 6;
}
message ListChannelsResponse {
// The list of active channels
Expand Down
11 changes: 11 additions & 0 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@
"required": false,
"type": "string",
"format": "byte"
},
{
"name": "peer_alias_lookup",
"description": "Informs the server if the peer alias lookup per channel should be\nenabled. It is turned off by default in order to avoid degradation of\nperformance for existing clients.",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
Expand Down Expand Up @@ -3556,6 +3563,10 @@
"type": "string",
"format": "uint64",
"description": "This is the confirmed / on-chain zero-conf SCID."
},
"peer_alias": {
"type": "string",
"description": "The configured alias name of our peer."
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions lntest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,10 +1598,12 @@ func (h *HarnessTest) MineEmptyBlocks(num int) []*wire.MsgBlock {
// QueryChannelByChanPoint tries to find a channel matching the channel point
// and asserts. It returns the channel found.
func (h *HarnessTest) QueryChannelByChanPoint(hn *node.HarnessNode,
chanPoint *lnrpc.ChannelPoint) *lnrpc.Channel {
chanPoint *lnrpc.ChannelPoint,
opts ...ListChannelOption) *lnrpc.Channel {

channel, err := h.findChannel(hn, chanPoint)
channel, err := h.findChannel(hn, chanPoint, opts...)
require.NoError(h, err, "failed to query channel")

return channel
}

Expand Down
20 changes: 19 additions & 1 deletion lntest/harness_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ import (
"google.golang.org/protobuf/proto"
)

// FindChannelOption is a functional type for an option that modifies a
// ListChannelsRequest.
type ListChannelOption func(r *lnrpc.ListChannelsRequest)

// WithPeerAliasLookup is an option for setting the peer alias lookup flag on a
// ListChannelsRequest.
func WithPeerAliasLookup() ListChannelOption {
return func(r *lnrpc.ListChannelsRequest) {
r.PeerAliasLookup = true
}
}

// WaitForBlockchainSync waits until the node is synced to chain.
func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
err := wait.NoError(func() error {
Expand Down Expand Up @@ -368,12 +380,18 @@ func (h *HarnessTest) AssertChannelExists(hn *node.HarnessNode,
// findChannel tries to find a target channel in the node using the given
// channel point.
func (h *HarnessTest) findChannel(hn *node.HarnessNode,
chanPoint *lnrpc.ChannelPoint) (*lnrpc.Channel, error) {
chanPoint *lnrpc.ChannelPoint,
opts ...ListChannelOption) (*lnrpc.Channel, error) {

// Get the funding point.
fp := h.OutPointFromChannelPoint(chanPoint)

req := &lnrpc.ListChannelsRequest{}

for _, opt := range opts {
opt(req)
}

channelInfo := hn.RPC.ListChannels(req)

// Find the target channel.
Expand Down
19 changes: 15 additions & 4 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4017,7 +4017,9 @@ func (r *rpcServer) ListChannels(ctx context.Context,
// Next, we'll determine whether we should add this channel to
// our list depending on the type of channels requested to us.
isActive := peerOnline && linkActive
channel, err := createRPCOpenChannel(r, dbChannel, isActive)
channel, err := createRPCOpenChannel(
r, dbChannel, isActive, in.PeerAliasLookup,
guggero marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -4066,7 +4068,6 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
// *Channeldb.ChannelConfig.
func createChannelConstraint(
chanCfg *channeldb.ChannelConfig) *lnrpc.ChannelConstraints {

return &lnrpc.ChannelConstraints{
CsvDelay: uint32(chanCfg.CsvDelay),
ChanReserveSat: uint64(chanCfg.ChanReserve),
Expand All @@ -4088,7 +4089,7 @@ func isPrivate(dbChannel *channeldb.OpenChannel) bool {

// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
isActive bool) (*lnrpc.Channel, error) {
isActive, peerAliasLookup bool) (*lnrpc.Channel, error) {

nodePub := dbChannel.IdentityPub
nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
Expand Down Expand Up @@ -4164,6 +4165,16 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
RemoteChanReserveSat: int64(dbChannel.RemoteChanCfg.ChanReserve),
}

hieblmi marked this conversation as resolved.
Show resolved Hide resolved
// Look up our channel peer's node alias if the caller requests it.
if peerAliasLookup {
peerAlias, err := r.server.graphDB.LookupAlias(nodePub)
if err != nil {
return nil, fmt.Errorf("unable to lookup peer "+
"alias: %w", err)
}
channel.PeerAlias = peerAlias
}

// Populate the set of aliases.
for _, chanAlias := range channelAliases {
channel.AliasScids = append(
Expand Down Expand Up @@ -4576,7 +4587,7 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription,
}
case channelnotifier.OpenChannelEvent:
channel, err := createRPCOpenChannel(
r, event.Channel, true,
r, event.Channel, true, false,
)
if err != nil {
return err
Expand Down