From 2d104b7ec095452f777a2fd54bc848b141bc4042 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 23 Jan 2018 19:05:27 -0800 Subject: [PATCH] test: wait for 2 transactions to enter mempool at the end of testMultiHopHtlcRemoteChainClaim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we fix an existing flake on Travis related to the new set of on-chain HTLC tests. In this timing flake, Bob would broadcast his sweeping transaction, but *mid block mining*. As a result, the output would never be properly swept, needing an additional block to be mined. We’ll now wait for both Bob’s sweeping transaction, and Carol’s sweep transaction to be confirmed before we attempt our assertions. --- contractcourt/contract_resolvers.go | 20 ++++++++++++-------- lnd_test.go | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/contractcourt/contract_resolvers.go b/contractcourt/contract_resolvers.go index 29eafe033..92049eb52 100644 --- a/contractcourt/contract_resolvers.go +++ b/contractcourt/contract_resolvers.go @@ -487,8 +487,9 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { return nil, err } - log.Debugf("%T(%x): using %v sat/weight to sweep htlc", - "incoming+remote htlc confirmed", h, h.payHash[:]) + log.Debugf("%T(%x): using %v sat/weight to sweep htlc"+ + "incoming+remote htlc confirmed", h, + h.payHash[:], int64(satWeight)) // Using a weight estimator, we'll compute the total // fee required, and from that the value we'll end up @@ -511,9 +512,6 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { Value: sweepAmt, }) - log.Infof("%T(%v): crafted sweep tx=%v", h, - h.payHash[:], spew.Sdump(h.sweepTx)) - // With the transaction fully assembled, we can now // generate a valid witness for the transaction. h.htlcResolution.SweepSignDesc.SigHashes = txscript.NewTxSigHashes( @@ -527,6 +525,9 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { return nil, err } + log.Infof("%T(%x): crafted sweep tx=%v", h, + h.payHash[:], spew.Sdump(h.sweepTx)) + // With the sweep transaction confirmed, we'll now // Checkpoint our state. if err := h.Checkpoint(h); err != nil { @@ -538,6 +539,8 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { // // TODO(roasbeef): validate first? if err := h.PublishTx(h.sweepTx); err != nil { + log.Infof("%T(%x): unable to publish tx: %v", + h, h.payHash[:], err) return nil, err } } @@ -551,6 +554,10 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { if err != nil { return nil, err } + + log.Infof("%T(%x): waiting for sweep tx (txid=%v) to be "+ + "confirmed", h, h.payHash[:], sweepTXID) + select { case _, ok := <-confNtfn.Confirmed: if !ok { @@ -561,9 +568,6 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { return nil, fmt.Errorf("quitting") } - log.Infof("%T(%x): waiting for sweep tx (txid=%v) to be "+ - "confirmed", h, h.payHash[:], sweepTXID) - // Once the transaction has received a sufficient number of // confirmations, we'll mark ourselves as fully resolved and exit. h.resolved = true diff --git a/lnd_test.go b/lnd_test.go index fc457889b..37a5e30a3 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -6233,7 +6233,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest // With the block mined above, Bob should detect that Carol is // attempting to sweep the HTLC on-chain, and should obtain the // preimage. - _, err = waitForTxInMempool(net.Miner.Node, time.Second*10) + _, err = waitForNTxsInMempool(net.Miner.Node, 2, time.Second*15) if err != nil { t.Fatalf("unable to find bob's sweeping transaction") }