lnd+lnrpc: add private status to pendingchannels response

This commit is contained in:
mads krogh 2022-01-16 22:10:14 +01:00
parent 42cebcfe2b
commit 1e3c05399c
4 changed files with 1687 additions and 1659 deletions

File diff suppressed because it is too large Load diff

View file

@ -2315,6 +2315,9 @@ message PendingChannelsResponse {
// A set of flags showing the current state of the channel.
string chan_status_flags = 11;
// Whether this channel is advertised to the network or not.
bool private = 12;
}
message PendingOpenChannel {

View file

@ -2761,6 +2761,10 @@
"chan_status_flags": {
"type": "string",
"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."
}
}
},

View file

@ -3236,6 +3236,7 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) {
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
Initiator: rpcInitiator(pendingChan.IsInitiator),
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
Private: isPrivate(pendingChan),
},
CommitWeight: commitWeight,
CommitFee: int64(localCommitment.CommitFee),
@ -3323,6 +3324,8 @@ func (r *rpcServer) fetchPendingForceCloseChannels() (pendingForceClose,
historical.LocalCommitment.RemoteBalance.ToSatoshis(),
)
channel.Private = isPrivate(historical)
// If the error is non-nil, and not due to older versions of lnd
// not persisting historical channels, return it.
default:
@ -3518,6 +3521,7 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
NumForwardingPackages: int64(len(fwdPkgs)),
ChanStatusFlags: waitingClose.ChanStatus().String(),
Private: isPrivate(waitingClose),
}
waitingCloseResp := &lnrpc.PendingChannelsResponse_WaitingCloseChannel{
@ -3900,6 +3904,15 @@ 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.
func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
isActive bool) (*lnrpc.Channel, error) {
@ -3908,9 +3921,6 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
nodeID := hex.EncodeToString(nodePub.SerializeCompressed())
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
// the weight of the commitment transaction. We also add on the
// estimated weight of the witness to calculate the weight of
@ -3942,7 +3952,7 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
channel := &lnrpc.Channel{
Active: isActive,
Private: !isPublic,
Private: isPrivate(dbChannel),
RemotePubkey: nodeID,
ChannelPoint: chanPoint.String(),
ChanId: dbChannel.ShortChannelID.ToUint64(),