Skip to content

Commit 388981d

Browse files
committed
lntest+itest: fix flakes in testChannelFundingWithUnstableUtxos
This commit makes sure the sweep requests are received before mining blocks to trigger the actual sweeping in `testChannelFundingWithUnstableUtxos`. In addition, `testFundingExpiryBlocksOnPending` is updated to deal with the old `channel link not found` issue.
1 parent 42a0cc3 commit 388981d

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

itest/lnd_funding_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/btcsuite/btcd/txscript"
1313
"github.com/btcsuite/btcd/wire"
1414
"github.com/lightningnetwork/lnd/chainreg"
15-
"github.com/lightningnetwork/lnd/fn"
1615
"github.com/lightningnetwork/lnd/funding"
1716
"github.com/lightningnetwork/lnd/input"
1817
"github.com/lightningnetwork/lnd/labels"
@@ -1341,22 +1340,22 @@ func testChannelFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
13411340
// that by dave force-closing the channel. Which let's carol sweep its
13421341
// to_remote output which is not encumbered by any relative locktime.
13431342
ht.CloseChannelAssertPending(dave, chanPoint2, true)
1343+
13441344
// Mine the force close commitment transaction.
13451345
ht.MineBlocksAndAssertNumTxes(1, 1)
13461346

1347+
// Make sure Carol sees her to_remote output from the force close tx.
1348+
ht.AssertNumPendingSweeps(carol, 1)
1349+
13471350
// Mine one block to trigger the sweep transaction.
13481351
ht.MineEmptyBlocks(1)
13491352

13501353
// We need to wait for carol initiating the sweep of the to_remote
13511354
// output of chanPoint2.
1352-
utxos := ht.AssertNumUTXOsUnconfirmed(carol, 1)
1355+
utxo := ht.AssertNumUTXOsUnconfirmed(carol, 1)[0]
13531356

1354-
// We filter for the unconfirmed utxo and try to open a channel with
1355-
// that utxo.
1356-
utxoOpt := fn.Find(func(u *lnrpc.Utxo) bool {
1357-
return u.Confirmations == 0
1358-
}, utxos)
1359-
fundingUtxo := utxoOpt.UnwrapOrFail(ht.T)
1357+
// We now try to open channel using the unconfirmed utxo.
1358+
fundingUtxo := utxo
13601359

13611360
// Now try to open the channel with this utxo and expect an error.
13621361
expectedErr := fmt.Errorf("outpoint already spent or "+
@@ -1405,6 +1404,9 @@ func testChannelFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
14051404
ht.CloseChannelAssertPending(dave, chanPoint3, true)
14061405
ht.MineBlocksAndAssertNumTxes(1, 1)
14071406

1407+
// Make sure Carol sees her to_remote output from the force close tx.
1408+
ht.AssertNumPendingSweeps(carol, 1)
1409+
14081410
// Mine one block to trigger the sweep transaction.
14091411
ht.MineEmptyBlocks(1)
14101412

itest/lnd_open_channel_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"strings"
66
"testing"
7+
"time"
78

89
"github.com/btcsuite/btcd/btcutil"
910
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -767,6 +768,18 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
767768
// channel.
768769
ht.MineBlocksAndAssertNumTxes(1, 1)
769770
chanPoint := lntest.ChanPointFromPendingUpdate(update)
771+
772+
// TODO(yy): remove the sleep once the following bug is fixed.
773+
//
774+
// We may get the error `unable to gracefully close channel
775+
// while peer is offline (try force closing it instead):
776+
// channel link not found`. This happens because the channel
777+
// link hasn't been added yet but we now proceed to closing the
778+
// channel. We may need to revisit how the channel open event
779+
// is created and make sure the event is only sent after all
780+
// relevant states have been updated.
781+
time.Sleep(2 * time.Second)
782+
770783
ht.CloseChannel(alice, chanPoint)
771784
}
772785

lntest/harness_assertion.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,13 @@ func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode,
785785
return nil
786786
}
787787

788+
desc := "has UTXOs:\n"
789+
for _, utxo := range resp.Utxos {
790+
desc += fmt.Sprintf("%v\n", utxo)
791+
}
792+
788793
return errNumNotMatched(hn.Name(), "num of UTXOs",
789-
expectedUtxos, total-old, total, old)
794+
expectedUtxos, total-old, total, old, desc)
790795
}, DefaultTimeout)
791796
require.NoError(h, err, "timeout waiting for UTXOs")
792797

lntest/utils.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ func CopyFile(dest, src string) error {
5353

5454
// errNumNotMatched is a helper method to return a nicely formatted error.
5555
func errNumNotMatched(name string, subject string,
56-
want, got, total, old int) error {
56+
want, got, total, old int, desc ...any) error {
5757

58-
return fmt.Errorf("%s: assert %s failed: want %d, got: %d, total: "+
58+
err := fmt.Errorf("%s: assert %s failed: want %d, got: %d, total: "+
5959
"%d, previously had: %d", name, subject, want, got, total, old)
60+
61+
if len(desc) > 0 {
62+
err = fmt.Errorf("%s, desc: %v", err, desc)
63+
}
64+
65+
return err
6066
}
6167

6268
// parseDerivationPath parses a path in the form of m/x'/y'/z'/a/b into a slice

0 commit comments

Comments
 (0)