contractcourt: watch proper output within htlcOutgoingContestResolver

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.
This commit is contained in:
Olaoluwa Osuntokun 2018-01-23 14:16:13 -08:00
parent dd08662c87
commit 5dc0d669a6
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 13 additions and 2 deletions

@ -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 {

@ -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