mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
Merge pull request #7322 from hieblmi/cmd-listchannels-peer-alias
lncli: remote peer alias in `listchannels`
This commit is contained in:
commit
d321182220
9 changed files with 2454 additions and 2344 deletions
|
@ -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),
|
||||
}
|
||||
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
|
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.
|
||||
uint64 zero_conf_confirmed_scid = 33;
|
||||
|
||||
// The configured alias name of our peer.
|
||||
string peer_alias = 34;
|
||||
}
|
||||
|
||||
message ListChannelsRequest {
|
||||
|
@ -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
|
||||
|
|
|
@ -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": [
|
||||
|
@ -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."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
|
19
rpcserver.go
19
rpcserver.go
|
@ -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,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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())
|
||||
|
@ -4164,6 +4165,16 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
|||
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.
|
||||
for _, chanAlias := range channelAliases {
|
||||
channel.AliasScids = append(
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue