lntest/itest/lnd_test: wait when calling OpenChannel

In #4130, OpenChannel was changed to assert that the wallet is fully
synced before allowing a channel open. This introduced flakes on travis,
which are resolved here by using a wait predicate when calling
OpenChannel.

Note there is one existing call that was not converted, because it is
interested in the returned error. This call does not have a wait
predicate surrounding it, but this shouldn't cause a flake because other
channels are opened earlier in the test that will have already waited
for the wallet to sync up.
This commit is contained in:
Conner Fromknecht 2020-04-02 14:29:50 -07:00
parent c14d99f05d
commit ae41623a91
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -205,14 +205,14 @@ func mineBlocks(t *harnessTest, net *lntest.NetworkHarness,
return blocks return blocks
} }
// openChannelAndAssert attempts to open a channel with the specified // openChannelStream blocks until an OpenChannel request for a channel funding
// parameters extended from Alice to Bob. Additionally, two items are asserted // by alice succeeds. If it does, a stream client is returned to receive events
// after the channel is considered open: the funding transaction should be // about the opening channel.
// found within a block, and that Alice can report the status of the new func openChannelStream(ctx context.Context, t *harnessTest,
// channel.
func openChannelAndAssert(ctx context.Context, t *harnessTest,
net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode, net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode,
p lntest.OpenChannelParams) *lnrpc.ChannelPoint { p lntest.OpenChannelParams) lnrpc.Lightning_OpenChannelClient {
t.t.Helper()
// Wait until we are able to fund a channel successfully. This wait // Wait until we are able to fund a channel successfully. This wait
// prevents us from erroring out when trying to create a channel while // prevents us from erroring out when trying to create a channel while
@ -227,6 +227,22 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest,
t.Fatalf("unable to open channel: %v", err) t.Fatalf("unable to open channel: %v", err)
} }
return chanOpenUpdate
}
// openChannelAndAssert attempts to open a channel with the specified
// parameters extended from Alice to Bob. Additionally, two items are asserted
// after the channel is considered open: the funding transaction should be
// found within a block, and that Alice can report the status of the new
// channel.
func openChannelAndAssert(ctx context.Context, t *harnessTest,
net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode,
p lntest.OpenChannelParams) *lnrpc.ChannelPoint {
t.t.Helper()
chanOpenUpdate := openChannelStream(ctx, t, net, alice, bob, p)
// Mine 6 blocks, then wait for Alice's node to notify us that the // Mine 6 blocks, then wait for Alice's node to notify us that the
// channel has been opened. The funding transaction should be found // channel has been opened. The funding transaction should be found
// within the first newly mined block. We mine 6 blocks so that in the // within the first newly mined block. We mine 6 blocks so that in the
@ -1353,23 +1369,20 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// Now, we'll connect her to Alice so that they can open a channel // Now, we'll connect her to Alice so that they can open a channel
// together. The funding flow should select Carol's unconfirmed output // together. The funding flow should select Carol's unconfirmed output
// as she doesn't have any other funds since it's a new node. // as she doesn't have any other funds since it's a new node.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, carol, net.Alice); err != nil { if err := net.ConnectNodes(ctxt, carol, net.Alice); err != nil {
t.Fatalf("unable to connect dave to alice: %v", err) t.Fatalf("unable to connect dave to alice: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanOpenUpdate, err := net.OpenChannel( chanOpenUpdate := openChannelStream(
ctxt, carol, net.Alice, ctxt, t, net, carol, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
SpendUnconfirmed: true, SpendUnconfirmed: true,
}, },
) )
if err != nil {
t.Fatalf("unable to open channel between carol and alice: %v",
err)
}
// Confirm the channel and wait for it to be recognized by both // Confirm the channel and wait for it to be recognized by both
// parties. Two transactions should be mined, the unconfirmed spend and // parties. Two transactions should be mined, the unconfirmed spend and
@ -5452,15 +5465,12 @@ func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel between Alice and Bob, ensuring the // Open a channel between Alice and Bob, ensuring the
// channel has been opened properly. // channel has been opened properly.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanOpenUpdate, err := net.OpenChannel( chanOpenUpdate := openChannelStream(
ctxt, net.Alice, net.Bob, ctxt, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: amount, Amt: amount,
}, },
) )
if err != nil {
t.Fatalf("unable to open channel: %v", err)
}
// Mine 2 blocks, and check that the channel is opened but not yet // Mine 2 blocks, and check that the channel is opened but not yet
// announced to the network. // announced to the network.
@ -5690,8 +5700,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect dave to alice: %v", err) t.Fatalf("unable to connect dave to alice: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanOpenUpdate, err := net.OpenChannel( chanOpenUpdate := openChannelStream(
ctxt, carol, net.Alice, ctxt, t, net, carol, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: true, Private: true,
@ -6870,15 +6880,12 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
openStreams := make([]lnrpc.Lightning_OpenChannelClient, maxPendingChannels) openStreams := make([]lnrpc.Lightning_OpenChannelClient, maxPendingChannels)
for i := 0; i < maxPendingChannels; i++ { for i := 0; i < maxPendingChannels; i++ {
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
stream, err := net.OpenChannel( stream := openChannelStream(
ctxt, net.Alice, carol, ctxt, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: amount, Amt: amount,
}, },
) )
if err != nil {
t.Fatalf("unable to open channel: %v", err)
}
openStreams[i] = stream openStreams[i] = stream
} }