Skip to content

Commit

Permalink
Merge pull request lightningnetwork#9248 from yyforyongyu/fix-itest
Browse files Browse the repository at this point in the history
lntest: fix edge assertion and reset min relay fee
  • Loading branch information
yyforyongyu authored Nov 11, 2024
2 parents 5a8026a + 7dd9a17 commit 4f6b510
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 128 deletions.
30 changes: 14 additions & 16 deletions itest/lnd_channel_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,23 @@ import (
// thus a following operation will fail if it relies on the channel being
// enabled.
func testUpdateChanStatus(ht *lntest.HarnessTest) {
// Create two fresh nodes and open a channel between them.
alice, bob := ht.Alice, ht.Bob
args := []string{
// Prepare params.
chanAmt := btcutil.Amount(100_000)
openChannelParams := lntest.OpenChannelParams{
Amt: chanAmt,
}
cfg := []string{
"--minbackoff=60s",
"--chan-enable-timeout=3s",
"--chan-disable-timeout=6s",
"--chan-status-sample-interval=0.5s",
}
ht.RestartNodeWithExtraArgs(alice, args)
ht.RestartNodeWithExtraArgs(bob, args)
ht.EnsureConnected(alice, bob)
cfgs := [][]string{cfg, cfg}

// Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel.
chanAmt := btcutil.Amount(100000)
chanPoint := ht.OpenChannel(
alice, bob, lntest.OpenChannelParams{Amt: chanAmt},
)
defer ht.CloseChannel(alice, chanPoint)
// Create two fresh nodes and open a channel between them.
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)
chanPoint := chanPoints[0]
alice, bob := nodes[0], nodes[1]

// assertEdgeDisabled ensures that Alice has the correct Disabled state
// for given channel from her DescribeGraph.
Expand Down Expand Up @@ -237,17 +235,17 @@ func testUnannouncedChannels(ht *lntest.HarnessTest) {
fundingChanPoint := ht.WaitForChannelOpenEvent(chanOpenUpdate)

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

// Channels should not be announced yet, hence Alice should have no
// announced edges in her graph.
ht.AssertNumEdges(alice, 0, false)
ht.AssertNumActiveEdges(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.AssertNumEdges(alice, 1, false)
ht.AssertNumActiveEdges(alice, 1, false)

// Close the channel used during the test.
ht.CloseChannel(alice, fundingChanPoint)
Expand Down
7 changes: 4 additions & 3 deletions itest/lnd_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1421,9 +1421,10 @@ func testSendSelectedCoinsChannelReserve(ht *lntest.HarnessTest) {
// Create a two-hop network: Alice -> Bob.
//
// NOTE: Alice will have one UTXO after the funding.
_, nodes := createSimpleNetwork(
ht, []string{"--protocol.anchors"}, 2,
lntest.OpenChannelParams{
cfg := []string{"--protocol.anchors"}
cfgs := [][]string{cfg, cfg}
_, nodes := ht.CreateSimpleNetwork(
cfgs, lntest.OpenChannelParams{
Amt: chanAmt,
},
)
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_mpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (m *mppTestScenario) openChannels(r *mppOpenChannelRequest) {
}

// Each node should have exactly 6 edges.
m.ht.AssertNumEdges(hn, len(m.channelPoints), false)
m.ht.AssertNumActiveEdges(hn, len(m.channelPoints), false)
}
}

Expand Down
4 changes: 2 additions & 2 deletions itest/lnd_open_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {
ht.AssertTopologyChannelOpen(bob, chanPoint)

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

// Now we disconnect Alice's chain backend from the original miner, and
// connect the two miners together. Since the temporary miner knows
Expand Down Expand Up @@ -112,7 +112,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {

// Since the fundingtx was reorged out, Alice should now have no edges
// in her graph.
ht.AssertNumEdges(alice, 0, true)
ht.AssertNumActiveEdges(alice, 0, true)

// Cleanup by mining the funding tx again, then closing the channel.
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
Expand Down
9 changes: 6 additions & 3 deletions itest/lnd_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ func testPaymentSucceededHTLCRemoteSwept(ht *lntest.HarnessTest) {
openChannelParams := lntest.OpenChannelParams{
Amt: chanAmt,
}
cfgs := [][]string{nil, nil}

// Create a two hop network: Alice -> Bob.
chanPoints, nodes := createSimpleNetwork(ht, nil, 2, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)
chanPoint := chanPoints[0]
alice, bob := nodes[0], nodes[1]

Expand Down Expand Up @@ -197,9 +198,10 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
openChannelParams := lntest.OpenChannelParams{
Amt: chanAmt,
}
cfgs := [][]string{nil, nil}

// Create a two hop network: Alice -> Bob.
chanPoints, nodes := createSimpleNetwork(ht, nil, 2, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)
chanPoint := chanPoints[0]
alice, bob := nodes[0], nodes[1]

Expand Down Expand Up @@ -1247,9 +1249,10 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
openChannelParams := lntest.OpenChannelParams{
Amt: chanAmt,
}
cfgs := [][]string{nil, nil}

// Create a two hop network: Alice -> Bob.
chanPoints, nodes := createSimpleNetwork(ht, nil, 2, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)
chanPoint := chanPoints[0]
alice, bob := nodes[0], nodes[1]

Expand Down
6 changes: 3 additions & 3 deletions itest/lnd_route_blinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ func testMPPToSingleBlindedPath(ht *lntest.HarnessTest) {
}

// Each node should have exactly numPublic edges.
ht.AssertNumEdges(hn, numPublic, false)
ht.AssertNumActiveEdges(hn, numPublic, false)
}

// Make Dave create an invoice with a blinded path for Alice to pay.
Expand Down Expand Up @@ -1156,7 +1156,7 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
}

// Each node should have exactly 5 edges.
ht.AssertNumEdges(hn, len(channelPoints), false)
ht.AssertNumActiveEdges(hn, len(channelPoints), false)
}

// Make Dave create an invoice with a blinded path for Alice to pay.
Expand Down Expand Up @@ -1325,7 +1325,7 @@ func testMPPToMultipleBlindedPaths(ht *lntest.HarnessTest) {
}

// Each node should have exactly 5 edges.
ht.AssertNumEdges(hn, len(channelPoints), false)
ht.AssertNumActiveEdges(hn, len(channelPoints), false)
}

// Ok now make a payment that must be split to succeed.
Expand Down
17 changes: 9 additions & 8 deletions itest/lnd_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,12 @@ func testPrivateChannels(ht *lntest.HarnessTest) {

// Carol and Alice should know about 4, while Bob and Dave should only
// know about 3, since one channel is private.
ht.AssertNumEdges(alice, 4, true)
ht.AssertNumEdges(alice, 3, false)
ht.AssertNumEdges(bob, 3, true)
ht.AssertNumEdges(carol, 4, true)
ht.AssertNumEdges(carol, 3, false)
ht.AssertNumEdges(dave, 3, true)
ht.AssertNumActiveEdges(alice, 4, true)
ht.AssertNumActiveEdges(alice, 3, false)
ht.AssertNumActiveEdges(bob, 3, true)
ht.AssertNumActiveEdges(carol, 4, true)
ht.AssertNumActiveEdges(carol, 3, false)
ht.AssertNumActiveEdges(dave, 3, true)

// Close all channels.
ht.CloseChannel(alice, chanPointAlice)
Expand Down Expand Up @@ -1525,8 +1525,9 @@ func testRouteFeeCutoff(ht *lntest.HarnessTest) {
func testFeeLimitAfterQueryRoutes(ht *lntest.HarnessTest) {
// Create a three hop network: Alice -> Bob -> Carol.
chanAmt := btcutil.Amount(100000)
chanPoints, nodes := createSimpleNetwork(
ht, []string{}, 3, lntest.OpenChannelParams{Amt: chanAmt},
cfgs := [][]string{nil, nil, nil}
chanPoints, nodes := ht.CreateSimpleNetwork(
cfgs, lntest.OpenChannelParams{Amt: chanAmt},
)
alice, bob, carol := nodes[0], nodes[1], nodes[2]
chanPointAliceBob, chanPointBobCarol := chanPoints[0], chanPoints[1]
Expand Down
80 changes: 14 additions & 66 deletions itest/lnd_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
// swept so we can focus on testing HTLCs.
fmt.Sprintf("--bitcoin.defaultremotedelay=%v", cltvDelta*10),
}
cfgs := [][]string{cfg, cfg, cfg}

openChannelParams := lntest.OpenChannelParams{
Amt: invoiceAmt * 10,
}

// Create a three hop network: Alice -> Bob -> Carol.
chanPoints, nodes := createSimpleNetwork(ht, cfg, 3, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)

// Unwrap the results.
abChanPoint, bcChanPoint := chanPoints[0], chanPoints[1]
Expand Down Expand Up @@ -426,12 +428,14 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
// swept so we can focus on testing HTLCs.
fmt.Sprintf("--bitcoin.defaultremotedelay=%v", cltvDelta*10),
}
cfgs := [][]string{cfg, cfg, cfg}

openChannelParams := lntest.OpenChannelParams{
Amt: invoiceAmt * 10,
}

// Create a three hop network: Alice -> Bob -> Carol.
chanPoints, nodes := createSimpleNetwork(ht, cfg, 3, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)

// Unwrap the results.
abChanPoint, bcChanPoint := chanPoints[0], chanPoints[1]
Expand Down Expand Up @@ -771,12 +775,14 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// swept so we can focus on testing HTLCs.
fmt.Sprintf("--bitcoin.defaultremotedelay=%v", cltvDelta*10),
}
cfgs := [][]string{cfg, cfg, cfg}

openChannelParams := lntest.OpenChannelParams{
Amt: invoiceAmt * 10,
}

// Create a three hop network: Alice -> Bob -> Carol.
chanPoints, nodes := createSimpleNetwork(ht, cfg, 3, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)

// Unwrap the results.
abChanPoint, bcChanPoint := chanPoints[0], chanPoints[1]
Expand Down Expand Up @@ -1298,13 +1304,15 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
fmt.Sprintf("--sweeper.nodeadlineconftarget=%v", deadline),
fmt.Sprintf("--bitcoin.defaultremotedelay=%v", toLocalCSV),
}
cfgs := [][]string{cfg, cfg}

openChannelParams := lntest.OpenChannelParams{
Amt: fundAmt,
PushAmt: bobBalance,
}

// Create a two hop network: Alice -> Bob.
chanPoints, nodes := createSimpleNetwork(ht, cfg, 2, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)

// Unwrap the results.
chanPoint := chanPoints[0]
Expand Down Expand Up @@ -1780,67 +1788,6 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
ht.MineBlocksAndAssertNumTxes(1, 2)
}

// createSimpleNetwork creates the specified number of nodes and makes a
// topology of `node1 -> node2 -> node3...`. Each node is created using the
// specified config, the neighbors are connected, and the channels are opened.
// Each node will be funded with a single UTXO of 1 BTC except the last one.
func createSimpleNetwork(ht *lntest.HarnessTest, nodeCfg []string,
numNodes int, p lntest.OpenChannelParams) ([]*lnrpc.ChannelPoint,
[]*node.HarnessNode) {

// Make a slice of nodes.
nodes := make([]*node.HarnessNode, numNodes)

// Create new nodes.
for i := range nodes {
nodeName := fmt.Sprintf("Node%q", string(rune('A'+i)))
n := ht.NewNode(nodeName, nodeCfg)
nodes[i] = n
}

// Connect the nodes in a chain.
for i := 1; i < len(nodes); i++ {
nodeA := nodes[i-1]
nodeB := nodes[i]
ht.EnsureConnected(nodeA, nodeB)
}

// Fund all the nodes expect the last one.
for i := 0; i < len(nodes)-1; i++ {
node := nodes[i]
ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, node)
}

// Mine 1 block to get the above coins confirmed.
ht.MineBlocksAndAssertNumTxes(1, numNodes-1)

// Open channels in batch to save blocks mined.
reqs := make([]*lntest.OpenChannelRequest, 0, len(nodes)-1)
for i := 0; i < len(nodes)-1; i++ {
nodeA := nodes[i]
nodeB := nodes[i+1]

req := &lntest.OpenChannelRequest{
Local: nodeA,
Remote: nodeB,
Param: p,
}
reqs = append(reqs, req)
}
resp := ht.OpenMultiChannelsAsync(reqs)

// Make sure the nodes know each other's channels if they are public.
if !p.Private {
for _, node := range nodes {
for _, chanPoint := range resp {
ht.AssertTopologyChannelOpen(node, chanPoint)
}
}
}

return resp, nodes
}

// testBumpFee checks that when a new input is requested, it's first bumped via
// CPFP, then RBF. Along the way, we check the `BumpFee` can properly update
// the fee function used by supplying new params.
Expand Down Expand Up @@ -2185,9 +2132,10 @@ func testBumpForceCloseFee(ht *lntest.HarnessTest) {
cfg := []string{
"--protocol.anchors",
}
cfgs := [][]string{cfg, cfg}

// Create a two hop network: Alice -> Bob.
chanPoints, nodes := createSimpleNetwork(ht, cfg, 2, openChannelParams)
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)

// Unwrap the results.
chanPoint := chanPoints[0]
Expand Down
Loading

0 comments on commit 4f6b510

Please sign in to comment.