contractcourt: store htlc timeout sweeps

This commit is contained in:
carla committed 2020-07-07 19:49:57 +02:00
1 parent a38dc256fd
commit d0ec872ef3
2 files changed
+97 -7

No files matched your search

+33 -3
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/davecgh/go-spew/spew"
@@ -275,6 +276,8 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
}
}
var spendTxID *chainhash.Hash
// waitForOutputResolution waits for the HTLC output to be fully
// resolved. The output is considered fully resolved once it has been
// spent, and the spending transaction has been fully confirmed.
@@ -291,10 +294,11 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
}
select {
case _, ok := <-spendNtfn.Spend:
case spendDetail, ok := <-spendNtfn.Spend:
if !ok {
return errResolverShuttingDown
}
spendTxID = spendDetail.SpenderTxHash
case <-h.quit:
return errResolverShuttingDown
@@ -333,6 +337,7 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
if !ok {
return nil, errResolverShuttingDown
}
spendTxID = spend.SpenderTxHash
case <-h.quit:
return nil, errResolverShuttingDown
@@ -365,6 +370,8 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
return nil, err
}
var reports []*channeldb.ResolverReport
// Finally, if this was an output on our commitment transaction, we'll
// wait for the second-level HTLC output to be spent, and for that
// transaction itself to confirm.
@@ -374,12 +381,35 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
if err := waitForOutputResolution(); err != nil {
return nil, err
}
// Once our timeout tx has confirmed, we add a resolution for
// our timeoutTx tx first stage transaction.
timeoutTx := h.htlcResolution.SignedTimeoutTx
spendHash := timeoutTx.TxHash()
reports = append(reports, &channeldb.ResolverReport{
OutPoint: timeoutTx.TxIn[0].PreviousOutPoint,
Amount: h.htlc.Amt.ToSatoshis(),
ResolverType: channeldb.ResolverTypeOutgoingHtlc,
ResolverOutcome: channeldb.ResolverOutcomeFirstStage,
SpendTxID: &spendHash,
})
}
// With the clean up message sent, we'll now mark the contract
// resolved, and wait.
// resolved, record the timeout and the sweep txid on disk, and wait.
h.resolved = true
return nil, h.Checkpoint(h)
amt := btcutil.Amount(h.htlcResolution.SweepSignDesc.Output.Value)
reports = append(reports, &channeldb.ResolverReport{
OutPoint: h.htlcResolution.ClaimOutpoint,
Amount: amt,
ResolverType: channeldb.ResolverTypeOutgoingHtlc,
ResolverOutcome: channeldb.ResolverOutcomeTimeout,
SpendTxID: spendTxID,
})
return nil, h.Checkpoint(h, reports...)
}
// Stop signals the resolver to cancel any current resolution processes, and