contractcourt: update contract resolvers to use pkScripts for spend ntfns

This commit is contained in:
Olaoluwa Osuntokun 2018-07-17 19:43:46 -07:00
parent c6950fcc2f
commit d9969f5dc2
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -172,6 +172,7 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
// has been spent by a confirmed transaction. // has been spent by a confirmed transaction.
spendNtfn, err := h.Notifier.RegisterSpendNtfn( spendNtfn, err := h.Notifier.RegisterSpendNtfn(
&h.htlcResolution.ClaimOutpoint, &h.htlcResolution.ClaimOutpoint,
h.htlcResolution.SweepSignDesc.Output.PkScript,
h.broadcastHeight, h.broadcastHeight,
) )
if err != nil { 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 // To wrap this up, we'll wait until the second-level transaction has
// been spent, then fully resolve the contract. // been spent, then fully resolve the contract.
spendNtfn, err := h.Notifier.RegisterSpendNtfn( spendNtfn, err := h.Notifier.RegisterSpendNtfn(
&h.htlcResolution.ClaimOutpoint, h.broadcastHeight, &h.htlcResolution.ClaimOutpoint,
h.htlcResolution.SweepSignDesc.Output.PkScript,
h.broadcastHeight,
) )
if err != nil { if err != nil {
return nil, err 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 // 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 resolution. Otherwise, we fetch this pointer from the input of
// the time out transaction. // the time out transaction.
var outPointToWatch wire.OutPoint var (
outPointToWatch wire.OutPoint
scriptToWatch []byte
err error
)
if h.htlcResolution.SignedTimeoutTx == nil { if h.htlcResolution.SignedTimeoutTx == nil {
outPointToWatch = h.htlcResolution.ClaimOutpoint outPointToWatch = h.htlcResolution.ClaimOutpoint
scriptToWatch = h.htlcResolution.SweepSignDesc.Output.PkScript
} else { } 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 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 // 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( spendNtfn, err := h.Notifier.RegisterSpendNtfn(
&outPointToWatch, h.broadcastHeight, &outPointToWatch, scriptToWatch, h.broadcastHeight,
) )
if err != nil { if err != nil {
return nil, err 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. // We'll quickly check to see if the output has already been spent.
select { select {
// If the output has already been spent, then we can stop early and // 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: case commitSpend, ok := <-spendNtfn.Spend:
if !ok { if !ok {
return nil, fmt.Errorf("quitting") return nil, fmt.Errorf("quitting")
@ -1295,6 +1316,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
// until the commitment output has been spent. // until the commitment output has been spent.
spendNtfn, err := c.Notifier.RegisterSpendNtfn( spendNtfn, err := c.Notifier.RegisterSpendNtfn(
&c.commitResolution.SelfOutPoint, &c.commitResolution.SelfOutPoint,
c.commitResolution.SelfOutputSignDesc.Output.PkScript,
c.broadcastHeight, c.broadcastHeight,
) )
if err != nil { if err != nil {