diff --git a/itest/flakes.go b/itest/flakes.go index 8b3c39638..465ef4bec 100644 --- a/itest/flakes.go +++ b/itest/flakes.go @@ -1,6 +1,7 @@ package itest import ( + "runtime" "time" "github.com/btcsuite/btcd/btcutil" @@ -70,3 +71,36 @@ func flakeTxNotifierNeutrino(ht *lntest.HarnessTest) { ht.MineEmptyBlocks(1) } } + +// flakeSkipPendingSweepsCheckDarwin documents a flake found only in macOS +// build. When running in macOS, we might see three anchor sweeps - one from the +// local, one from the remote, and one from the pending remote: +// - the local one will be swept. +// - the remote one will be marked as failed due to `testmempoolaccept` check. +// - the pending remote one will not be attempted due to it being uneconomical +// since it was not used for CPFP. +// +// The anchor from the pending remote may or may not appear, which is a bug +// found only in macOS - when updating the commitments, the channel state +// machine somehow thinks we still have a pending remote commitment, causing it +// to sweep the anchor from that version. +// +// TODO(yy): fix the above bug in the channel state machine. +func flakeSkipPendingSweepsCheckDarwin(ht *lntest.HarnessTest, + node *node.HarnessNode, num int) { + + // Skip the assertion below if it's on macOS. + if isDarwin() { + ht.Logf("Skipped AssertNumPendingSweeps for node %s", + node.Name()) + + return + } + + ht.AssertNumPendingSweeps(node, num) +} + +// isDarwin returns true if the test is running on a macOS. +func isDarwin() bool { + return runtime.GOOS == "darwin" +} diff --git a/itest/lnd_multi-hop_force_close_test.go b/itest/lnd_multi-hop_force_close_test.go index 7d8d7ea1d..17fd75758 100644 --- a/itest/lnd_multi-hop_force_close_test.go +++ b/itest/lnd_multi-hop_force_close_test.go @@ -423,22 +423,7 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest, numSweeps = 2 } - // When running in macOS, we might see three anchor sweeps - one from - // the local, one from the remote, and one from the pending remote: - // - the local one will be swept. - // - the remote one will be marked as failed due to `testmempoolaccept` - // check. - // - the pending remote one will not be attempted due to it being - // uneconomical since it was not used for CPFP. - // The anchor from the pending remote may or may not appear, which is a - // bug found only in macOS - when updating the commitments, the channel - // state machine somehow thinks we still have a pending remote - // commitment, causing it to sweep the anchor from that version. - // - // TODO(yy): fix the above bug in the channel state machine. - if !isDarwin() { - ht.AssertNumPendingSweeps(bob, numSweeps) - } + flakeSkipPendingSweepsCheckDarwin(ht, bob, numSweeps) // We expect to see tow txns in the mempool, // 1. Bob's force close tx. @@ -795,22 +780,7 @@ func runMultiHopReceiverPreimageClaim(ht *lntest.HarnessTest, numSweeps = 2 } - // When running in macOS, we might see three anchor sweeps - one from - // the local, one from the remote, and one from the pending remote: - // - the local one will be swept. - // - the remote one will be marked as failed due to `testmempoolaccept` - // check. - // - the pending remote one will not be attempted due to it being - // uneconomical since it was not used for CPFP. - // The anchor from the pending remote may or may not appear, which is a - // bug found only in macOS - when updating the commitments, the channel - // state machine somehow thinks we still have a pending remote - // commitment, causing it to sweep the anchor from that version. - // - // TODO(yy): fix the above bug in the channel state machine. - if !isDarwin() { - ht.AssertNumPendingSweeps(carol, numSweeps) - } + flakeSkipPendingSweepsCheckDarwin(ht, carol, numSweeps) // We expect to see tow txns in the mempool, // 1. Carol's force close tx. @@ -2365,22 +2335,7 @@ func runLocalPreimageClaim(ht *lntest.HarnessTest, numSweeps = 2 } - // When running in macOS, we might see three anchor sweeps - one from - // the local, one from the remote, and one from the pending remote: - // - the local one will be swept. - // - the remote one will be marked as failed due to `testmempoolaccept` - // check. - // - the pending remote one will not be attempted due to it being - // uneconomical since it was not used for CPFP. - // The anchor from the pending remote may or may not appear, which is a - // bug found only in macOS - when updating the commitments, the channel - // state machine somehow thinks we still have a pending remote - // commitment, causing it to sweep the anchor from that version. - // - // TODO(yy): fix the above bug in the channel state machine. - if !isDarwin() { - ht.AssertNumPendingSweeps(carol, numSweeps) - } + flakeSkipPendingSweepsCheckDarwin(ht, carol, numSweeps) // We should see two txns in the mempool, we now a block to confirm, // - Carol's force close tx. @@ -2620,22 +2575,7 @@ func runLocalPreimageClaimLeased(ht *lntest.HarnessTest, numSweeps = 2 } - // When running in macOS, we might see three anchor sweeps - one from - // the local, one from the remote, and one from the pending remote: - // - the local one will be swept. - // - the remote one will be marked as failed due to `testmempoolaccept` - // check. - // - the pending remote one will not be attempted due to it being - // uneconomical since it was not used for CPFP. - // The anchor from the pending remote may or may not appear, which is a - // bug found only in macOS - when updating the commitments, the channel - // state machine somehow thinks we still have a pending remote - // commitment, causing it to sweep the anchor from that version. - // - // TODO(yy): fix the above bug in the channel state machine. - if !isDarwin() { - ht.AssertNumPendingSweeps(carol, numSweeps) - } + flakeSkipPendingSweepsCheckDarwin(ht, carol, numSweeps) // We should see two txns in the mempool, we now a block to confirm, // - Carol's force close tx. @@ -3043,22 +2983,7 @@ func runHtlcAggregation(ht *lntest.HarnessTest, numSweeps = 2 } - // When running in macOS, we might see three anchor sweeps - one from - // the local, one from the remote, and one from the pending remote: - // - the local one will be swept. - // - the remote one will be marked as failed due to `testmempoolaccept` - // check. - // - the pending remote one will not be attempted due to it being - // uneconomical since it was not used for CPFP. - // The anchor from the pending remote may or may not appear, which is a - // bug found only in macOS - when updating the commitments, the channel - // state machine somehow thinks we still have a pending remote - // commitment, causing it to sweep the anchor from that version. - // - // TODO(yy): fix the above bug in the channel state machine. - if !isDarwin() { - ht.AssertNumPendingSweeps(bob, numSweeps) - } + flakeSkipPendingSweepsCheckDarwin(ht, bob, numSweeps) // Bob's force close tx and anchor sweeping tx should now be found in // the mempool. diff --git a/itest/lnd_test.go b/itest/lnd_test.go index 07b8554f2..32c0f1c02 100644 --- a/itest/lnd_test.go +++ b/itest/lnd_test.go @@ -254,11 +254,6 @@ func getLndBinary(t *testing.T) string { return binary } -// isDarwin returns true if the test is running on a macOS. -func isDarwin() bool { - return runtime.GOOS == "darwin" -} - // isWindowsOS returns true if the test is running on a Windows OS. func isWindowsOS() bool { return runtime.GOOS == "windows"