lnd test: fix csv mempool sweep time

Since CSV locked outputs specifies the first block where they are
allowed to be included, they can actually be added one block earlier
into the mempool.

This led to a flake, where the sweep tx was already in the mempool at
the time we mined the last block, causing the next mempool check to
fail.
This commit is contained in:
Johan T. Halseth 2019-12-17 15:28:44 +01:00
parent f0bd4e775b
commit 7044219f90
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -3186,10 +3186,10 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Currently within the codebase, the default CSV is 4 relative blocks. // Currently within the codebase, the default CSV is 4 relative blocks.
// For the persistence test, we generate three blocks, then trigger // For the persistence test, we generate two blocks, then trigger
// a restart and then generate the final block that should trigger // a restart and then generate the final block that should trigger
// the creation of the sweep transaction. // the creation of the sweep transaction.
if _, err := net.Miner.Node.Generate(defaultCSV - 1); err != nil { if _, err := net.Miner.Node.Generate(defaultCSV - 2); err != nil {
t.Fatalf("unable to mine blocks: %v", err) t.Fatalf("unable to mine blocks: %v", err)
} }
@ -3225,12 +3225,12 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
} }
// At this point, the nursery should show that the commitment // At this point, the nursery should show that the commitment
// output has 1 block left before its CSV delay expires. In // output has 2 block left before its CSV delay expires. In
// total, we have mined exactly defaultCSV blocks, so the htlc // total, we have mined exactly defaultCSV blocks, so the htlc
// outputs should also reflect that this many blocks have // outputs should also reflect that this many blocks have
// passed. // passed.
err = checkCommitmentMaturity( err = checkCommitmentMaturity(
forceClose, commCsvMaturityHeight, 1, forceClose, commCsvMaturityHeight, 2,
) )
if err != nil { if err != nil {
return err return err
@ -3258,9 +3258,9 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to mine blocks: %v", err) t.Fatalf("unable to mine blocks: %v", err)
} }
// At this point, the sweeping transaction should now be broadcast. So // At this point, the CSV will expire in the next block, meaning that
// we fetch the node's mempool to ensure it has been properly // the sweeping transaction should now be broadcast. So we fetch the
// broadcast. // node's mempool to ensure it has been properly broadcast.
sweepingTXID, err := waitForTxInMempool(net.Miner.Node, minerMempoolTimeout) sweepingTXID, err := waitForTxInMempool(net.Miner.Node, minerMempoolTimeout)
if err != nil { if err != nil {
t.Fatalf("failed to get sweep tx from mempool: %v", err) t.Fatalf("failed to get sweep tx from mempool: %v", err)
@ -3361,7 +3361,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
// of blocks we have generated since adding it to the nursery, and take // of blocks we have generated since adding it to the nursery, and take
// an additional block off so that we end up one block shy of the expiry // an additional block off so that we end up one block shy of the expiry
// height, and add the block padding. // height, and add the block padding.
cltvHeightDelta := padCLTV(defaultCLTV - defaultCSV - 2 - 1) cltvHeightDelta := padCLTV(defaultCLTV - defaultCSV - 1 - 1)
// Advance the blockchain until just before the CLTV expires, nothing // Advance the blockchain until just before the CLTV expires, nothing
// exciting should have happened during this time. // exciting should have happened during this time.