test: wait for 2 transactions to enter mempool at the end of testMultiHopHtlcRemoteChainClaim

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

View File

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

View File

@ -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")
}