diff --git a/lntemp/harness.go b/lntemp/harness.go index 92253be1c..36f5c64a1 100644 --- a/lntemp/harness.go +++ b/lntemp/harness.go @@ -292,10 +292,22 @@ func (h *HarnessTest) Subtest(t *testing.T) (*HarnessTest, func()) { // Inherit context from the main test. st.runCtx, st.cancel = context.WithCancel(h.runCtx) + // Inherit the subtest for the miner. + st.Miner.T = st.T + // Reset the standby nodes. st.resetStandbyNodes(t) + // Record block height. + _, startHeight := h.Miner.GetBestBlock() + cleanup := func() { + _, endHeight := h.Miner.GetBestBlock() + + st.Logf("finished test: %s, start height=%d, end height=%d, "+ + "mined blocks=%d", st.manager.currentTestCase, + startHeight, endHeight, endHeight-startHeight) + // Don't bother run the cleanups if the test is failed. if st.Failed() { st.Log("test failed, skipped cleanup") @@ -920,10 +932,10 @@ func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode, return } - // Otherwise, we'll generate 2 new blocks to ensure the output gains a + // Otherwise, we'll generate 1 new blocks to ensure the output gains a // sufficient number of confirmations and wait for the balance to // reflect what's expected. - h.Miner.MineBlocks(2) + h.Miner.MineBlocks(1) expectedBalance := btcutil.Amount(initialBalance.ConfirmedBalance) + amt h.WaitForBalanceConfirmed(target, expectedBalance) @@ -936,6 +948,15 @@ func (h *HarnessTest) FundCoins(amt btcutil.Amount, hn *node.HarnessNode) { h.fundCoins(amt, hn, lnrpc.AddressType_WITNESS_PUBKEY_HASH, true) } +// FundCoinsUnconfirmed attempts to send amt satoshis from the internal mining +// node to the targeted lightning node using a P2WKH address. No blocks are +// mined after and the UTXOs are unconfirmed. +func (h *HarnessTest) FundCoinsUnconfirmed(amt btcutil.Amount, + hn *node.HarnessNode) { + + h.fundCoins(amt, hn, lnrpc.AddressType_WITNESS_PUBKEY_HASH, false) +} + // CompletePaymentRequests sends payments from a node to complete all payment // requests. This function does not return until all payments successfully // complete without errors. diff --git a/lntest/itest/lnd_channel_backup_test.go b/lntest/itest/lnd_channel_backup_test.go index 7c244b790..489215adc 100644 --- a/lntest/itest/lnd_channel_backup_test.go +++ b/lntest/itest/lnd_channel_backup_test.go @@ -990,7 +990,7 @@ func testChanRestoreScenario(ht *lntemp.HarnessTest, var fundingShim *lnrpc.FundingShim if testCase.commitmentType == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE { _, minerHeight := ht.Miner.GetBestBlock() - thawHeight := uint32(minerHeight + 144) + thawHeight := uint32(minerHeight + thawHeightDelta) fundingShim, _, _ = deriveFundingShim( ht, from, to, chanAmt, thawHeight, true, @@ -1512,7 +1512,7 @@ func assertTimeLockSwept(ht *lntemp.HarnessTest, // The commit sweep resolver publishes the sweep tx at defaultCSV-1 and // we already mined one block after the commitment was published, so // take that into account. - ht.Miner.MineBlocks(defaultCSV - 1 - 1) + ht.MineBlocksAssertNodesSync(defaultCSV - 1 - 1) daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0] block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0] ht.Miner.AssertTxInBlock(block, daveSweep) diff --git a/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go b/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go index d023e385f..091ff4936 100644 --- a/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go @@ -23,8 +23,6 @@ import ( func testMultiHopHtlcAggregation(ht *lntemp.HarnessTest, alice, bob *node.HarnessNode, c lnrpc.CommitmentType, zeroConf bool) { - const finalCltvDelta = 40 - // First, we'll create a three hop network: Alice -> Bob -> Carol. aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( ht, alice, bob, false, c, zeroConf, diff --git a/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go b/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go index 716ec37cb..14054e876 100644 --- a/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go @@ -35,7 +35,7 @@ func testMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest, payHash := preimage.Hash() invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ Value: invoiceAmt, - CltvExpiry: 40, + CltvExpiry: finalCltvDelta, Hash: payHash[:], } carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) diff --git a/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go b/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go index edb2acc54..c1bf83d12 100644 --- a/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go @@ -30,9 +30,8 @@ func testMultiHopHtlcLocalTimeout(ht *lntemp.HarnessTest, // to Carol. The first HTLC will be universally considered "dust", // while the second will be a proper fully valued HTLC. const ( - dustHtlcAmt = btcutil.Amount(100) - htlcAmt = btcutil.Amount(300_000) - finalCltvDelta = 40 + dustHtlcAmt = btcutil.Amount(100) + htlcAmt = btcutil.Amount(300_000) ) // We'll create two random payment hashes unknown to carol, then send diff --git a/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go b/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go index a34713dc9..9a5567b3b 100644 --- a/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go @@ -37,7 +37,7 @@ func testMultiHopReceiverChainClaim(ht *lntemp.HarnessTest, payHash := preimage.Hash() invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ Value: invoiceAmt, - CltvExpiry: 40, + CltvExpiry: finalCltvDelta, Hash: payHash[:], } carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) diff --git a/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go b/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go index 7433493f6..75437c423 100644 --- a/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go @@ -36,7 +36,7 @@ func testMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest, payHash := preimage.Hash() invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ Value: invoiceAmt, - CltvExpiry: 40, + CltvExpiry: finalCltvDelta, Hash: payHash[:], } carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) diff --git a/lntest/itest/lnd_multi-hop_local_force_close_on_chain_htlc_timeout_test.go b/lntest/itest/lnd_multi-hop_local_force_close_on_chain_htlc_timeout_test.go index a97b6e125..82b00d4db 100644 --- a/lntest/itest/lnd_multi-hop_local_force_close_on_chain_htlc_timeout_test.go +++ b/lntest/itest/lnd_multi-hop_local_force_close_on_chain_htlc_timeout_test.go @@ -28,10 +28,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest, // With our channels set up, we'll then send a single HTLC from Alice // to Carol. As Carol is in hodl mode, she won't settle this HTLC which // opens up the base for out tests. - const ( - finalCltvDelta = 40 - htlcAmt = btcutil.Amount(300_000) - ) + const htlcAmt = btcutil.Amount(300_000) // We'll now send a single HTLC across our multi-hop network. carolPubKey := carol.PubKey[:] diff --git a/lntest/itest/lnd_multi-hop_remote_force_close_on_chain_htlc_timeout_test.go b/lntest/itest/lnd_multi-hop_remote_force_close_on_chain_htlc_timeout_test.go index 2d7bfc226..1767c3421 100644 --- a/lntest/itest/lnd_multi-hop_remote_force_close_on_chain_htlc_timeout_test.go +++ b/lntest/itest/lnd_multi-hop_remote_force_close_on_chain_htlc_timeout_test.go @@ -30,10 +30,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest, // With our channels set up, we'll then send a single HTLC from Alice // to Carol. As Carol is in hodl mode, she won't settle this HTLC which // opens up the base for out tests. - const ( - finalCltvDelta = 40 - htlcAmt = btcutil.Amount(30000) - ) + const htlcAmt = btcutil.Amount(30000) // We'll now send a single HTLC across our multi-hop network. var preimage lntypes.Preimage @@ -41,7 +38,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest, payHash := preimage.Hash() invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ Value: int64(htlcAmt), - CltvExpiry: 40, + CltvExpiry: finalCltvDelta, Hash: payHash[:], } carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) diff --git a/lntest/itest/lnd_multi-hop_test.go b/lntest/itest/lnd_multi-hop_test.go index b22410cd4..09b995237 100644 --- a/lntest/itest/lnd_multi-hop_test.go +++ b/lntest/itest/lnd_multi-hop_test.go @@ -15,6 +15,12 @@ import ( "github.com/lightningnetwork/lnd/lntemp/rpc" "github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/routing" +) + +const ( + finalCltvDelta = routing.MinCLTVDelta // 18. + thawHeightDelta = finalCltvDelta * 2 // 36. ) func testMultiHopHtlcClaims(ht *lntemp.HarnessTest) { @@ -280,9 +286,12 @@ func createThreeHopNetwork(ht *lntemp.HarnessTest, // needs to be attached as an additional input. This can still lead to // a positively-yielding transaction. for i := 0; i < 2; i++ { - ht.FundCoins(btcutil.SatoshiPerBitcoin, alice) - ht.FundCoins(btcutil.SatoshiPerBitcoin, bob) - ht.FundCoins(btcutil.SatoshiPerBitcoin, carol) + ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, alice) + ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, bob) + ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, carol) + + // Mine 1 block to get the above coins confirmed. + ht.MineBlocksAssertNodesSync(1) } // We'll start the test by creating a channel between Alice and Bob, @@ -292,7 +301,7 @@ func createThreeHopNetwork(ht *lntemp.HarnessTest, var thawHeight uint32 if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE { _, minerHeight := ht.Miner.GetBestBlock() - thawHeight = uint32(minerHeight + 144) + thawHeight = uint32(minerHeight + thawHeightDelta) aliceFundingShim, _, _ = deriveFundingShim( ht, alice, bob, chanAmt, thawHeight, true, ) diff --git a/lntest/itest/temp_lnd_test.go b/lntest/itest/temp_lnd_test.go index 48a617564..5af1c2df3 100644 --- a/lntest/itest/temp_lnd_test.go +++ b/lntest/itest/temp_lnd_test.go @@ -127,10 +127,6 @@ func TestLightningNetworkDaemonTemp(t *testing.T) { break } } - - _, height := harnessTest.Miner.GetBestBlock() - t.Logf("=========> tests finished for tranche: %v, tested %d "+ - "cases, end height: %d\n", trancheIndex, len(testCases), height) } // getTestCaseSplitTranche returns the sub slice of the test cases that should