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:
1 file changed
+18
-16
@@ -417,20 +417,8 @@ func (h *htlcSuccessResolver) resolveRemoteCommitOutput() (
|
|||||||
// with the published one.
|
// with the published one.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regardless of whether an existing transaction was found or newly
|
// Register the confirmation notification before broadcasting the sweep
|
||||||
// constructed, we'll broadcast the sweep transaction to the network.
|
// transaction.
|
||||||
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.
|
|
||||||
sweepTXID := h.sweepTx.TxHash()
|
sweepTXID := h.sweepTx.TxHash()
|
||||||
sweepScript := h.sweepTx.TxOut[0].PkScript
|
sweepScript := h.sweepTx.TxOut[0].PkScript
|
||||||
confNtfn, err := h.Notifier.RegisterConfirmationsNtfn(
|
confNtfn, err := h.Notifier.RegisterConfirmationsNtfn(
|
||||||
@@ -440,8 +428,22 @@ func (h *htlcSuccessResolver) resolveRemoteCommitOutput() (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("%T(%x): waiting for sweep tx (txid=%v) to be "+
|
// Regardless of whether an existing transaction was found or newly
|
||||||
"confirmed", h, h.htlc.RHash[:], sweepTXID)
|
// 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 {
|
select {
|
||||||
case _, ok := <-confNtfn.Confirmed:
|
case _, ok := <-confNtfn.Confirmed:
|
||||||
|
|||||||
Reference in new issue
Block a user