Skip to content

Commit

Permalink
Merge pull request #9307 from lightningnetwork/yy-beat-itest-flakes
Browse files Browse the repository at this point in the history
 Beat itest [2/3]: document and fix itest flakes
  • Loading branch information
yyforyongyu authored Dec 18, 2024
2 parents 890b841 + 55b40e2 commit 4db3060
Show file tree
Hide file tree
Showing 27 changed files with 679 additions and 575 deletions.
13 changes: 7 additions & 6 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ var allTestCases = []*lntest.TestCase{
Name: "open channel reorg test",
TestFunc: testOpenChannelAfterReorg,
},
{
Name: "psbt channel funding",
TestFunc: testPsbtChanFunding,
},
{
Name: "sign psbt",
TestFunc: testSignPsbt,
Expand Down Expand Up @@ -573,8 +569,12 @@ var allTestCases = []*lntest.TestCase{
TestFunc: testChannelUtxoSelection,
},
{
Name: "update pending open channels",
TestFunc: testUpdateOnPendingOpenChannels,
Name: "update pending open channels on funder side",
TestFunc: testUpdateOnFunderPendingOpenChannels,
},
{
Name: "update pending open channels on fundee side",
TestFunc: testUpdateOnFundeePendingOpenChannels,
},
{
Name: "blinded payment htlc re-forward",
Expand Down Expand Up @@ -694,4 +694,5 @@ func init() {
// Register subtests.
allTestCases = append(allTestCases, multiHopForceCloseTestCases...)
allTestCases = append(allTestCases, watchtowerTestCases...)
allTestCases = append(allTestCases, psbtFundingTestCases...)
}
47 changes: 7 additions & 40 deletions itest/lnd_amp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func testSendPaymentAMPInvoiceCase(ht *lntest.HarnessTest,
req := &lnrpc.InvoiceSubscription{}
bobInvoiceSubscription := mts.bob.RPC.SubscribeInvoices(req)

const paymentAmt = btcutil.Amount(300000)

// Set up a network with three different paths Alice <-> Bob. Channel
// capacities are set such that the payment can only succeed if (at
// least) three paths are used.
Expand All @@ -59,15 +57,8 @@ func testSendPaymentAMPInvoiceCase(ht *lntest.HarnessTest,
// \ /
// \__ Dave ____/
//
mppReq := &mppOpenChannelRequest{
amtAliceCarol: 285000,
amtAliceDave: 155000,
amtCarolBob: 200000,
amtCarolEve: 155000,
amtDaveBob: 155000,
amtEveBob: 155000,
}
mts.openChannels(mppReq)
paymentAmt := mts.setupSendPaymentCase()

chanPointAliceDave := mts.channelPoints[1]
chanPointDaveBob := mts.channelPoints[4]

Expand Down Expand Up @@ -373,7 +364,6 @@ func testSendPaymentAMPInvoiceRepeat(ht *lntest.HarnessTest) {
// destination using SendPaymentV2.
func testSendPaymentAMP(ht *lntest.HarnessTest) {
mts := newMppTestScenario(ht)
const paymentAmt = btcutil.Amount(300000)

// Set up a network with three different paths Alice <-> Bob. Channel
// capacities are set such that the payment can only succeed if (at
Expand All @@ -385,15 +375,8 @@ func testSendPaymentAMP(ht *lntest.HarnessTest) {
// \ /
// \__ Dave ____/
//
mppReq := &mppOpenChannelRequest{
amtAliceCarol: 285000,
amtAliceDave: 155000,
amtCarolBob: 200000,
amtCarolEve: 155000,
amtDaveBob: 155000,
amtEveBob: 155000,
}
mts.openChannels(mppReq)
paymentAmt := mts.setupSendPaymentCase()

chanPointAliceDave := mts.channelPoints[1]

// Increase Dave's fee to make the test deterministic. Otherwise, it
Expand Down Expand Up @@ -497,12 +480,6 @@ func testSendPaymentAMP(ht *lntest.HarnessTest) {

func testSendToRouteAMP(ht *lntest.HarnessTest) {
mts := newMppTestScenario(ht)
const (
paymentAmt = btcutil.Amount(300000)
numShards = 3
shardAmt = paymentAmt / numShards
chanAmt = shardAmt * 3 / 2
)

// Subscribe to bob's invoices.
req := &lnrpc.InvoiceSubscription{}
Expand All @@ -515,20 +492,10 @@ func testSendToRouteAMP(ht *lntest.HarnessTest) {
// \ /
// \__ Dave ____/
//
mppReq := &mppOpenChannelRequest{
// Since the channel Alice-> Carol will have to carry two
// shards, we make it larger.
amtAliceCarol: chanAmt + shardAmt,
amtAliceDave: chanAmt,
amtCarolBob: chanAmt,
amtCarolEve: chanAmt,
amtDaveBob: chanAmt,
amtEveBob: chanAmt,
}
mts.openChannels(mppReq)
paymentAmt, shardAmt := mts.setupSendToRouteCase()

// We'll send shards along three routes from Alice.
sendRoutes := [numShards][]*node.HarnessNode{
sendRoutes := [][]*node.HarnessNode{
{mts.carol, mts.bob},
{mts.dave, mts.bob},
{mts.carol, mts.eve, mts.bob},
Expand Down Expand Up @@ -662,7 +629,7 @@ func testSendToRouteAMP(ht *lntest.HarnessTest) {

// Finally, assert that the proper set id is recorded for each htlc, and
// that the preimage hash pair is valid.
require.Equal(ht, numShards, len(rpcInvoice.Htlcs))
require.Equal(ht, 3, len(rpcInvoice.Htlcs))
for _, htlc := range rpcInvoice.Htlcs {
require.NotNil(ht, htlc.Amp)
require.Equal(ht, setID, htlc.Amp.SetId)
Expand Down
16 changes: 16 additions & 0 deletions itest/lnd_channel_force_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,22 @@ func runChannelForceClosureTest(ht *lntest.HarnessTest,
"sweep transaction not spending from commit")
}

// For neutrino backend, due to it has no mempool, we need to check the
// sweep tx has already been saved to db before restarting. This is due
// to the possible race,
// - the fee bumper returns a TxPublished event, which is received by
// the sweeper and the sweep tx is saved to db.
// - the sweeper receives a shutdown signal before it receives the
// above event.
//
// TODO(yy): fix the above race.
if ht.IsNeutrinoBackend() {
// Check that we can find the commitment sweep in our set of
// known sweeps, using the simple transaction id ListSweeps
// output.
ht.AssertSweepFound(alice, sweepingTXID.String(), false, 0)
}

// Restart Alice to ensure that she resumes watching the finalized
// commitment sweep txid.
ht.RestartNode(alice)
Expand Down
6 changes: 3 additions & 3 deletions itest/lnd_channel_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,17 @@ func testUnannouncedChannels(ht *lntest.HarnessTest) {
ht.WaitForChannelOpenEvent(chanOpenUpdate)

// Alice should have 1 edge in her graph.
ht.AssertNumActiveEdges(alice, 1, true)
ht.AssertNumEdges(alice, 1, true)

// Channels should not be announced yet, hence Alice should have no
// announced edges in her graph.
ht.AssertNumActiveEdges(alice, 0, false)
ht.AssertNumEdges(alice, 0, false)

// Mine 4 more blocks, and check that the channel is now announced.
ht.MineBlocks(4)

// Give the network a chance to learn that auth proof is confirmed.
ht.AssertNumActiveEdges(alice, 1, false)
ht.AssertNumEdges(alice, 1, false)
}

func testGraphTopologyNotifications(ht *lntest.HarnessTest) {
Expand Down
3 changes: 2 additions & 1 deletion itest/lnd_estimate_route_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/routing"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -376,7 +377,7 @@ func runFeeEstimationTestCase(ht *lntest.HarnessTest,
)
feeReq = &routerrpc.RouteFeeRequest{
PaymentRequest: payReqs[0],
Timeout: 10,
Timeout: uint32(wait.PaymentTimeout.Seconds()),
}
} else {
feeReq = &routerrpc.RouteFeeRequest{
Expand Down
34 changes: 8 additions & 26 deletions itest/lnd_experimental_endorsement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lntest/rpc"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lntypes"
Expand All @@ -24,37 +25,18 @@ func testExperimentalEndorsement(ht *lntest.HarnessTest) {
// testEndorsement sets up a 5 hop network and tests propagation of
// experimental endorsement signals.
func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
alice := ht.NewNodeWithCoins("Alice", nil)
bob := ht.NewNodeWithCoins("Bob", nil)
carol := ht.NewNode(
"carol", []string{"--protocol.no-experimental-endorsement"},
cfg := node.CfgAnchor
carolCfg := append(
[]string{"--protocol.no-experimental-endorsement"}, cfg...,
)
dave := ht.NewNode("dave", nil)
eve := ht.NewNode("eve", nil)
cfgs := [][]string{cfg, cfg, carolCfg, cfg, cfg}

ht.EnsureConnected(alice, bob)
ht.EnsureConnected(bob, carol)
ht.EnsureConnected(carol, dave)
ht.EnsureConnected(dave, eve)

ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
ht.FundCoins(btcutil.SatoshiPerBitcoin, dave)
// Open and wait for channels.
const chanAmt = btcutil.Amount(300000)
p := lntest.OpenChannelParams{Amt: chanAmt}
reqs := []*lntest.OpenChannelRequest{
{Local: alice, Remote: bob, Param: p},
{Local: bob, Remote: carol, Param: p},
{Local: carol, Remote: dave, Param: p},
{Local: dave, Remote: eve, Param: p},
}
resp := ht.OpenMultiChannelsAsync(reqs)
_, cpBC, cpCD, cpDE := resp[0], resp[1], resp[2], resp[3]

// Make sure Alice is aware of Bob=>Carol=>Dave=>Eve channels.
ht.AssertChannelInGraph(alice, cpBC)
ht.AssertChannelInGraph(alice, cpCD)
ht.AssertChannelInGraph(alice, cpDE)
_, nodes := ht.CreateSimpleNetwork(cfgs, p)
alice, bob, carol, dave, eve := nodes[0], nodes[1], nodes[2], nodes[3],
nodes[4]

bobIntercept, cancelBob := bob.RPC.HtlcInterceptor()
defer cancelBob()
Expand Down
Loading

0 comments on commit 4db3060

Please sign in to comment.