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:
4 files changed
+768
-753
No files matched your search
+745
-745
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -2093,8 +2093,8 @@ message PendingChannelsResponse {
|
|||||||
*/
|
*/
|
||||||
int64 remote_chan_reserve_sat = 7;
|
int64 remote_chan_reserve_sat = 7;
|
||||||
|
|
||||||
// True if we initiated opening the channel.
|
// The party that initiated opening the channel.
|
||||||
bool initiator = 8;
|
Initiator initiator = 8;
|
||||||
|
|
||||||
/// The commitment type used by this channel.
|
/// The commitment type used by this channel.
|
||||||
CommitmentType commitment_type = 9;
|
CommitmentType commitment_type = 9;
|
||||||
|
|||||||
@@ -1733,9 +1733,8 @@
|
|||||||
"description": "*\nThe minimum satoshis the other node is required to reserve in its\nbalance."
|
"description": "*\nThe minimum satoshis the other node is required to reserve in its\nbalance."
|
||||||
},
|
},
|
||||||
"initiator": {
|
"initiator": {
|
||||||
"type": "boolean",
|
"$ref": "#/definitions/lnrpcInitiator",
|
||||||
"format": "boolean",
|
"description": "The party that initiated opening the channel."
|
||||||
"description": "True if we initiated opening the channel."
|
|
||||||
},
|
},
|
||||||
"commitment_type": {
|
"commitment_type": {
|
||||||
"$ref": "#/definitions/lnrpcCommitmentType",
|
"$ref": "#/definitions/lnrpcCommitmentType",
|
||||||
|
|||||||
+19
-3
@@ -2664,6 +2664,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
|
|
||||||
resp := &lnrpc.PendingChannelsResponse{}
|
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
|
// 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
|
// soon to be opened. We can easily fetch this data from the database
|
||||||
// and map the db struct to the proto response.
|
// 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()),
|
RemoteBalance: int64(localCommitment.RemoteBalance.ToSatoshis()),
|
||||||
LocalChanReserveSat: int64(pendingChan.LocalChanCfg.ChanReserve),
|
LocalChanReserveSat: int64(pendingChan.LocalChanCfg.ChanReserve),
|
||||||
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
|
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
|
||||||
Initiator: pendingChan.IsInitiator,
|
Initiator: rpcInitiator(pendingChan.IsInitiator),
|
||||||
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
|
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
|
||||||
},
|
},
|
||||||
CommitWeight: commitWeight,
|
CommitWeight: commitWeight,
|
||||||
@@ -2725,12 +2735,18 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
// needed regardless of how this channel was closed.
|
// needed regardless of how this channel was closed.
|
||||||
pub := pendingClose.RemotePub.SerializeCompressed()
|
pub := pendingClose.RemotePub.SerializeCompressed()
|
||||||
chanPoint := pendingClose.ChanPoint
|
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{
|
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
|
||||||
RemoteNodePub: hex.EncodeToString(pub),
|
RemoteNodePub: hex.EncodeToString(pub),
|
||||||
ChannelPoint: chanPoint.String(),
|
ChannelPoint: chanPoint.String(),
|
||||||
Capacity: int64(pendingClose.Capacity),
|
Capacity: int64(pendingClose.Capacity),
|
||||||
LocalBalance: int64(pendingClose.SettledBalance),
|
LocalBalance: int64(pendingClose.SettledBalance),
|
||||||
CommitmentType: lnrpc.CommitmentType_UNKNOWN_COMMITMENT_TYPE,
|
CommitmentType: lnrpc.CommitmentType_UNKNOWN_COMMITMENT_TYPE,
|
||||||
|
Initiator: lnrpc.Initiator_INITIATOR_UNKNOWN,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup the channel in the historical channel bucket to obtain
|
// 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 channeldb.ErrChannelNotFound:
|
||||||
|
|
||||||
case nil:
|
case nil:
|
||||||
channel.Initiator = historical.IsInitiator
|
channel.Initiator = rpcInitiator(historical.IsInitiator)
|
||||||
channel.CommitmentType = rpcCommitmentType(
|
channel.CommitmentType = rpcCommitmentType(
|
||||||
historical.ChanType,
|
historical.ChanType,
|
||||||
)
|
)
|
||||||
@@ -2878,7 +2894,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
RemoteBalance: int64(waitingClose.LocalCommitment.RemoteBalance.ToSatoshis()),
|
RemoteBalance: int64(waitingClose.LocalCommitment.RemoteBalance.ToSatoshis()),
|
||||||
LocalChanReserveSat: int64(waitingClose.LocalChanCfg.ChanReserve),
|
LocalChanReserveSat: int64(waitingClose.LocalChanCfg.ChanReserve),
|
||||||
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
|
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
|
||||||
Initiator: waitingClose.IsInitiator,
|
Initiator: rpcInitiator(waitingClose.IsInitiator),
|
||||||
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
|
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user