From f73a2f362e6e35b8459e02b0f8b1f6e13e39433f Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 18 Jul 2018 15:55:59 +0200 Subject: [PATCH 1/2] lnd_test: correct that Bob can sweep immediately This commit fixes a flake within the integration tests, where we would mine a set of blocks before checking if Bob's sweep tx was in the mempool. Usually this would pass since the blocks were generated before the tx hit the miner's mempool, but sometimes it was mined and then we would check the mempool. This commit fixes this by correctly waiting immediately for Bob to sweep his funds, as they are not time locked. --- lnd_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 660d6a687..43d4d45df 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -8130,21 +8130,17 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness, t.Fatalf(predErr.Error()) } - // We'll mine csvDelay blocks in order to generate the sweep transaction - // of Bob's funding output. - if _, err := net.Miner.Node.Generate(csvDelay - 1); err != nil { - t.Fatalf("unable to generate blocks: %v", err) - } - - _, err = waitForTxInMempool(net.Miner.Node, 10*time.Second) + // Bob can sweep his output immediately. + _, err = waitForTxInMempool(net.Miner.Node, 20*time.Second) if err != nil { - t.Fatalf("unable to find bob's funding output sweep tx: %v", err) + t.Fatalf("unable to find bob's funding output sweep tx: %v", + err) } // Next, we'll mine enough blocks for the HTLC to expire. At this // point, Bob should hand off the output to his internal utxo nursery, // which will broadcast a sweep transaction. - if _, err := net.Miner.Node.Generate(finalCltvDelta - csvDelay - 1); err != nil { + if _, err := net.Miner.Node.Generate(finalCltvDelta - 1); err != nil { t.Fatalf("unable to generate blocks: %v", err) } From 45a1fa54d849282b03946d45a433d4177ee2dcb4 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 18 Jul 2018 13:37:53 +0200 Subject: [PATCH 2/2] lnd_test: check close status also for force closes This commit makes sure the channels that are force closed also are put into the state "waiting close" before the commitment transaction is confirmed, and exits this state when it confirms. This was previously not checked, as this check was added before the "waiting close" state was introduced. --- lnd_test.go | 68 +++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 43d4d45df..dae99f566 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -220,25 +220,23 @@ func closeChannelAndAssert(ctx context.Context, t *harnessTest, } chanPointStr := fmt.Sprintf("%v:%v", txid, fundingChanPoint.OutputIndex) - // If we didn't force close the transaction, at this point, the channel - // should now be marked as being in the state of "waiting close". - if !force { - pendingChansRequest := &lnrpc.PendingChannelsRequest{} - pendingChanResp, err := node.PendingChannels(ctx, pendingChansRequest) - if err != nil { - t.Fatalf("unable to query for pending channels: %v", err) - } - var found bool - for _, pendingClose := range pendingChanResp.WaitingCloseChannels { - if pendingClose.Channel.ChannelPoint == chanPointStr { - found = true - break - } - } - if !found { - t.Fatalf("channel not marked as waiting close") + // At this point, the channel should now be marked as being in the + // state of "waiting close". + pendingChansRequest := &lnrpc.PendingChannelsRequest{} + pendingChanResp, err := node.PendingChannels(ctx, pendingChansRequest) + if err != nil { + t.Fatalf("unable to query for pending channels: %v", err) + } + var found bool + for _, pendingClose := range pendingChanResp.WaitingCloseChannels { + if pendingClose.Channel.ChannelPoint == chanPointStr { + found = true + break } } + if !found { + t.Fatalf("channel not marked as waiting close") + } // We'll now, generate a single block, wait for the final close status // update, then ensure that the closing transaction was included in the @@ -254,28 +252,26 @@ func closeChannelAndAssert(ctx context.Context, t *harnessTest, // Finally, the transaction should no longer be in the waiting close // state as we've just mined a block that should include the closing - // transaction. This only applies for co-op close channels though. - if !force { - err = lntest.WaitPredicate(func() bool { - pendingChansRequest := &lnrpc.PendingChannelsRequest{} - pendingChanResp, err := node.PendingChannels( - ctx, pendingChansRequest, - ) - if err != nil { + // transaction. + err = lntest.WaitPredicate(func() bool { + pendingChansRequest := &lnrpc.PendingChannelsRequest{} + pendingChanResp, err := node.PendingChannels( + ctx, pendingChansRequest, + ) + if err != nil { + return false + } + + for _, pendingClose := range pendingChanResp.WaitingCloseChannels { + if pendingClose.Channel.ChannelPoint == chanPointStr { return false } - - for _, pendingClose := range pendingChanResp.WaitingCloseChannels { - if pendingClose.Channel.ChannelPoint == chanPointStr { - return false - } - } - - return true - }, time.Second*15) - if err != nil { - t.Fatalf("closing transaction not marked as fully closed") } + + return true + }, time.Second*15) + if err != nil { + t.Fatalf("closing transaction not marked as fully closed") } return closingTxid