Merge pull request #4129 from joostjager/pending-close-type

lnrpc: expose commitment type on pending open and waiting close channels
This commit is contained in:
Joost Jager 2020-03-31 21:40:24 +02:00 committed by GitHub
commit 7ba5bf69e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 809 additions and 764 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1314,6 +1314,11 @@ enum CommitmentType {
been broadcast.
*/
ANCHORS = 2;
/**
Returned when the commitment type isn't known or unavailable.
*/
UNKNOWN_COMMITMENT_TYPE = 999;
}
message Channel {
@ -2087,6 +2092,9 @@ message PendingChannelsResponse {
// True if we initiated opening the channel.
bool initiator = 8;
/// The commitment type used by this channel.
CommitmentType commitment_type = 9;
}
message PendingOpenChannel {

View File

@ -1746,6 +1746,10 @@
"type": "boolean",
"format": "boolean",
"description": "True if we initiated opening the channel."
},
"commitment_type": {
"$ref": "#/definitions/lnrpcCommitmentType",
"description": "/ The commitment type used by this channel."
}
}
},
@ -2523,10 +2527,11 @@
"enum": [
"LEGACY",
"STATIC_REMOTE_KEY",
"ANCHORS"
"ANCHORS",
"UNKNOWN_COMMITMENT_TYPE"
],
"default": "LEGACY",
"description": " - LEGACY: *\nA channel using the legacy commitment format having tweaked to_remote\nkeys.\n - STATIC_REMOTE_KEY: *\nA channel that uses the modern commitment format where the key in the\noutput of the remote party does not change each state. This makes back\nup and recovery easier as when the channel is closed, the funds go\ndirectly to that key.\n - ANCHORS: *\nA channel that uses a commitment format that has anchor outputs on the\ncommitments, allowing fee bumping after a force close transaction has\nbeen broadcast."
"description": " - LEGACY: *\nA channel using the legacy commitment format having tweaked to_remote\nkeys.\n - STATIC_REMOTE_KEY: *\nA channel that uses the modern commitment format where the key in the\noutput of the remote party does not change each state. This makes back\nup and recovery easier as when the channel is closed, the funds go\ndirectly to that key.\n - ANCHORS: *\nA channel that uses a commitment format that has anchor outputs on the\ncommitments, allowing fee bumping after a force close transaction has\nbeen broadcast.\n - UNKNOWN_COMMITMENT_TYPE: *\nReturned when the commitment type isn't known or unavailable."
},
"lnrpcConnectPeerRequest": {
"type": "object",

View File

@ -2738,6 +2738,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
LocalChanReserveSat: int64(pendingChan.LocalChanCfg.ChanReserve),
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
Initiator: pendingChan.IsInitiator,
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
},
CommitWeight: commitWeight,
CommitFee: int64(localCommitment.CommitFee),
@ -2764,10 +2765,11 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
pub := pendingClose.RemotePub.SerializeCompressed()
chanPoint := pendingClose.ChanPoint
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
RemoteNodePub: hex.EncodeToString(pub),
ChannelPoint: chanPoint.String(),
Capacity: int64(pendingClose.Capacity),
LocalBalance: int64(pendingClose.SettledBalance),
RemoteNodePub: hex.EncodeToString(pub),
ChannelPoint: chanPoint.String(),
Capacity: int64(pendingClose.Capacity),
LocalBalance: int64(pendingClose.SettledBalance),
CommitmentType: lnrpc.CommitmentType_UNKNOWN_COMMITMENT_TYPE,
}
// Lookup the channel in the historical channel bucket to obtain
@ -2786,6 +2788,9 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
case nil:
channel.Initiator = historical.IsInitiator
channel.CommitmentType = rpcCommitmentType(
historical.ChanType,
)
// If the error is non-nil, and not due to older versions of lnd
// not persisting historical channels, return it.
@ -2913,6 +2918,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
LocalChanReserveSat: int64(waitingClose.LocalChanCfg.ChanReserve),
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
Initiator: waitingClose.IsInitiator,
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
}
waitingCloseResp := &lnrpc.PendingChannelsResponse_WaitingCloseChannel{
@ -3220,6 +3226,23 @@ func (r *rpcServer) ListChannels(ctx context.Context,
return resp, nil
}
// rpcCommitmentType takes the channel type and converts it to an rpc commitment
// type value.
func rpcCommitmentType(chanType channeldb.ChannelType) lnrpc.CommitmentType {
// Extract the commitment type from the channel type flags. We must
// first check whether it has anchors, since in that case it would also
// be tweakless.
if chanType.HasAnchors() {
return lnrpc.CommitmentType_ANCHORS
}
if chanType.IsTweakless() {
return lnrpc.CommitmentType_STATIC_REMOTE_KEY
}
return lnrpc.CommitmentType_LEGACY
}
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
dbChannel *channeldb.OpenChannel, isActive bool) (*lnrpc.Channel, error) {
@ -3257,15 +3280,8 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
}
externalCommitFee := dbChannel.Capacity - sumOutputs
// Extract the commitment type from the channel type flags. We must
// first check whether it has anchors, since in that case it would also
// be tweakless.
commitmentType := lnrpc.CommitmentType_LEGACY
if dbChannel.ChanType.HasAnchors() {
commitmentType = lnrpc.CommitmentType_ANCHORS
} else if dbChannel.ChanType.IsTweakless() {
commitmentType = lnrpc.CommitmentType_STATIC_REMOTE_KEY
}
// Extract the commitment type from the channel type flags.
commitmentType := rpcCommitmentType(dbChannel.ChanType)
channel := &lnrpc.Channel{
Active: isActive,