lnrpc: add initiator bool to PendingChannel message

This commit is contained in:
carla
2020-03-25 08:40:44 +02:00
parent 4bc7524410
commit fd6b397496
4 changed files with 757 additions and 714 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1973,6 +1973,9 @@ message PendingChannelsResponse {
balance. balance.
*/ */
int64 remote_chan_reserve_sat = 7; int64 remote_chan_reserve_sat = 7;
// True if we initiated opening the channel.
bool initiator = 8;
} }
message PendingOpenChannel { message PendingOpenChannel {

View File

@@ -1692,6 +1692,11 @@
"type": "string", "type": "string",
"format": "int64", "format": "int64",
"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": {
"type": "boolean",
"format": "boolean",
"description": "True if we initiated opening the channel."
} }
} }
}, },

View File

@@ -2665,6 +2665,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,
}, },
CommitWeight: commitWeight, CommitWeight: commitWeight,
CommitFee: int64(localCommitment.CommitFee), CommitFee: int64(localCommitment.CommitFee),
@@ -2697,6 +2698,29 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
LocalBalance: int64(pendingClose.SettledBalance), LocalBalance: int64(pendingClose.SettledBalance),
} }
// Lookup the channel in the historical channel bucket to obtain
// initiator information. If the historical channel bucket was
// not found, or the channel itself, this channel was closed
// in a version before we started persisting historical
// channels, so we silence the error.
historical, err := r.server.chanDB.FetchHistoricalChannel(
&pendingClose.ChanPoint,
)
switch err {
// If the channel was closed in a version that did not record
// historical channels, ignore the error.
case channeldb.ErrNoHistoricalBucket:
case channeldb.ErrChannelNotFound:
case nil:
channel.Initiator = historical.IsInitiator
// If the error is non-nil, and not due to older versions of lnd
// not persisting historical channels, return it.
default:
return nil, err
}
closeTXID := pendingClose.ClosingTXID.String() closeTXID := pendingClose.ClosingTXID.String()
switch pendingClose.CloseType { switch pendingClose.CloseType {
@@ -2813,6 +2837,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,
} }
waitingCloseResp := &lnrpc.PendingChannelsResponse_WaitingCloseChannel{ waitingCloseResp := &lnrpc.PendingChannelsResponse_WaitingCloseChannel{