Merge pull request #3758 from joostjager/anchor-output-poc-joost
cnct: anchor output sweeping and fee bumping
This commit is contained in:
27 files changed
+2448
-978
No files matched your search
+66
-6
@@ -2757,6 +2757,43 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
||||
for _, waitingClose := range waitingCloseChans {
|
||||
pub := waitingClose.IdentityPub.SerializeCompressed()
|
||||
chanPoint := waitingClose.FundingOutpoint
|
||||
|
||||
var commitments lnrpc.PendingChannelsResponse_Commitments
|
||||
|
||||
// Report local commit. May not be present when DLP is active.
|
||||
if waitingClose.LocalCommitment.CommitTx != nil {
|
||||
commitments.LocalTxid =
|
||||
waitingClose.LocalCommitment.CommitTx.TxHash().
|
||||
String()
|
||||
}
|
||||
|
||||
// Report remote commit. May not be present when DLP is active.
|
||||
if waitingClose.RemoteCommitment.CommitTx != nil {
|
||||
commitments.RemoteTxid =
|
||||
waitingClose.RemoteCommitment.CommitTx.TxHash().
|
||||
String()
|
||||
}
|
||||
|
||||
// Report the remote pending commit if any.
|
||||
remoteCommitDiff, err := waitingClose.RemoteCommitChainTip()
|
||||
|
||||
switch {
|
||||
|
||||
// Don't set hash if there is no pending remote commit.
|
||||
case err == channeldb.ErrNoPendingCommit:
|
||||
|
||||
// An unexpected error occurred.
|
||||
case err != nil:
|
||||
return nil, err
|
||||
|
||||
// There is a pending remote commit. Set its hash in the
|
||||
// response.
|
||||
default:
|
||||
hash := remoteCommitDiff.Commitment.CommitTx.TxHash()
|
||||
commitments.RemotePendingTxid = hash.String()
|
||||
|
||||
}
|
||||
|
||||
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
|
||||
RemoteNodePub: hex.EncodeToString(pub),
|
||||
ChannelPoint: chanPoint.String(),
|
||||
@@ -2767,14 +2804,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
||||
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
|
||||
}
|
||||
|
||||
waitingCloseResp := &lnrpc.PendingChannelsResponse_WaitingCloseChannel{
|
||||
Channel: channel,
|
||||
LimboBalance: channel.LocalBalance,
|
||||
Commitments: &commitments,
|
||||
}
|
||||
|
||||
// A close tx has been broadcasted, all our balance will be in
|
||||
// limbo until it confirms.
|
||||
resp.WaitingCloseChannels = append(
|
||||
resp.WaitingCloseChannels,
|
||||
&lnrpc.PendingChannelsResponse_WaitingCloseChannel{
|
||||
Channel: channel,
|
||||
LimboBalance: channel.LocalBalance,
|
||||
},
|
||||
resp.WaitingCloseChannels, waitingCloseResp,
|
||||
)
|
||||
|
||||
resp.TotalLimboBalance += channel.LocalBalance
|
||||
@@ -2818,6 +2857,12 @@ func (r *rpcServer) arbitratorPopulateForceCloseResp(chanPoint *wire.OutPoint,
|
||||
case contractcourt.ReportOutputIncomingHtlc,
|
||||
contractcourt.ReportOutputOutgoingHtlc:
|
||||
|
||||
// Don't report details on htlcs that are no longer in
|
||||
// limbo.
|
||||
if report.LimboBalance == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
incoming := report.Type == contractcourt.ReportOutputIncomingHtlc
|
||||
htlc := &lnrpc.PendingHTLC{
|
||||
Incoming: incoming,
|
||||
@@ -2834,6 +2879,22 @@ func (r *rpcServer) arbitratorPopulateForceCloseResp(chanPoint *wire.OutPoint,
|
||||
|
||||
forceClose.PendingHtlcs = append(forceClose.PendingHtlcs, htlc)
|
||||
|
||||
case contractcourt.ReportOutputAnchor:
|
||||
// There are three resolution states for the anchor:
|
||||
// limbo, lost and recovered. Derive the current state
|
||||
// from the limbo and recovered balances.
|
||||
switch {
|
||||
|
||||
case report.RecoveredBalance != 0:
|
||||
forceClose.Anchor = lnrpc.PendingChannelsResponse_ForceClosedChannel_RECOVERED
|
||||
|
||||
case report.LimboBalance != 0:
|
||||
forceClose.Anchor = lnrpc.PendingChannelsResponse_ForceClosedChannel_LIMBO
|
||||
|
||||
default:
|
||||
forceClose.Anchor = lnrpc.PendingChannelsResponse_ForceClosedChannel_LOST
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown report output type: %v",
|
||||
report.Type)
|
||||
@@ -2841,7 +2902,6 @@ func (r *rpcServer) arbitratorPopulateForceCloseResp(chanPoint *wire.OutPoint,
|
||||
|
||||
forceClose.LimboBalance += int64(report.LimboBalance)
|
||||
forceClose.RecoveredBalance += int64(report.RecoveredBalance)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user