mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
contractcourt: register conf notification before publish tx
This commit moves the confirmation registration before publishing the tx to make sure the conf event won't be missed.
This commit is contained in:
parent
a1671a8674
commit
92671ad250
1 changed files with 18 additions and 16 deletions
|
@ -417,20 +417,8 @@ func (h *htlcSuccessResolver) resolveRemoteCommitOutput() (
|
|||
// with the published one.
|
||||
}
|
||||
|
||||
// Regardless of whether an existing transaction was found or newly
|
||||
// constructed, we'll broadcast the sweep transaction to the network.
|
||||
label := labels.MakeLabel(
|
||||
labels.LabelTypeChannelClose, &h.ShortChanID,
|
||||
)
|
||||
err := h.PublishTx(h.sweepTx, label)
|
||||
if err != nil {
|
||||
log.Infof("%T(%x): unable to publish tx: %v",
|
||||
h, h.htlc.RHash[:], err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// With the sweep transaction broadcast, we'll wait for its
|
||||
// confirmation.
|
||||
// Register the confirmation notification before broadcasting the sweep
|
||||
// transaction.
|
||||
sweepTXID := h.sweepTx.TxHash()
|
||||
sweepScript := h.sweepTx.TxOut[0].PkScript
|
||||
confNtfn, err := h.Notifier.RegisterConfirmationsNtfn(
|
||||
|
@ -440,8 +428,22 @@ func (h *htlcSuccessResolver) resolveRemoteCommitOutput() (
|
|||
return nil, err
|
||||
}
|
||||
|
||||
log.Infof("%T(%x): waiting for sweep tx (txid=%v) to be "+
|
||||
"confirmed", h, h.htlc.RHash[:], sweepTXID)
|
||||
// Regardless of whether an existing transaction was found or newly
|
||||
// constructed, we'll broadcast the sweep transaction to the network.
|
||||
label := labels.MakeLabel(
|
||||
labels.LabelTypeChannelClose, &h.ShortChanID,
|
||||
)
|
||||
err = h.PublishTx(h.sweepTx, label)
|
||||
if err != nil {
|
||||
log.Infof("%T(%x): unable to publish tx: %v",
|
||||
h, h.htlc.RHash[:], err)
|
||||
confNtfn.Cancel()
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Infof("%T(%x): waiting for sweep tx (txid=%v) to be confirmed", h,
|
||||
h.htlc.RHash[:], sweepTXID)
|
||||
|
||||
select {
|
||||
case _, ok := <-confNtfn.Confirmed:
|
||||
|
|
Loading…
Add table
Reference in a new issue