lntest+itest: fix flakes found using neutrino backend
This commit makes sure the sweep requests are received before mining blocks to trigger the actual sweeping. In addition, `testFundingExpiryBlocksOnPending` is updated to deal with the old `channel link not found` issue.
This commit is contained in:
5 files changed
+43
-19
No files matched your search
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/chainreg"
|
"github.com/lightningnetwork/lnd/chainreg"
|
||||||
"github.com/lightningnetwork/lnd/fn"
|
|
||||||
"github.com/lightningnetwork/lnd/funding"
|
"github.com/lightningnetwork/lnd/funding"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/labels"
|
"github.com/lightningnetwork/lnd/labels"
|
||||||
@@ -1341,22 +1340,22 @@ func testChannelFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
|
|||||||
// that by dave force-closing the channel. Which let's carol sweep its
|
// that by dave force-closing the channel. Which let's carol sweep its
|
||||||
// to_remote output which is not encumbered by any relative locktime.
|
// to_remote output which is not encumbered by any relative locktime.
|
||||||
ht.CloseChannelAssertPending(dave, chanPoint2, true)
|
ht.CloseChannelAssertPending(dave, chanPoint2, true)
|
||||||
|
|
||||||
// Mine the force close commitment transaction.
|
// Mine the force close commitment transaction.
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
|
// Make sure Carol sees her to_remote output from the force close tx.
|
||||||
|
ht.AssertNumPendingSweeps(carol, 1)
|
||||||
|
|
||||||
// Mine one block to trigger the sweep transaction.
|
// Mine one block to trigger the sweep transaction.
|
||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
|
|
||||||
// We need to wait for carol initiating the sweep of the to_remote
|
// We need to wait for carol initiating the sweep of the to_remote
|
||||||
// output of chanPoint2.
|
// output of chanPoint2.
|
||||||
utxos := ht.AssertNumUTXOsUnconfirmed(carol, 1)
|
utxo := ht.AssertNumUTXOsUnconfirmed(carol, 1)[0]
|
||||||
|
|
||||||
// We filter for the unconfirmed utxo and try to open a channel with
|
// We now try to open channel using the unconfirmed utxo.
|
||||||
// that utxo.
|
fundingUtxo := utxo
|
||||||
utxoOpt := fn.Find(func(u *lnrpc.Utxo) bool {
|
|
||||||
return u.Confirmations == 0
|
|
||||||
}, utxos)
|
|
||||||
fundingUtxo := utxoOpt.UnwrapOrFail(ht.T)
|
|
||||||
|
|
||||||
// Now try to open the channel with this utxo and expect an error.
|
// Now try to open the channel with this utxo and expect an error.
|
||||||
expectedErr := fmt.Errorf("outpoint already spent or "+
|
expectedErr := fmt.Errorf("outpoint already spent or "+
|
||||||
@@ -1405,6 +1404,9 @@ func testChannelFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
|
|||||||
ht.CloseChannelAssertPending(dave, chanPoint3, true)
|
ht.CloseChannelAssertPending(dave, chanPoint3, true)
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
|
// Make sure Carol sees her to_remote output from the force close tx.
|
||||||
|
ht.AssertNumPendingSweeps(carol, 1)
|
||||||
|
|
||||||
// Mine one block to trigger the sweep transaction.
|
// Mine one block to trigger the sweep transaction.
|
||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
@@ -767,6 +768,18 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
|
|||||||
// channel.
|
// channel.
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
chanPoint := lntest.ChanPointFromPendingUpdate(update)
|
chanPoint := lntest.ChanPointFromPendingUpdate(update)
|
||||||
|
|
||||||
|
// TODO(yy): remove the sleep once the following bug is fixed.
|
||||||
|
//
|
||||||
|
// We may get the error `unable to gracefully close channel
|
||||||
|
// while peer is offline (try force closing it instead):
|
||||||
|
// channel link not found`. This happens because the channel
|
||||||
|
// link hasn't been added yet but we now proceed to closing the
|
||||||
|
// channel. We may need to revisit how the channel open event
|
||||||
|
// is created and make sure the event is only sent after all
|
||||||
|
// relevant states have been updated.
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
ht.CloseChannel(alice, chanPoint)
|
ht.CloseChannel(alice, chanPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1683,6 +1683,9 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
|
|||||||
ht.CloseChannelAssertPending(dave, channelPoint, true)
|
ht.CloseChannelAssertPending(dave, channelPoint, true)
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
|
// Make sure Carol sees her to_remote output from the force close tx.
|
||||||
|
ht.AssertNumPendingSweeps(carol, 1)
|
||||||
|
|
||||||
// Mine one block to trigger the sweep transaction.
|
// Mine one block to trigger the sweep transaction.
|
||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
|
|
||||||
@@ -1805,6 +1808,9 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
|
|||||||
ht.CloseChannelAssertPending(dave, channelPoint2, true)
|
ht.CloseChannelAssertPending(dave, channelPoint2, true)
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
|
// Make sure Carol sees her to_remote output from the force close tx.
|
||||||
|
ht.AssertNumPendingSweeps(carol, 1)
|
||||||
|
|
||||||
// Mine one block to trigger the sweep transaction.
|
// Mine one block to trigger the sweep transaction.
|
||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
|
|
||||||
@@ -1929,12 +1935,6 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
|
|||||||
updateResp = ht.ReceiveOpenChannelUpdate(chanUpdates)
|
updateResp = ht.ReceiveOpenChannelUpdate(chanUpdates)
|
||||||
upd, ok = updateResp.Update.(*lnrpc.OpenStatusUpdate_ChanPending)
|
upd, ok = updateResp.Update.(*lnrpc.OpenStatusUpdate_ChanPending)
|
||||||
require.True(ht, ok)
|
require.True(ht, ok)
|
||||||
channelPoint3 := &lnrpc.ChannelPoint{
|
|
||||||
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
|
|
||||||
FundingTxidBytes: upd.ChanPending.Txid,
|
|
||||||
},
|
|
||||||
OutputIndex: upd.ChanPending.OutputIndex,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = finalTx.Deserialize(bytes.NewReader(finalizeRes.RawFinalTx))
|
err = finalTx.Deserialize(bytes.NewReader(finalizeRes.RawFinalTx))
|
||||||
require.NoError(ht, err)
|
require.NoError(ht, err)
|
||||||
@@ -1942,6 +1942,4 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
|
|||||||
txHash = finalTx.TxHash()
|
txHash = finalTx.TxHash()
|
||||||
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
|
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
|
||||||
ht.AssertTxInBlock(block, &txHash)
|
ht.AssertTxInBlock(block, &txHash)
|
||||||
|
|
||||||
ht.CloseChannel(carol, channelPoint3)
|
|
||||||
}
|
}
|
||||||
@@ -785,8 +785,13 @@ func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
desc := "has UTXOs:\n"
|
||||||
|
for _, utxo := range resp.Utxos {
|
||||||
|
desc += fmt.Sprintf("%v\n", utxo)
|
||||||
|
}
|
||||||
|
|
||||||
return errNumNotMatched(hn.Name(), "num of UTXOs",
|
return errNumNotMatched(hn.Name(), "num of UTXOs",
|
||||||
expectedUtxos, total-old, total, old)
|
expectedUtxos, total-old, total, old, desc)
|
||||||
}, DefaultTimeout)
|
}, DefaultTimeout)
|
||||||
require.NoError(h, err, "timeout waiting for UTXOs")
|
require.NoError(h, err, "timeout waiting for UTXOs")
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -53,10 +53,16 @@ func CopyFile(dest, src string) error {
|
|||||||
|
|
||||||
// errNumNotMatched is a helper method to return a nicely formatted error.
|
// errNumNotMatched is a helper method to return a nicely formatted error.
|
||||||
func errNumNotMatched(name string, subject string,
|
func errNumNotMatched(name string, subject string,
|
||||||
want, got, total, old int) error {
|
want, got, total, old int, desc ...any) error {
|
||||||
|
|
||||||
return fmt.Errorf("%s: assert %s failed: want %d, got: %d, total: "+
|
err := fmt.Errorf("%s: assert %s failed: want %d, got: %d, total: "+
|
||||||
"%d, previously had: %d", name, subject, want, got, total, old)
|
"%d, previously had: %d", name, subject, want, got, total, old)
|
||||||
|
|
||||||
|
if len(desc) > 0 {
|
||||||
|
err = fmt.Errorf("%w, desc: %v", err, desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseDerivationPath parses a path in the form of m/x'/y'/z'/a/b into a slice
|
// parseDerivationPath parses a path in the form of m/x'/y'/z'/a/b into a slice
|
||||||
|
|||||||
Reference in new issue
Block a user