Merge pull request #4111 from carlaKC/4067-pendingchannelsrpcadditions

lnrpc: add fee and initiator to pending channels
This commit is contained in:
Carla Kirk-Cohen 2020-03-25 13:47:16 +02:00 committed by GitHub
commit f5e364071b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 862 additions and 739 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 {
@ -2025,6 +2028,24 @@ message PendingChannelsResponse {
/// Hash of the remote pending version of the commitment tx. /// Hash of the remote pending version of the commitment tx.
string remote_pending_txid = 3; string remote_pending_txid = 3;
/*
The amount in satoshis calculated to be paid in fees for the local
commitment.
*/
uint64 local_commit_fee_sat = 4;
/*
The amount in satoshis calculated to be paid in fees for the remote
commitment.
*/
uint64 remote_commit_fee_sat = 5;
/*
The amount in satoshis calculated to be paid in fees for the remote
pending commitment.
*/
uint64 remote_pending_commit_fee_sat = 6;
} }
message ClosedChannel { message ClosedChannel {
@ -2075,8 +2096,12 @@ message PendingChannelsResponse {
/// Channels pending opening /// Channels pending opening
repeated PendingOpenChannel pending_open_channels = 2; repeated PendingOpenChannel pending_open_channels = 2;
/// Channels pending closing /*
repeated ClosedChannel pending_closing_channels = 3; Deprecated: Channels pending closing previously contained cooperatively
closed channels with a single confirmation. These channels are now
considered closed from the time we see them on chain.
*/
repeated ClosedChannel pending_closing_channels = 3 [deprecated = true];
/// Channels pending force closing /// Channels pending force closing
repeated ForceClosedChannel pending_force_closing_channels = 4; repeated ForceClosedChannel pending_force_closing_channels = 4;

View File

@ -1617,6 +1617,21 @@
"remote_pending_txid": { "remote_pending_txid": {
"type": "string", "type": "string",
"description": "/ Hash of the remote pending version of the commitment tx." "description": "/ Hash of the remote pending version of the commitment tx."
},
"local_commit_fee_sat": {
"type": "string",
"format": "uint64",
"description": "The amount in satoshis calculated to be paid in fees for the local\ncommitment."
},
"remote_commit_fee_sat": {
"type": "string",
"format": "uint64",
"description": "The amount in satoshis calculated to be paid in fees for the remote\ncommitment."
},
"remote_pending_commit_fee_sat": {
"type": "string",
"format": "uint64",
"description": "The amount in satoshis calculated to be paid in fees for the remote\npending commitment."
} }
} }
}, },
@ -1692,6 +1707,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."
} }
} }
}, },
@ -3919,7 +3939,7 @@
"items": { "items": {
"$ref": "#/definitions/PendingChannelsResponseClosedChannel" "$ref": "#/definitions/PendingChannelsResponseClosedChannel"
}, },
"title": "/ Channels pending closing" "description": "Deprecated: Channels pending closing previously contained cooperatively\nclosed channels with a single confirmation. These channels are now\nconsidered closed from the time we see them on chain."
}, },
"pending_force_closing_channels": { "pending_force_closing_channels": {
"type": "array", "type": "array",

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,26 +2698,42 @@ 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 {
// If the channel was closed cooperatively, then we'll only // A coop closed channel should never be in the "pending close"
// need to tack on the closing txid. // state. If a node upgraded from an older lnd version in the
// TODO(halseth): remove. After recent changes, a coop closed // middle of a their channel confirming, it will be in this
// channel should never be in the "pending close" state. // state. We log a warning that the channel will not be included
// Keeping for now to let someone that upgraded in the middle // in the now deprecated pending close channels field.
// of a close let their closing tx confirm.
case channeldb.CooperativeClose: case channeldb.CooperativeClose:
resp.PendingClosingChannels = append( rpcsLog.Warn("channel %v cooperatively closed and "+
resp.PendingClosingChannels, "in pending close state",
&lnrpc.PendingChannelsResponse_ClosedChannel{ pendingClose.ChanPoint)
Channel: channel,
ClosingTxid: closeTXID,
},
)
resp.TotalLimboBalance += channel.LocalBalance
// If the channel was force closed, then we'll need to query // If the channel was force closed, then we'll need to query
// the utxoNursery for additional information. // the utxoNursery for additional information.
@ -2776,6 +2793,10 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
commitments.LocalTxid = commitments.LocalTxid =
waitingClose.LocalCommitment.CommitTx.TxHash(). waitingClose.LocalCommitment.CommitTx.TxHash().
String() String()
commitments.LocalCommitFeeSat = uint64(
waitingClose.LocalCommitment.CommitFee,
)
} }
// Report remote commit. May not be present when DLP is active. // Report remote commit. May not be present when DLP is active.
@ -2783,6 +2804,10 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
commitments.RemoteTxid = commitments.RemoteTxid =
waitingClose.RemoteCommitment.CommitTx.TxHash(). waitingClose.RemoteCommitment.CommitTx.TxHash().
String() String()
commitments.RemoteCommitFeeSat = uint64(
waitingClose.RemoteCommitment.CommitFee,
)
} }
// Report the remote pending commit if any. // Report the remote pending commit if any.
@ -2802,7 +2827,9 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
default: default:
hash := remoteCommitDiff.Commitment.CommitTx.TxHash() hash := remoteCommitDiff.Commitment.CommitTx.TxHash()
commitments.RemotePendingTxid = hash.String() commitments.RemotePendingTxid = hash.String()
commitments.RemoteCommitFeeSat = uint64(
remoteCommitDiff.Commitment.CommitFee,
)
} }
channel := &lnrpc.PendingChannelsResponse_PendingChannel{ channel := &lnrpc.PendingChannelsResponse_PendingChannel{
@ -2813,6 +2840,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{