itest: fix flake in update_channel_status itest

This commit fixes a flake in the channel status update itest that
occurred if Carol got a channel edge update for a channel before it
heard of the channel in the first place. To avoid that, we wait for
Carol to sync her graph before sending out channel edge or policy
updates.

As always when we touch itest code, we bring the formatting and use of
the require library up to date.
This commit is contained in:
Oliver Gugger committed 2021-09-29 17:50:01 +02:00
1 parent 6240851f93
commit 493262e253
1 file changed
+50 -62
+50 -62
View File
@@ -25,24 +25,20 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
// Create two fresh nodes and open a channel between them. // Create two fresh nodes and open a channel between them.
alice := net.NewNode( alice := net.NewNode(t.t, "Alice", []string{
t.t, "Alice", []string{ "--minbackoff=10s",
"--minbackoff=10s", "--chan-enable-timeout=1.5s",
"--chan-enable-timeout=1.5s", "--chan-disable-timeout=3s",
"--chan-disable-timeout=3s", "--chan-status-sample-interval=.5s",
"--chan-status-sample-interval=.5s", })
},
)
defer shutdownAndAssert(net, t, alice) defer shutdownAndAssert(net, t, alice)
bob := net.NewNode( bob := net.NewNode(t.t, "Bob", []string{
t.t, "Bob", []string{ "--minbackoff=10s",
"--minbackoff=10s", "--chan-enable-timeout=1.5s",
"--chan-enable-timeout=1.5s", "--chan-disable-timeout=3s",
"--chan-disable-timeout=3s", "--chan-status-sample-interval=.5s",
"--chan-status-sample-interval=.5s", })
},
)
defer shutdownAndAssert(net, t, bob) defer shutdownAndAssert(net, t, bob)
// Connect Alice to Bob. // Connect Alice to Bob.
@@ -55,36 +51,32 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// being the sole funder of the channel. // being the sole funder of the channel.
chanAmt := btcutil.Amount(100000) chanAmt := btcutil.Amount(100000)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
t, net, alice, bob, t, net, alice, bob, lntest.OpenChannelParams{
lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
// Wait for Alice and Bob to receive the channel edge from the // Wait for Alice and Bob to receive the channel edge from the
// funding manager. // funding manager.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { require.NoError(t.t, err, "alice didn't see the alice->bob channel")
t.Fatalf("alice didn't see the alice->bob channel before "+
"timeout: %v", err)
}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = bob.WaitForNetworkChannelOpen(ctxt, chanPoint) err = bob.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { require.NoError(t.t, err, "bob didn't see the alice->bob channel")
t.Fatalf("bob didn't see the bob->alice channel before "+
"timeout: %v", err)
}
// Launch a node for Carol which will connect to Alice and Bob in // Launch a node for Carol which will connect to Alice and Bob in order
// order to receive graph updates. This will ensure that the // to receive graph updates. This will ensure that the channel updates
// channel updates are propagated throughout the network. // are propagated throughout the network.
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
// Connect both Alice and Bob to the new node Carol, so she can sync her
// graph.
net.ConnectNodes(t.t, alice, carol) net.ConnectNodes(t.t, alice, carol)
net.ConnectNodes(t.t, bob, carol) net.ConnectNodes(t.t, bob, carol)
waitForGraphSync(t, carol)
// assertChannelUpdate checks that the required policy update has // assertChannelUpdate checks that the required policy update has
// happened on the given node. // happened on the given node.
@@ -109,12 +101,11 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
ChanPoint: chanPoint, ChanPoint: chanPoint,
Action: action, Action: action,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
_, err = node.RouterClient.UpdateChanStatus(ctxt, req) _, err = node.RouterClient.UpdateChanStatus(ctxt, req)
if err != nil { require.NoErrorf(t.t, err, "UpdateChanStatus")
t.Fatalf("unable to call UpdateChanStatus for %s's node: %v",
node.Name(), err)
}
} }
// assertEdgeDisabled ensures that a given node has the correct // assertEdgeDisabled ensures that a given node has the correct
@@ -122,26 +113,30 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
assertEdgeDisabled := func(node *lntest.HarnessNode, assertEdgeDisabled := func(node *lntest.HarnessNode,
chanPoint *lnrpc.ChannelPoint, disabled bool) { chanPoint *lnrpc.ChannelPoint, disabled bool) {
var predErr error outPoint, err := lntest.MakeOutpoint(chanPoint)
err = wait.Predicate(func() bool { require.NoError(t.t, err)
err = wait.NoError(func() error {
req := &lnrpc.ChannelGraphRequest{ req := &lnrpc.ChannelGraphRequest{
IncludeUnannounced: true, IncludeUnannounced: true,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
chanGraph, err := node.DescribeGraph(ctxt, req) chanGraph, err := node.DescribeGraph(ctxt, req)
if err != nil { if err != nil {
predErr = fmt.Errorf("unable to query node %v's graph: %v", node, err) return fmt.Errorf("unable to query node %v's "+
return false "graph: %v", node, err)
} }
numEdges := len(chanGraph.Edges) numEdges := len(chanGraph.Edges)
if numEdges != 1 { if numEdges != 1 {
predErr = fmt.Errorf("expected to find 1 edge in the graph, found %d", numEdges) return fmt.Errorf("expected to find 1 edge in "+
return false "the graph, found %d", numEdges)
} }
edge := chanGraph.Edges[0] edge := chanGraph.Edges[0]
if edge.ChanPoint != chanPoint.GetFundingTxidStr() { if edge.ChanPoint != outPoint.String() {
predErr = fmt.Errorf("expected chan_point %v, got %v", return fmt.Errorf("expected chan_point %v, "+
chanPoint.GetFundingTxidStr(), edge.ChanPoint) "got %v", outPoint, edge.ChanPoint)
} }
var policy *lnrpc.RoutingPolicy var policy *lnrpc.RoutingPolicy
if node.PubKeyStr == edge.Node1Pub { if node.PubKeyStr == edge.Node1Pub {
@@ -150,15 +145,14 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
policy = edge.Node2Policy policy = edge.Node2Policy
} }
if disabled != policy.Disabled { if disabled != policy.Disabled {
predErr = fmt.Errorf("expected policy.Disabled to be %v, "+ return fmt.Errorf("expected policy.Disabled "+
"but policy was %v", disabled, policy) "to be %v, but policy was %v", disabled,
return false policy)
} }
return true
return nil
}, defaultTimeout) }, defaultTimeout)
if err != nil { require.NoError(t.t, err)
t.Fatalf("%v", predErr)
}
} }
// When updating the state of the channel between Alice and Bob, we // When updating the state of the channel between Alice and Bob, we
@@ -193,9 +187,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// disconnections from automatically disabling the channel again // disconnections from automatically disabling the channel again
// (we don't want to clutter the network with channels that are // (we don't want to clutter the network with channels that are
// falsely advertised as enabled when they don't work). // falsely advertised as enabled when they don't work).
if err := net.DisconnectNodes(alice, bob); err != nil { require.NoError(t.t, net.DisconnectNodes(alice, bob))
t.Fatalf("unable to disconnect Alice from Bob: %v", err)
}
expectedPolicy.Disabled = true expectedPolicy.Disabled = true
assertChannelUpdate(alice, expectedPolicy) assertChannelUpdate(alice, expectedPolicy)
assertChannelUpdate(bob, expectedPolicy) assertChannelUpdate(bob, expectedPolicy)
@@ -217,9 +209,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
expectedPolicy.Disabled = true expectedPolicy.Disabled = true
assertChannelUpdate(alice, expectedPolicy) assertChannelUpdate(alice, expectedPolicy)
if err := net.DisconnectNodes(alice, bob); err != nil { require.NoError(t.t, net.DisconnectNodes(alice, bob))
t.Fatalf("unable to disconnect Alice from Bob: %v", err)
}
// Bob sends a "Disabled = true" update upon detecting the // Bob sends a "Disabled = true" update upon detecting the
// disconnect. // disconnect.
@@ -237,9 +227,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// note the asymmetry between manual enable and manual disable! // note the asymmetry between manual enable and manual disable!
assertEdgeDisabled(alice, chanPoint, true) assertEdgeDisabled(alice, chanPoint, true)
if err := net.DisconnectNodes(alice, bob); err != nil { require.NoError(t.t, net.DisconnectNodes(alice, bob))
t.Fatalf("unable to disconnect Alice from Bob: %v", err)
}
// Bob sends a "Disabled = true" update upon detecting the // Bob sends a "Disabled = true" update upon detecting the
// disconnect. // disconnect.