lnrpc: use initiator enum for pending channel channel intiator

Update the PendingChannel message from a bool to an enum to
differentiate between the case where the remote party initiated the
channel and we have no record of the channel initiator. The previous
field has not been included in a release of lnd, so we can replace the
field directly.
This commit is contained in:
carla 2020-04-03 09:13:53 +02:00
parent 2ae61162db
commit d66ff04583
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
4 changed files with 768 additions and 753 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2093,8 +2093,8 @@ message PendingChannelsResponse {
*/
int64 remote_chan_reserve_sat = 7;
// True if we initiated opening the channel.
bool initiator = 8;
// The party that initiated opening the channel.
Initiator initiator = 8;
/// The commitment type used by this channel.
CommitmentType commitment_type = 9;

View File

@ -1733,9 +1733,8 @@
"description": "*\nThe minimum satoshis the other node is required to reserve in its\nbalance."
},
"initiator": {
"type": "boolean",
"format": "boolean",
"description": "True if we initiated opening the channel."
"$ref": "#/definitions/lnrpcInitiator",
"description": "The party that initiated opening the channel."
},
"commitment_type": {
"$ref": "#/definitions/lnrpcCommitmentType",

View File

@ -2664,6 +2664,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
resp := &lnrpc.PendingChannelsResponse{}
// rpcInitiator returns the correct lnrpc initiator for channels where
// we have a record of the opening channel.
rpcInitiator := func(isInitiator bool) lnrpc.Initiator {
if isInitiator {
return lnrpc.Initiator_INITIATOR_LOCAL
}
return lnrpc.Initiator_INITIATOR_REMOTE
}
// First, we'll populate the response with all the channels that are
// soon to be opened. We can easily fetch this data from the database
// and map the db struct to the proto response.
@ -2698,7 +2708,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
RemoteBalance: int64(localCommitment.RemoteBalance.ToSatoshis()),
LocalChanReserveSat: int64(pendingChan.LocalChanCfg.ChanReserve),
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
Initiator: pendingChan.IsInitiator,
Initiator: rpcInitiator(pendingChan.IsInitiator),
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
},
CommitWeight: commitWeight,
@ -2725,12 +2735,18 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
// needed regardless of how this channel was closed.
pub := pendingClose.RemotePub.SerializeCompressed()
chanPoint := pendingClose.ChanPoint
// Create the pending channel. If this channel was closed before
// we started storing historical channel data, we will not know
// who initiated the channel, so we set the initiator field to
// unknown.
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
RemoteNodePub: hex.EncodeToString(pub),
ChannelPoint: chanPoint.String(),
Capacity: int64(pendingClose.Capacity),
LocalBalance: int64(pendingClose.SettledBalance),
CommitmentType: lnrpc.CommitmentType_UNKNOWN_COMMITMENT_TYPE,
Initiator: lnrpc.Initiator_INITIATOR_UNKNOWN,
}
// Lookup the channel in the historical channel bucket to obtain
@ -2748,7 +2764,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
case channeldb.ErrChannelNotFound:
case nil:
channel.Initiator = historical.IsInitiator
channel.Initiator = rpcInitiator(historical.IsInitiator)
channel.CommitmentType = rpcCommitmentType(
historical.ChanType,
)
@ -2878,7 +2894,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
RemoteBalance: int64(waitingClose.LocalCommitment.RemoteBalance.ToSatoshis()),
LocalChanReserveSat: int64(waitingClose.LocalChanCfg.ChanReserve),
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
Initiator: waitingClose.IsInitiator,
Initiator: rpcInitiator(waitingClose.IsInitiator),
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
}