Merge pull request #7322 from hieblmi/cmd-listchannels-peer-alias
lncli: remote peer alias in `listchannels`
This commit is contained in:
9 files changed
+2454
-2344
No files matched your search
+15
-5
@@ -1415,6 +1415,11 @@ var listChannelsCommand = cli.Command{
|
|||||||
"particular peer, accepts 66-byte, " +
|
"particular peer, accepts 66-byte, " +
|
||||||
"hex-encoded pubkeys",
|
"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),
|
Action: actionDecorator(listChannels),
|
||||||
}
|
}
|
||||||
@@ -1463,12 +1468,17 @@ func listChannels(ctx *cli.Context) error {
|
|||||||
peerKey = pk[:]
|
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{
|
req := &lnrpc.ListChannelsRequest{
|
||||||
ActiveOnly: ctx.Bool("active_only"),
|
ActiveOnly: ctx.Bool("active_only"),
|
||||||
InactiveOnly: ctx.Bool("inactive_only"),
|
InactiveOnly: ctx.Bool("inactive_only"),
|
||||||
PublicOnly: ctx.Bool("public_only"),
|
PublicOnly: ctx.Bool("public_only"),
|
||||||
PrivateOnly: ctx.Bool("private_only"),
|
PrivateOnly: ctx.Bool("private_only"),
|
||||||
Peer: peerKey,
|
Peer: peerKey,
|
||||||
|
PeerAliasLookup: lookupPeerAlias,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.ListChannels(ctxc, req)
|
resp, err := client.ListChannels(ctxc, req)
|
||||||
|
|||||||
@@ -141,6 +141,13 @@ of order is also [fixed](https://github.com/lightningnetwork/lnd/pull/7264).
|
|||||||
`updatenodeannouncement` peers cli which did not allow setting/
|
`updatenodeannouncement` peers cli which did not allow setting/
|
||||||
unsetting of feature bits also has been fixed.
|
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
|
## Wallet
|
||||||
|
|
||||||
* [Allows Taproot public keys and tap scripts to be imported as watch-only
|
* [Allows Taproot public keys and tap scripts to be imported as watch-only
|
||||||
|
|||||||
@@ -272,11 +272,20 @@ func testListChannels(ht *lntest.HarnessTest) {
|
|||||||
// Check the returned response is correct.
|
// Check the returned response is correct.
|
||||||
aliceChannel := ht.QueryChannelByChanPoint(alice, chanPoint)
|
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.
|
// Since Alice is the initiator, she pays the commit fee.
|
||||||
aliceBalance := int64(chanAmt) - aliceChannel.CommitFee - int64(pushAmt)
|
aliceBalance := int64(chanAmt) - aliceChannel.CommitFee - int64(pushAmt)
|
||||||
|
|
||||||
|
bobAlias := bob.RPC.GetInfo().Alias
|
||||||
|
|
||||||
// Check the balance related fields are correct.
|
// Check the balance related fields are correct.
|
||||||
require.Equal(ht, aliceBalance, aliceChannel.LocalBalance)
|
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.RemoteBalance)
|
||||||
require.EqualValues(ht, pushAmt, aliceChannel.PushAmountSat)
|
require.EqualValues(ht, pushAmt, aliceChannel.PushAmountSat)
|
||||||
|
|
||||||
@@ -318,8 +327,17 @@ func testListChannels(ht *lntest.HarnessTest) {
|
|||||||
require.Equal(ht, aliceChannel.ChannelPoint, bobChannel.ChannelPoint,
|
require.Equal(ht, aliceChannel.ChannelPoint, bobChannel.ChannelPoint,
|
||||||
"Bob's channel point mismatched")
|
"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.
|
// Check the balance related fields are correct.
|
||||||
require.Equal(ht, aliceBalance, bobChannel.RemoteBalance)
|
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.LocalBalance)
|
||||||
require.EqualValues(ht, pushAmt, bobChannel.PushAmountSat)
|
require.EqualValues(ht, pushAmt, bobChannel.PushAmountSat)
|
||||||
|
|
||||||
|
|||||||
+2357
-2332
File diff suppressed because it is too large.
Load diff
@@ -1531,6 +1531,9 @@ message Channel {
|
|||||||
|
|
||||||
// This is the confirmed / on-chain zero-conf SCID.
|
// This is the confirmed / on-chain zero-conf SCID.
|
||||||
uint64 zero_conf_confirmed_scid = 33;
|
uint64 zero_conf_confirmed_scid = 33;
|
||||||
|
|
||||||
|
// The configured alias name of our peer.
|
||||||
|
string peer_alias = 34;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListChannelsRequest {
|
message ListChannelsRequest {
|
||||||
@@ -1544,6 +1547,11 @@ message ListChannelsRequest {
|
|||||||
empty, all channels will be returned.
|
empty, all channels will be returned.
|
||||||
*/
|
*/
|
||||||
bytes peer = 5;
|
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 {
|
message ListChannelsResponse {
|
||||||
// The list of active channels
|
// The list of active channels
|
||||||
|
|||||||
@@ -135,6 +135,13 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "byte"
|
"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": [
|
"tags": [
|
||||||
@@ -3556,6 +3563,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "uint64",
|
"format": "uint64",
|
||||||
"description": "This is the confirmed / on-chain zero-conf SCID."
|
"description": "This is the confirmed / on-chain zero-conf SCID."
|
||||||
|
},
|
||||||
|
"peer_alias": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The configured alias name of our peer."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+4
-2
@@ -1598,10 +1598,12 @@ func (h *HarnessTest) MineEmptyBlocks(num int) []*wire.MsgBlock {
|
|||||||
// QueryChannelByChanPoint tries to find a channel matching the channel point
|
// QueryChannelByChanPoint tries to find a channel matching the channel point
|
||||||
// and asserts. It returns the channel found.
|
// and asserts. It returns the channel found.
|
||||||
func (h *HarnessTest) QueryChannelByChanPoint(hn *node.HarnessNode,
|
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")
|
require.NoError(h, err, "failed to query channel")
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,18 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"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.
|
// WaitForBlockchainSync waits until the node is synced to chain.
|
||||||
func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
|
func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
|
||||||
err := wait.NoError(func() error {
|
err := wait.NoError(func() error {
|
||||||
@@ -368,12 +380,18 @@ func (h *HarnessTest) AssertChannelExists(hn *node.HarnessNode,
|
|||||||
// findChannel tries to find a target channel in the node using the given
|
// findChannel tries to find a target channel in the node using the given
|
||||||
// channel point.
|
// channel point.
|
||||||
func (h *HarnessTest) findChannel(hn *node.HarnessNode,
|
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.
|
// Get the funding point.
|
||||||
fp := h.OutPointFromChannelPoint(chanPoint)
|
fp := h.OutPointFromChannelPoint(chanPoint)
|
||||||
|
|
||||||
req := &lnrpc.ListChannelsRequest{}
|
req := &lnrpc.ListChannelsRequest{}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(req)
|
||||||
|
}
|
||||||
|
|
||||||
channelInfo := hn.RPC.ListChannels(req)
|
channelInfo := hn.RPC.ListChannels(req)
|
||||||
|
|
||||||
// Find the target channel.
|
// Find the target channel.
|
||||||
|
|||||||
+15
-4
@@ -4017,7 +4017,9 @@ func (r *rpcServer) ListChannels(ctx context.Context,
|
|||||||
// Next, we'll determine whether we should add this channel to
|
// Next, we'll determine whether we should add this channel to
|
||||||
// our list depending on the type of channels requested to us.
|
// our list depending on the type of channels requested to us.
|
||||||
isActive := peerOnline && linkActive
|
isActive := peerOnline && linkActive
|
||||||
channel, err := createRPCOpenChannel(r, dbChannel, isActive)
|
channel, err := createRPCOpenChannel(
|
||||||
|
r, dbChannel, isActive, in.PeerAliasLookup,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -4066,7 +4068,6 @@ func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
|
|||||||
// *Channeldb.ChannelConfig.
|
// *Channeldb.ChannelConfig.
|
||||||
func createChannelConstraint(
|
func createChannelConstraint(
|
||||||
chanCfg *channeldb.ChannelConfig) *lnrpc.ChannelConstraints {
|
chanCfg *channeldb.ChannelConfig) *lnrpc.ChannelConstraints {
|
||||||
|
|
||||||
return &lnrpc.ChannelConstraints{
|
return &lnrpc.ChannelConstraints{
|
||||||
CsvDelay: uint32(chanCfg.CsvDelay),
|
CsvDelay: uint32(chanCfg.CsvDelay),
|
||||||
ChanReserveSat: uint64(chanCfg.ChanReserve),
|
ChanReserveSat: uint64(chanCfg.ChanReserve),
|
||||||
@@ -4088,7 +4089,7 @@ func isPrivate(dbChannel *channeldb.OpenChannel) bool {
|
|||||||
|
|
||||||
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
|
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
|
||||||
func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
||||||
isActive bool) (*lnrpc.Channel, error) {
|
isActive, peerAliasLookup bool) (*lnrpc.Channel, error) {
|
||||||
|
|
||||||
nodePub := dbChannel.IdentityPub
|
nodePub := dbChannel.IdentityPub
|
||||||
nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
|
nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
|
||||||
@@ -4164,6 +4165,16 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
|||||||
RemoteChanReserveSat: int64(dbChannel.RemoteChanCfg.ChanReserve),
|
RemoteChanReserveSat: int64(dbChannel.RemoteChanCfg.ChanReserve),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
// Populate the set of aliases.
|
||||||
for _, chanAlias := range channelAliases {
|
for _, chanAlias := range channelAliases {
|
||||||
channel.AliasScids = append(
|
channel.AliasScids = append(
|
||||||
@@ -4576,7 +4587,7 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription,
|
|||||||
}
|
}
|
||||||
case channelnotifier.OpenChannelEvent:
|
case channelnotifier.OpenChannelEvent:
|
||||||
channel, err := createRPCOpenChannel(
|
channel, err := createRPCOpenChannel(
|
||||||
r, event.Channel, true,
|
r, event.Channel, true, false,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in new issue
Block a user