rpcserver: add closing txid in WaitingCloseChannel
This commit is contained in:
4 files changed
+1698
-1629
No files matched your search
+1640
-1629
File diff suppressed because it is too large.
Load diff
@@ -2356,6 +2356,9 @@ message PendingChannelsResponse {
|
|||||||
this point.
|
this point.
|
||||||
*/
|
*/
|
||||||
Commitments commitments = 3;
|
Commitments commitments = 3;
|
||||||
|
|
||||||
|
// The transaction id of the closing transaction
|
||||||
|
string closing_txid = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Commitments {
|
message Commitments {
|
||||||
|
|||||||
@@ -2808,6 +2808,10 @@
|
|||||||
"commitments": {
|
"commitments": {
|
||||||
"$ref": "#/definitions/PendingChannelsResponseCommitments",
|
"$ref": "#/definitions/PendingChannelsResponseCommitments",
|
||||||
"description": "A list of valid commitment transactions. Any of these can confirm at\nthis point."
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3398,6 +3398,45 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
|
|||||||
result := make(waitingCloseChannels, 0)
|
result := make(waitingCloseChannels, 0)
|
||||||
limboBalance := int64(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 {
|
for _, waitingClose := range channels {
|
||||||
pub := waitingClose.IdentityPub.SerializeCompressed()
|
pub := waitingClose.IdentityPub.SerializeCompressed()
|
||||||
chanPoint := waitingClose.FundingOutpoint
|
chanPoint := waitingClose.FundingOutpoint
|
||||||
@@ -3456,6 +3495,17 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
|
|||||||
return nil, 0, err
|
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{
|
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
|
||||||
RemoteNodePub: hex.EncodeToString(pub),
|
RemoteNodePub: hex.EncodeToString(pub),
|
||||||
ChannelPoint: chanPoint.String(),
|
ChannelPoint: chanPoint.String(),
|
||||||
@@ -3474,6 +3524,7 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
|
|||||||
Channel: channel,
|
Channel: channel,
|
||||||
LimboBalance: channel.LocalBalance,
|
LimboBalance: channel.LocalBalance,
|
||||||
Commitments: &commitments,
|
Commitments: &commitments,
|
||||||
|
ClosingTxid: closingTxid,
|
||||||
}
|
}
|
||||||
|
|
||||||
// A close tx has been broadcasted, all our balance will be in
|
// A close tx has been broadcasted, all our balance will be in
|
||||||
|
|||||||
Reference in new issue
Block a user