Merge pull request #4143 from cfromknecht/open-channel-flakes

lntest/itest/lnd_test: wait when calling OpenChannel
This commit is contained in:
Olaoluwa Osuntokun 2020-04-03 18:10:45 -07:00 committed by GitHub
commit a8a0aaa214
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
@ -1395,23 +1411,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
@ -5529,15 +5542,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.
@ -5767,8 +5777,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,
@ -6947,15 +6957,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
} }