From 5dc0d669a609e748bbc7716748cb0e85044fec5e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 23 Jan 2018 14:16:13 -0800 Subject: [PATCH] contractcourt: watch proper output within htlcOutgoingContestResolver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we fix an existing bug in the implementation of the resolution of the htlcOutgoingContestResolver. Before this commit, we would _always_ watch the claim outpoint. However, if this is on the remote party’s commitment transaction, then we would end up watching the wrong output. We’ll now properly detect this by modifying which output we watch, based on if we have a second level transaction or not. --- contractcourt/contract_resolvers.go | 13 ++++++++++++- lnd_test.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/contractcourt/contract_resolvers.go b/contractcourt/contract_resolvers.go index 60bb6a17..29eafe03 100644 --- a/contractcourt/contract_resolvers.go +++ b/contractcourt/contract_resolvers.go @@ -801,10 +801,21 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) { // Otherwise, we'll watch for two external signals to decide if we'll // morph into another resolver, or fully resolve the contract. + // The output we'll be watching for is the *direct* spend from the HTLC + // 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 + if h.htlcResolution.SignedTimeoutTx == nil { + outPointToWatch = h.htlcResolution.ClaimOutpoint + } else { + outPointToWatch = h.htlcResolution.SignedTimeoutTx.TxIn[0].PreviousOutPoint + } + // First, we'll register for a spend notification for this output. If // the remote party sweeps with the pre-image, we'll be notified. spendNtfn, err := h.Notifier.RegisterSpendNtfn( - &h.htlcResolution.ClaimOutpoint, + &outPointToWatch, h.broadcastHeight, ) if err != nil { diff --git a/lnd_test.go b/lnd_test.go index 666e640d..fc457889 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -5136,7 +5136,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest) { return true }, time.Second*15) if err != nil { - t.Fatalf("htlc mismatch: %v", err) + t.Fatalf("htlc mismatch: %v", predErr) } // We'll now mine enough blocks to trigger Bob's broadcast of his