diff --git a/contractcourt/contract_resolvers.go b/contractcourt/contract_resolvers.go index 541b40fb0..086b8d26c 100644 --- a/contractcourt/contract_resolvers.go +++ b/contractcourt/contract_resolvers.go @@ -172,6 +172,7 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) { // has been spent by a confirmed transaction. spendNtfn, err := h.Notifier.RegisterSpendNtfn( &h.htlcResolution.ClaimOutpoint, + h.htlcResolution.SweepSignDesc.Output.PkScript, h.broadcastHeight, ) if err != nil { @@ -582,7 +583,9 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { // To wrap this up, we'll wait until the second-level transaction has // been spent, then fully resolve the contract. spendNtfn, err := h.Notifier.RegisterSpendNtfn( - &h.htlcResolution.ClaimOutpoint, h.broadcastHeight, + &h.htlcResolution.ClaimOutpoint, + h.htlcResolution.SweepSignDesc.Output.PkScript, + h.broadcastHeight, ) if err != nil { return nil, err @@ -783,17 +786,34 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) { // output. If this isn't our commitment transaction, it'll be right on // the resolution. Otherwise, we fetch this pointer from the input of // the time out transaction. - var outPointToWatch wire.OutPoint + var ( + outPointToWatch wire.OutPoint + scriptToWatch []byte + err error + ) if h.htlcResolution.SignedTimeoutTx == nil { outPointToWatch = h.htlcResolution.ClaimOutpoint + scriptToWatch = h.htlcResolution.SweepSignDesc.Output.PkScript } else { + // If this is the remote party's commitment, then we'll need to + // grab watch the output that our timeout transaction points + // to. We can directly grab the outpoint, then also extract the + // witness script (the last element of the witness stack) to + // re-construct the pkScipt we need to watch. outPointToWatch = h.htlcResolution.SignedTimeoutTx.TxIn[0].PreviousOutPoint + witness := h.htlcResolution.SignedTimeoutTx.TxIn[0].Witness + scriptToWatch, err = lnwallet.WitnessScriptHash( + witness[len(witness)-1], + ) + if err != nil { + return nil, err + } } // First, we'll register for a spend notification for this output. If - // the remote party sweeps with the pre-image, we'll be notified. + // the remote party sweeps with the pre-image, we'll be notified. spendNtfn, err := h.Notifier.RegisterSpendNtfn( - &outPointToWatch, h.broadcastHeight, + &outPointToWatch, scriptToWatch, h.broadcastHeight, ) if err != nil { return nil, err @@ -802,6 +822,7 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) { // We'll quickly check to see if the output has already been spent. select { // If the output has already been spent, then we can stop early and + // sweep the pre-image from the output. case commitSpend, ok := <-spendNtfn.Spend: if !ok { return nil, fmt.Errorf("quitting") @@ -1295,6 +1316,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) { // until the commitment output has been spent. spendNtfn, err := c.Notifier.RegisterSpendNtfn( &c.commitResolution.SelfOutPoint, + c.commitResolution.SelfOutputSignDesc.Output.PkScript, c.broadcastHeight, ) if err != nil {