itest: reduce blocks mined to save sync time

This commit is contained in:
yyforyongyu committed 2022-10-27 01:11:33 +08:00
1 parent b463147595
commit c3bc4d403c
11 files changed
+46 -29

No files matched your search

+23 -2
View File
@@ -292,10 +292,22 @@ func (h *HarnessTest) Subtest(t *testing.T) (*HarnessTest, func()) {
// Inherit context from the main test. // Inherit context from the main test.
st.runCtx, st.cancel = context.WithCancel(h.runCtx) st.runCtx, st.cancel = context.WithCancel(h.runCtx)
// Inherit the subtest for the miner.
st.Miner.T = st.T
// Reset the standby nodes. // Reset the standby nodes.
st.resetStandbyNodes(t) st.resetStandbyNodes(t)
// Record block height.
_, startHeight := h.Miner.GetBestBlock()
cleanup := func() { 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. // Don't bother run the cleanups if the test is failed.
if st.Failed() { if st.Failed() {
st.Log("test failed, skipped cleanup") st.Log("test failed, skipped cleanup")
@@ -920,10 +932,10 @@ func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode,
return 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 // sufficient number of confirmations and wait for the balance to
// reflect what's expected. // reflect what's expected.
h.Miner.MineBlocks(2) h.Miner.MineBlocks(1)
expectedBalance := btcutil.Amount(initialBalance.ConfirmedBalance) + amt expectedBalance := btcutil.Amount(initialBalance.ConfirmedBalance) + amt
h.WaitForBalanceConfirmed(target, expectedBalance) 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) 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 // CompletePaymentRequests sends payments from a node to complete all payment
// requests. This function does not return until all payments successfully // requests. This function does not return until all payments successfully
// complete without errors. // complete without errors.
+2 -2
View File
@@ -990,7 +990,7 @@ func testChanRestoreScenario(ht *lntemp.HarnessTest,
var fundingShim *lnrpc.FundingShim var fundingShim *lnrpc.FundingShim
if testCase.commitmentType == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE { if testCase.commitmentType == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
_, minerHeight := ht.Miner.GetBestBlock() _, minerHeight := ht.Miner.GetBestBlock()
thawHeight := uint32(minerHeight + 144) thawHeight := uint32(minerHeight + thawHeightDelta)
fundingShim, _, _ = deriveFundingShim( fundingShim, _, _ = deriveFundingShim(
ht, from, to, chanAmt, thawHeight, true, 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 // The commit sweep resolver publishes the sweep tx at defaultCSV-1 and
// we already mined one block after the commitment was published, so // we already mined one block after the commitment was published, so
// take that into account. // take that into account.
ht.Miner.MineBlocks(defaultCSV - 1 - 1) ht.MineBlocksAssertNodesSync(defaultCSV - 1 - 1)
daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0] daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0] block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, daveSweep) ht.Miner.AssertTxInBlock(block, daveSweep)
@@ -23,8 +23,6 @@ import (
func testMultiHopHtlcAggregation(ht *lntemp.HarnessTest, func testMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
alice, bob *node.HarnessNode, c lnrpc.CommitmentType, zeroConf bool) { alice, bob *node.HarnessNode, c lnrpc.CommitmentType, zeroConf bool) {
const finalCltvDelta = 40
// First, we'll create a three hop network: Alice -> Bob -> Carol. // First, we'll create a three hop network: Alice -> Bob -> Carol.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
ht, alice, bob, false, c, zeroConf, ht, alice, bob, false, c, zeroConf,
@@ -35,7 +35,7 @@ func testMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
payHash := preimage.Hash() payHash := preimage.Hash()
invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{
Value: invoiceAmt, Value: invoiceAmt,
CltvExpiry: 40, CltvExpiry: finalCltvDelta,
Hash: payHash[:], Hash: payHash[:],
} }
carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq)
@@ -30,9 +30,8 @@ func testMultiHopHtlcLocalTimeout(ht *lntemp.HarnessTest,
// to Carol. The first HTLC will be universally considered "dust", // to Carol. The first HTLC will be universally considered "dust",
// while the second will be a proper fully valued HTLC. // while the second will be a proper fully valued HTLC.
const ( const (
dustHtlcAmt = btcutil.Amount(100) dustHtlcAmt = btcutil.Amount(100)
htlcAmt = btcutil.Amount(300_000) htlcAmt = btcutil.Amount(300_000)
finalCltvDelta = 40
) )
// We'll create two random payment hashes unknown to carol, then send // We'll create two random payment hashes unknown to carol, then send
@@ -37,7 +37,7 @@ func testMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
payHash := preimage.Hash() payHash := preimage.Hash()
invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{
Value: invoiceAmt, Value: invoiceAmt,
CltvExpiry: 40, CltvExpiry: finalCltvDelta,
Hash: payHash[:], Hash: payHash[:],
} }
carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq)
@@ -36,7 +36,7 @@ func testMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
payHash := preimage.Hash() payHash := preimage.Hash()
invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{
Value: invoiceAmt, Value: invoiceAmt,
CltvExpiry: 40, CltvExpiry: finalCltvDelta,
Hash: payHash[:], Hash: payHash[:],
} }
carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq)
@@ -28,10 +28,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
// With our channels set up, we'll then send a single HTLC from Alice // 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 // to Carol. As Carol is in hodl mode, she won't settle this HTLC which
// opens up the base for out tests. // opens up the base for out tests.
const ( const htlcAmt = btcutil.Amount(300_000)
finalCltvDelta = 40
htlcAmt = btcutil.Amount(300_000)
)
// We'll now send a single HTLC across our multi-hop network. // We'll now send a single HTLC across our multi-hop network.
carolPubKey := carol.PubKey[:] carolPubKey := carol.PubKey[:]
@@ -30,10 +30,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
// With our channels set up, we'll then send a single HTLC from Alice // 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 // to Carol. As Carol is in hodl mode, she won't settle this HTLC which
// opens up the base for out tests. // opens up the base for out tests.
const ( const htlcAmt = btcutil.Amount(30000)
finalCltvDelta = 40
htlcAmt = btcutil.Amount(30000)
)
// We'll now send a single HTLC across our multi-hop network. // We'll now send a single HTLC across our multi-hop network.
var preimage lntypes.Preimage var preimage lntypes.Preimage
@@ -41,7 +38,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
payHash := preimage.Hash() payHash := preimage.Hash()
invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{ invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{
Value: int64(htlcAmt), Value: int64(htlcAmt),
CltvExpiry: 40, CltvExpiry: finalCltvDelta,
Hash: payHash[:], Hash: payHash[:],
} }
carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq) carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq)
+13 -4
View File
@@ -15,6 +15,12 @@ import (
"github.com/lightningnetwork/lnd/lntemp/rpc" "github.com/lightningnetwork/lnd/lntemp/rpc"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/routing"
)
const (
finalCltvDelta = routing.MinCLTVDelta // 18.
thawHeightDelta = finalCltvDelta * 2 // 36.
) )
func testMultiHopHtlcClaims(ht *lntemp.HarnessTest) { 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 // needs to be attached as an additional input. This can still lead to
// a positively-yielding transaction. // a positively-yielding transaction.
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
ht.FundCoins(btcutil.SatoshiPerBitcoin, alice) ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, alice)
ht.FundCoins(btcutil.SatoshiPerBitcoin, bob) ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, bob)
ht.FundCoins(btcutil.SatoshiPerBitcoin, carol) 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, // 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 var thawHeight uint32
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE { if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
_, minerHeight := ht.Miner.GetBestBlock() _, minerHeight := ht.Miner.GetBestBlock()
thawHeight = uint32(minerHeight + 144) thawHeight = uint32(minerHeight + thawHeightDelta)
aliceFundingShim, _, _ = deriveFundingShim( aliceFundingShim, _, _ = deriveFundingShim(
ht, alice, bob, chanAmt, thawHeight, true, ht, alice, bob, chanAmt, thawHeight, true,
) )
-4
View File
@@ -127,10 +127,6 @@ func TestLightningNetworkDaemonTemp(t *testing.T) {
break 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 // getTestCaseSplitTranche returns the sub slice of the test cases that should