Skip to content

staticaddr: monitor tx id of expiry sweep #996

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions staticaddr/deposit/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop/fsm"
Expand Down Expand Up @@ -103,20 +104,27 @@ func (f *FSM) PublishDepositExpirySweepAction(ctx context.Context,
return fsm.OnError
}
} else {
f.Debugf("published timeout sweep with txid: %v",
msgTx.TxHash())
txHash := msgTx.TxHash()
f.deposit.ExpirySweepTxid = txHash
f.Debugf("published timeout sweep with txid: %v", txHash)
}

return OnExpiryPublished
}

// WaitForExpirySweepAction waits for a sufficient number of confirmations
// before a timeout sweep is considered successful.
// WaitForExpirySweepAction waits for enough confirmations before a timeout
// sweep is considered successful.
func (f *FSM) WaitForExpirySweepAction(ctx context.Context,
_ fsm.EventContext) fsm.EventType {

var txID *chainhash.Hash
// Only pass the txid if we know it from our own publication.
if f.deposit.ExpirySweepTxid != (chainhash.Hash{}) {
txID = &f.deposit.ExpirySweepTxid
}

spendChan, errSpendChan, err := f.cfg.ChainNotifier.RegisterConfirmationsNtfn( //nolint:lll
ctx, nil, f.deposit.TimeOutSweepPkScript, DefaultConfTarget,
ctx, txID, f.deposit.TimeOutSweepPkScript, DefaultConfTarget,
int32(f.deposit.ConfirmationHeight),
)
if err != nil {
Expand Down