From 940d0735f8a65238ffc7ad4a80770dee202366bf Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 9 Aug 2018 10:03:13 +0200 Subject: [PATCH] lnd_test: use dave to listen for ChannelUpdates in testSendUpdateDisableChannel This commit changes the test testSendUpdateDisableChannel to use Dave to listen for channel updates, as was originally intended. Since a ChannelUpdate won't propagate in the network if the channel is already closed (if the closing transaction has been mined), we change the closing procedure to initiate the closing process, wait for the ChannelUpdates, then finally mining the closing transaction. This avoids a propagation race between the mined block and the ChannelUpdate. --- lnd_test.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 82dd6a6d..e08374f8 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -10925,7 +10925,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) { t.Fatalf("unable to connect bob to dave: %v", err) } - daveUpdates, quit := subscribeGraphNotifications(t, ctxb, net.Alice) + daveUpdates, quit := subscribeGraphNotifications(t, ctxb, dave) defer close(quit) // We should expect to see a channel update with the default routing @@ -10940,16 +10940,30 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) { // Close Alice's channels with Bob and Carol cooperatively and // unilaterally respectively. ctxt, _ = context.WithTimeout(ctxb, timeout) - closeChannelAndAssert(ctxt, t, net, net.Alice, chanPointAliceBob, false) - ctxt, _ = context.WithTimeout(ctxb, timeout) - closeChannelAndAssert(ctxt, t, net, net.Alice, chanPointAliceCarol, true) + _, _, err = net.CloseChannel(ctxt, net.Alice, chanPointAliceBob, false) + if err != nil { + t.Fatalf("unable to close channel: %v", err) + } - // Now that the channels have been closed, we should receive an update - // marking each as disabled. + ctxt, _ = context.WithTimeout(ctxb, timeout) + _, _, err = net.CloseChannel(ctxt, net.Alice, chanPointAliceCarol, true) + if err != nil { + t.Fatalf("unable to close channel: %v", err) + } + + // Now that the channel close processes have been started, we should + // receive an update marking each as disabled. waitForChannelUpdate( t, daveUpdates, net.Alice.PubKeyStr, expectedPolicy, chanPointAliceBob, chanPointAliceCarol, ) + + // Finally, close the channels by mining the closing transactions. + _, err = waitForNTxsInMempool(net.Miner.Node, 2, timeout) + if err != nil { + t.Fatalf("expected transactions not found in mempool: %v", err) + } + mineBlocks(t, net, 1) } type testCase struct {