Merge pull request #6167 from madskrogh/pendingchannels-private-status

lnrpc: add Private field to PendingChannelsResponse
This commit is contained in:
Oliver Gugger authored and GitHub committed 2022-01-18 10:48:00 +01:00
commit 3ff849d15b
5 files changed
+1696 -1668

No files matched your search

@@ -13,6 +13,9 @@
* Add [chan_point flag](https://github.com/lightningnetwork/lnd/pull/6152) * Add [chan_point flag](https://github.com/lightningnetwork/lnd/pull/6152)
to closechannel command. to closechannel command.
* Add [private status](https://github.com/lightningnetwork/lnd/pull/6167)
to pendingchannels response.
## Bug Fixes ## Bug Fixes
* [Fixed an inactive invoice subscription not removed from invoice * [Fixed an inactive invoice subscription not removed from invoice
+1666 -1655
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -2315,6 +2315,9 @@ message PendingChannelsResponse {
// A set of flags showing the current state of the channel. // A set of flags showing the current state of the channel.
string chan_status_flags = 11; string chan_status_flags = 11;
// Whether this channel is advertised to the network or not.
bool private = 12;
} }
message PendingOpenChannel { message PendingOpenChannel {
+4
View File
@@ -2761,6 +2761,10 @@
"chan_status_flags": { "chan_status_flags": {
"type": "string", "type": "string",
"description": "A set of flags showing the current state of the channel." "description": "A set of flags showing the current state of the channel."
},
"private": {
"type": "boolean",
"description": "Whether this channel is advertised to the network or not."
} }
} }
}, },
+20 -13
View File
@@ -3236,6 +3236,7 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) {
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve), RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
Initiator: rpcInitiator(pendingChan.IsInitiator), Initiator: rpcInitiator(pendingChan.IsInitiator),
CommitmentType: rpcCommitmentType(pendingChan.ChanType), CommitmentType: rpcCommitmentType(pendingChan.ChanType),
Private: isPrivate(pendingChan),
}, },
CommitWeight: commitWeight, CommitWeight: commitWeight,
CommitFee: int64(localCommitment.CommitFee), CommitFee: int64(localCommitment.CommitFee),
@@ -3323,6 +3324,8 @@ func (r *rpcServer) fetchPendingForceCloseChannels() (pendingForceClose,
historical.LocalCommitment.RemoteBalance.ToSatoshis(), historical.LocalCommitment.RemoteBalance.ToSatoshis(),
) )
channel.Private = isPrivate(historical)
// If the error is non-nil, and not due to older versions of lnd // If the error is non-nil, and not due to older versions of lnd
// not persisting historical channels, return it. // not persisting historical channels, return it.
default: default:
@@ -3518,6 +3521,7 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
CommitmentType: rpcCommitmentType(waitingClose.ChanType), CommitmentType: rpcCommitmentType(waitingClose.ChanType),
NumForwardingPackages: int64(len(fwdPkgs)), NumForwardingPackages: int64(len(fwdPkgs)),
ChanStatusFlags: waitingClose.ChanStatus().String(), ChanStatusFlags: waitingClose.ChanStatus().String(),
Private: isPrivate(waitingClose),
} }
waitingCloseResp := &lnrpc.PendingChannelsResponse_WaitingCloseChannel{ waitingCloseResp := &lnrpc.PendingChannelsResponse_WaitingCloseChannel{
@@ -3804,8 +3808,6 @@ func (r *rpcServer) ListChannels(ctx context.Context,
resp := &lnrpc.ListChannelsResponse{} resp := &lnrpc.ListChannelsResponse{}
graph := r.server.graphDB
dbChannels, err := r.server.chanStateDB.FetchAllOpenChannels() dbChannels, err := r.server.chanStateDB.FetchAllOpenChannels()
if err != nil { if err != nil {
return nil, err return nil, err
@@ -3842,7 +3844,7 @@ 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, graph, dbChannel, isActive) channel, err := createRPCOpenChannel(r, dbChannel, isActive)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -3902,17 +3904,23 @@ func createChannelConstraint(
} }
} }
// isPrivate evaluates the ChannelFlags of the db channel to determine if the
// channel is private or not.
func isPrivate(dbChannel *channeldb.OpenChannel) bool {
if dbChannel == nil {
return false
}
return dbChannel.ChannelFlags&lnwire.FFAnnounceChannel != 1
}
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel. // createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph, func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
dbChannel *channeldb.OpenChannel, isActive bool) (*lnrpc.Channel, error) { isActive bool) (*lnrpc.Channel, error) {
nodePub := dbChannel.IdentityPub nodePub := dbChannel.IdentityPub
nodeID := hex.EncodeToString(nodePub.SerializeCompressed()) nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
chanPoint := dbChannel.FundingOutpoint chanPoint := dbChannel.FundingOutpoint
// Next, we'll determine whether the channel is public or not.
isPublic := dbChannel.ChannelFlags&lnwire.FFAnnounceChannel != 0
// As this is required for display purposes, we'll calculate // As this is required for display purposes, we'll calculate
// the weight of the commitment transaction. We also add on the // the weight of the commitment transaction. We also add on the
// estimated weight of the witness to calculate the weight of // estimated weight of the witness to calculate the weight of
@@ -3944,7 +3952,7 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
channel := &lnrpc.Channel{ channel := &lnrpc.Channel{
Active: isActive, Active: isActive,
Private: !isPublic, Private: isPrivate(dbChannel),
RemotePubkey: nodeID, RemotePubkey: nodeID,
ChannelPoint: chanPoint.String(), ChannelPoint: chanPoint.String(),
ChanId: dbChannel.ShortChannelID.ToUint64(), ChanId: dbChannel.ShortChannelID.ToUint64(),
@@ -4330,8 +4338,6 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription,
// the server, or client exits. // the server, or client exits.
defer channelEventSub.Cancel() defer channelEventSub.Cancel()
graph := r.server.graphDB
for { for {
select { select {
// A new update has been sent by the channel router, we'll // A new update has been sent by the channel router, we'll
@@ -4351,8 +4357,9 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription,
}, },
} }
case channelnotifier.OpenChannelEvent: case channelnotifier.OpenChannelEvent:
channel, err := createRPCOpenChannel(r, graph, channel, err := createRPCOpenChannel(
event.Channel, true) r, event.Channel, true,
)
if err != nil { if err != nil {
return err return err
} }