rpcserver: add closing txid in WaitingCloseChannel

This commit is contained in:
yyforyongyu 2022-01-07 17:27:22 +08:00
parent 3c1c640612
commit 99378b22c3
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
4 changed files with 1698 additions and 1629 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2356,6 +2356,9 @@ message PendingChannelsResponse {
this point.
*/
Commitments commitments = 3;
// The transaction id of the closing transaction
string closing_txid = 4;
}
message Commitments {

View File

@ -2808,6 +2808,10 @@
"commitments": {
"$ref": "#/definitions/PendingChannelsResponseCommitments",
"description": "A list of valid commitment transactions. Any of these can confirm at\nthis point."
},
"closing_txid": {
"type": "string",
"title": "The transaction id of the closing transaction"
}
}
},

View File

@ -3398,6 +3398,45 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
result := make(waitingCloseChannels, 0)
limboBalance := int64(0)
// getClosingTx is a helper closure that tries to find the closing txid
// of a given waiting close channel. Notice that if the remote closes
// the channel, we may not have the closing txid.
getClosingTx := func(c *channeldb.OpenChannel) (string, error) {
var (
tx *wire.MsgTx
err error
)
// First, we try to locate the force closing txid. If not
// found, we will then try to find its coop closing txid.
tx, err = c.BroadcastedCommitment()
if err == nil {
return tx.TxHash().String(), nil
}
// If the error returned is not ErrNoCloseTx, something
// unexpected happened and we will return the error.
if err != channeldb.ErrNoCloseTx {
return "", err
}
// Otherwise, we continue to locate its coop closing txid.
tx, err = c.BroadcastedCooperative()
if err == nil {
return tx.TxHash().String(), nil
}
// Return the error if it's not ErrNoCloseTx.
if err != channeldb.ErrNoCloseTx {
return "", err
}
// Otherwise return an empty txid. This can happen if the
// remote broadcast the closing txid and we haven't recorded it
// yet.
return "", nil
}
for _, waitingClose := range channels {
pub := waitingClose.IdentityPub.SerializeCompressed()
chanPoint := waitingClose.FundingOutpoint
@ -3456,6 +3495,17 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
return nil, 0, err
}
// Get the closing txid.
// NOTE: the closing txid could be empty here if it's the
// remote broadcasted the closing tx.
closingTxid, err := getClosingTx(waitingClose)
if err != nil {
rpcsLog.Errorf("unable to find closing txid for "+
"channel:%s, %v",
waitingClose.ShortChannelID, err)
return nil, 0, err
}
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
RemoteNodePub: hex.EncodeToString(pub),
ChannelPoint: chanPoint.String(),
@ -3474,6 +3524,7 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
Channel: channel,
LimboBalance: channel.LocalBalance,
Commitments: &commitments,
ClosingTxid: closingTxid,
}
// A close tx has been broadcasted, all our balance will be in