Skip to content

Commit 652d39d

Browse files
committed
itest: fix flakeSkipPendingSweepsCheckDarwin
Now that we have the new RPC to assert the HTLC state, this flake should be fixed.
1 parent 5a72d52 commit 652d39d

File tree

3 files changed

+49
-56
lines changed

3 files changed

+49
-56
lines changed

itest/flakes.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package itest
22

33
import (
4-
"runtime"
54
"time"
65

76
"github.com/btcsuite/btcd/btcutil"
@@ -72,39 +71,6 @@ func flakeTxNotifierNeutrino(ht *lntest.HarnessTest) {
7271
}
7372
}
7473

75-
// flakeSkipPendingSweepsCheckDarwin documents a flake found only in macOS
76-
// build. When running in macOS, we might see three anchor sweeps - one from the
77-
// local, one from the remote, and one from the pending remote:
78-
// - the local one will be swept.
79-
// - the remote one will be marked as failed due to `testmempoolaccept` check.
80-
// - the pending remote one will not be attempted due to it being uneconomical
81-
// since it was not used for CPFP.
82-
//
83-
// The anchor from the pending remote may or may not appear, which is a bug
84-
// found only in macOS - when updating the commitments, the channel state
85-
// machine somehow thinks we still have a pending remote commitment, causing it
86-
// to sweep the anchor from that version.
87-
//
88-
// TODO(yy): fix the above bug in the channel state machine.
89-
func flakeSkipPendingSweepsCheckDarwin(ht *lntest.HarnessTest,
90-
node *node.HarnessNode, num int) {
91-
92-
// Skip the assertion below if it's on macOS.
93-
if isDarwin() {
94-
ht.Logf("Skipped AssertNumPendingSweeps for node %s",
95-
node.Name())
96-
97-
return
98-
}
99-
100-
ht.AssertNumPendingSweeps(node, num)
101-
}
102-
103-
// isDarwin returns true if the test is running on a macOS.
104-
func isDarwin() bool {
105-
return runtime.GOOS == "darwin"
106-
}
107-
10874
// flakeInconsistentHTLCView documents a flake found that the `ListChannels` RPC
10975
// can give inaccurate HTLC states, which is found when we call
11076
// `AssertHTLCNotActive` after a commitment dance is finished. Suppose Carol is

itest/lnd_multi-hop_force_close_test.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
422422
if ht.IsNeutrinoBackend() {
423423
numSweeps = 2
424424
}
425-
426-
flakeSkipPendingSweepsCheckDarwin(ht, bob, numSweeps)
425+
ht.AssertNumPendingSweeps(bob, numSweeps)
427426

428427
// We expect to see tow txns in the mempool,
429428
// 1. Bob's force close tx.
@@ -753,6 +752,9 @@ func runMultiHopReceiverPreimageClaim(ht *lntest.HarnessTest,
753752
// channel arbitrator won't go to chain.
754753
carol.RPC.SettleInvoice(preimage[:])
755754

755+
// Carol should still have one incoming HTLC on channel Bob -> Carol.
756+
ht.AssertNumActiveHtlcs(carol, 1)
757+
756758
// We now advance the block height to the point where Carol will force
757759
// close her channel with Bob, broadcast the closing tx but keep it
758760
// unconfirmed.
@@ -780,8 +782,7 @@ func runMultiHopReceiverPreimageClaim(ht *lntest.HarnessTest,
780782
if ht.IsNeutrinoBackend() {
781783
numSweeps = 2
782784
}
783-
784-
flakeSkipPendingSweepsCheckDarwin(ht, carol, numSweeps)
785+
ht.AssertNumPendingSweeps(carol, numSweeps)
785786

786787
// We expect to see tow txns in the mempool,
787788
// 1. Carol's force close tx.
@@ -1700,6 +1701,9 @@ func runLocalClaimIncomingHTLC(ht *lntest.HarnessTest,
17001701
// channel arbitrator won't go to chain.
17011702
carol.RPC.SettleInvoice(preimage[:])
17021703

1704+
// Carol should still have one incoming HTLC on channel Bob -> Carol.
1705+
ht.AssertNumActiveHtlcs(carol, 1)
1706+
17031707
// We now advance the block height to the point where Carol will force
17041708
// close her channel with Bob, broadcast the closing tx but keep it
17051709
// unconfirmed.
@@ -1978,6 +1982,9 @@ func runLocalClaimIncomingHTLCLeased(ht *lntest.HarnessTest,
19781982
// channel arbitrator won't go to chain.
19791983
carol.RPC.SettleInvoice(preimage[:])
19801984

1985+
// Carol should still have one incoming HTLC on channel Bob -> Carol.
1986+
ht.AssertNumActiveHtlcs(carol, 1)
1987+
19811988
// We now advance the block height to the point where Carol will force
19821989
// close her channel with Bob, broadcast the closing tx but keep it
19831990
// unconfirmed.
@@ -2319,6 +2326,9 @@ func runLocalPreimageClaim(ht *lntest.HarnessTest,
23192326
// channel arbitrator won't go to chain.
23202327
carol.RPC.SettleInvoice(preimage[:])
23212328

2329+
// Carol should still have one incoming HTLC on channel Bob -> Carol.
2330+
ht.AssertNumActiveHtlcs(carol, 1)
2331+
23222332
ht.Logf("Invoice expire height: %d, current: %d", invoiceExpiry,
23232333
ht.CurrentHeight())
23242334

@@ -2338,8 +2348,7 @@ func runLocalPreimageClaim(ht *lntest.HarnessTest,
23382348
if ht.IsNeutrinoBackend() {
23392349
numSweeps = 2
23402350
}
2341-
2342-
flakeSkipPendingSweepsCheckDarwin(ht, carol, numSweeps)
2351+
ht.AssertNumPendingSweeps(carol, numSweeps)
23432352

23442353
// We should see two txns in the mempool, we now a block to confirm,
23452354
// - Carol's force close tx.
@@ -2560,6 +2569,9 @@ func runLocalPreimageClaimLeased(ht *lntest.HarnessTest,
25602569
// channel arbitrator won't go to chain.
25612570
carol.RPC.SettleInvoice(preimage[:])
25622571

2572+
// Carol should still have one incoming HTLC on channel Bob -> Carol.
2573+
ht.AssertNumActiveHtlcs(carol, 1)
2574+
25632575
ht.Logf("Invoice expire height: %d, current: %d", invoiceExpiry,
25642576
ht.CurrentHeight())
25652577

@@ -2579,8 +2591,7 @@ func runLocalPreimageClaimLeased(ht *lntest.HarnessTest,
25792591
if ht.IsNeutrinoBackend() {
25802592
numSweeps = 2
25812593
}
2582-
2583-
flakeSkipPendingSweepsCheckDarwin(ht, carol, numSweeps)
2594+
ht.AssertNumPendingSweeps(carol, numSweeps)
25842595

25852596
// We should see two txns in the mempool, we now a block to confirm,
25862597
// - Carol's force close tx.
@@ -2988,8 +2999,7 @@ func runHtlcAggregation(ht *lntest.HarnessTest,
29882999
if ht.IsNeutrinoBackend() {
29893000
numSweeps = 2
29903001
}
2991-
2992-
flakeSkipPendingSweepsCheckDarwin(ht, bob, numSweeps)
3002+
ht.AssertNumPendingSweeps(bob, numSweeps)
29933003

29943004
// Bob's force close tx and anchor sweeping tx should now be found in
29953005
// the mempool.

lntest/harness_assertion.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,17 +1239,30 @@ func (h *HarnessTest) AssertNumActiveHtlcs(hn *node.HarnessNode, num int) {
12391239
old := hn.State.HTLC
12401240

12411241
err := wait.NoError(func() error {
1242+
// pendingHTLCs is used to print unacked HTLCs, if found.
1243+
var pendingHTLCs []string
1244+
12421245
// We require the RPC call to be succeeded and won't wait for
12431246
// it as it's an unexpected behavior.
12441247
req := &lnrpc.ListChannelsRequest{}
12451248
nodeChans := hn.RPC.ListChannels(req)
12461249

12471250
total := 0
12481251
for _, channel := range nodeChans.Channels {
1249-
total += len(channel.PendingHtlcs)
1252+
for _, htlc := range channel.PendingHtlcs {
1253+
if htlc.LockedIn {
1254+
total++
1255+
}
1256+
1257+
rHash := fmt.Sprintf("%x", htlc.HashLock)
1258+
pendingHTLCs = append(pendingHTLCs, rHash)
1259+
}
12501260
}
12511261
if total-old != num {
1252-
return errNumNotMatched(hn.Name(), "active HTLCs",
1262+
desc := fmt.Sprintf("active HTLCs: unacked HTLCs: %v",
1263+
pendingHTLCs)
1264+
1265+
return errNumNotMatched(hn.Name(), desc,
12531266
num, total-old, total, old)
12541267
}
12551268

@@ -1291,17 +1304,22 @@ func (h *HarnessTest) assertHTLCActive(hn *node.HarnessNode,
12911304

12921305
// Check all payment hashes active for this channel.
12931306
for _, htlc := range ch.PendingHtlcs {
1294-
h := hex.EncodeToString(htlc.HashLock)
1295-
if h != target {
1307+
rHash := hex.EncodeToString(htlc.HashLock)
1308+
if rHash != target {
12961309
continue
12971310
}
12981311

12991312
// If the payment hash is found, check the incoming
13001313
// field.
13011314
if htlc.Incoming == incoming {
1302-
// Found it and return.
1303-
result = htlc
1304-
return nil
1315+
// Return the result if it's locked in.
1316+
if htlc.LockedIn {
1317+
result = htlc
1318+
return nil
1319+
}
1320+
1321+
return fmt.Errorf("htlc(%x) not locked in",
1322+
payHash)
13051323
}
13061324

13071325
// Otherwise we do have the HTLC but its direction is
@@ -1311,14 +1329,13 @@ func (h *HarnessTest) assertHTLCActive(hn *node.HarnessNode,
13111329
have, want = "incoming", "outgoing"
13121330
}
13131331

1314-
return fmt.Errorf("node[%s] have htlc(%v), want: %s, "+
1315-
"have: %s", hn.Name(), payHash, want, have)
1332+
return fmt.Errorf("htlc(%x) has wrong direction - "+
1333+
"want: %s, have: %s", payHash, want, have)
13161334
}
13171335

1318-
return fmt.Errorf("node [%s:%x] didn't have: the payHash %x",
1319-
hn.Name(), hn.PubKey[:], payHash)
1336+
return fmt.Errorf("htlc not found using payHash %x", payHash)
13201337
}, DefaultTimeout)
1321-
require.NoError(h, err, "timeout checking pending HTLC")
1338+
require.NoError(h, err, "%s: timeout checking pending HTLC", hn.Name())
13221339

13231340
return result
13241341
}

0 commit comments

Comments
 (0)