Skip to content

Commit

Permalink
Merge pull request #9195 from yyforyongyu/optimize-itest-setup
Browse files Browse the repository at this point in the history
itest+lntest: speed up test setup
  • Loading branch information
guggero authored Oct 17, 2024
2 parents 6992ecc + 7849e63 commit f46ae2f
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 102 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@

* Log rotation can now use ZSTD

* [A new method](https://github.com/lightningnetwork/lnd/pull/9195)
`AssertTxnsNotInMempool` has been added to `lntest` package to allow batch
exclusion check in itest.

# Technical and Architectural Updates
## BOLT Spec Updates

Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_channel_force_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
// Recorf the HTLC outpoint, such that we can later
// check whether it gets swept
op := wire.OutPoint{
Hash: *htlcTxID,
Hash: htlcTxID,
Index: uint32(i),
}
htlcTxOutpointSet[op] = 0
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_coop_close_with_htlcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func coopCloseWithHTLCs(ht *lntest.HarnessTest) {
)

// Wait for the close tx to be in the Mempool.
ht.AssertTxInMempool(&closeTxid)
ht.AssertTxInMempool(closeTxid)

// Wait for it to get mined and finish tearing down.
ht.AssertStreamChannelCoopClosed(alice, chanPoint, false, closeClient)
Expand Down
6 changes: 3 additions & 3 deletions itest/lnd_funding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ func testChannelFundingPersistence(ht *lntest.HarnessTest) {
// channel has been opened. The funding transaction should be found
// within the newly mined block.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, fundingTxID)
ht.AssertTxInBlock(block, *fundingTxID)

// Get the height that our transaction confirmed at.
height := int32(ht.CurrentHeight())
Expand Down Expand Up @@ -1067,13 +1067,13 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {

// Mine the batch transaction and check the network topology.
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, txHash)
ht.AssertTxInBlock(block, *txHash)
ht.AssertTopologyChannelOpen(alice, chanPoint1)
ht.AssertTopologyChannelOpen(alice, chanPoint2)
ht.AssertTopologyChannelOpen(alice, chanPoint3)

// Check if the change type from the batch_open_channel funding is P2TR.
rawTx := ht.GetRawTransaction(txHash)
rawTx := ht.GetRawTransaction(*txHash)
require.Len(ht, rawTx.MsgTx().TxOut, 5)

// Check the fee rate of the batch-opening transaction. We expect slight
Expand Down
30 changes: 15 additions & 15 deletions itest/lnd_multi-hop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
ht.MineBlocksAndAssertNumTxes(1, 1)
blocksMined++

htlcOutpoint := wire.OutPoint{Hash: *closeTx, Index: 2}
bobCommitOutpoint := wire.OutPoint{Hash: *closeTx, Index: 3}
htlcOutpoint := wire.OutPoint{Hash: closeTx, Index: 2}
bobCommitOutpoint := wire.OutPoint{Hash: closeTx, Index: 3}

// Before the HTLC times out, we'll need to assert that Bob broadcasts
// a sweep transaction for his commit output. Note that if the channel
Expand All @@ -761,7 +761,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
)
txid := commitSweepTx.TxHash()
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &txid)
ht.AssertTxInBlock(block, txid)

blocksMined++
}
Expand Down Expand Up @@ -789,7 +789,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
// Next, we'll mine an additional block. This should serve to confirm
// the second layer timeout transaction.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &timeoutTx)
ht.AssertTxInBlock(block, timeoutTx)

// With the second layer timeout transaction confirmed, Bob should have
// canceled backwards the HTLC that carol sent.
Expand Down Expand Up @@ -1041,13 +1041,13 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
// Mine a block to trigger the sweep.
ht.MineEmptyBlocks(1)

bobCommitOutpoint := wire.OutPoint{Hash: *closeTx, Index: 3}
bobCommitOutpoint := wire.OutPoint{Hash: closeTx, Index: 3}
bobCommitSweep := ht.AssertOutpointInMempool(
bobCommitOutpoint,
)
bobCommitSweepTxid := bobCommitSweep.TxHash()
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &bobCommitSweepTxid)
ht.AssertTxInBlock(block, bobCommitSweepTxid)
}
ht.AssertNumPendingForceClose(bob, 0)

Expand Down Expand Up @@ -1226,7 +1226,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,

// Mine a block that should confirm the commit tx.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &closingTxid)
ht.AssertTxInBlock(block, closingTxid)

// After the force close transaction is mined, Carol should offer her
// second-level success HTLC tx and anchor to the sweeper.
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
bobSecondLvlTx := ht.GetNumTxsFromMempool(1)[0]

// It should spend from the commitment in the channel with Alice.
ht.AssertTxSpendFrom(bobSecondLvlTx, *bobForceClose)
ht.AssertTxSpendFrom(bobSecondLvlTx, bobForceClose)

// At this point, Bob should have broadcast his second layer success
// transaction, and should have sent it to the nursery for incubation.
Expand Down Expand Up @@ -1362,7 +1362,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
// Now Bob should have no pending channels anymore, as this just
// resolved it by the confirmation of the sweep transaction.
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &bobSweepTxid)
ht.AssertTxInBlock(block, bobSweepTxid)

// With the script-enforced lease commitment type, Alice and Bob still
// haven't been able to sweep their respective commit outputs due to the
Expand Down Expand Up @@ -1397,7 +1397,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,

// Both Alice and Bob show broadcast their commit sweeps.
aliceCommitOutpoint := wire.OutPoint{
Hash: *bobForceClose, Index: 3,
Hash: bobForceClose, Index: 3,
}
ht.AssertOutpointInMempool(
aliceCommitOutpoint,
Expand Down Expand Up @@ -1574,7 +1574,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,

// Mine a block, which should contain: the commitment.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &closingTxid)
ht.AssertTxInBlock(block, closingTxid)

// After the force close transaction is mined, Carol should offer her
// second level HTLC tx to the sweeper, along with her anchor output.
Expand Down Expand Up @@ -1628,12 +1628,12 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
bobHtlcSweepTxid := bobHtlcSweep.TxHash()

// It should spend from the commitment in the channel with Alice.
ht.AssertTxSpendFrom(bobHtlcSweep, *aliceForceClose)
ht.AssertTxSpendFrom(bobHtlcSweep, aliceForceClose)

// We'll now mine a block which should confirm Bob's HTLC sweep
// transaction.
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &bobHtlcSweepTxid)
ht.AssertTxInBlock(block, bobHtlcSweepTxid)
carolSecondLevelCSV--

// Now that the sweeping transaction has been confirmed, Bob should now
Expand Down Expand Up @@ -1690,7 +1690,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,

// Both Alice and Bob should broadcast their commit sweeps.
aliceCommitOutpoint := wire.OutPoint{
Hash: *aliceForceClose, Index: 3,
Hash: aliceForceClose, Index: 3,
}
ht.AssertOutpointInMempool(aliceCommitOutpoint)
bobCommitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
Expand Down Expand Up @@ -2145,7 +2145,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
// level sweep. Now Bob should have no pending channels anymore, as
// this just resolved it by the confirmation of the sweep transaction.
block := ht.MineBlocksAndAssertNumTxes(1, numExpected)[0]
ht.AssertTxInBlock(block, &bobSweep)
ht.AssertTxInBlock(block, bobSweep)

// For leased channels, we need to mine one more block to confirm Bob's
// commit output sweep.
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_nonstd_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func testNonStdSweepInner(ht *lntest.HarnessTest, address string) {
for _, inp := range msgTx.TxIn {
// Fetch the previous outpoint's value.
prevOut := inp.PreviousOutPoint
ptx := ht.GetRawTransaction(&prevOut.Hash)
ptx := ht.GetRawTransaction(prevOut.Hash)

pout := ptx.MsgTx().TxOut[prevOut.Index]
inputVal += int(pout.Value)
Expand Down
4 changes: 2 additions & 2 deletions itest/lnd_open_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {
// channel on the original miner's chain, which should be considered
// open.
block := ht.MineBlocksAndAssertNumTxes(10, 1)[0]
ht.AssertTxInBlock(block, fundingTxID)
ht.AssertTxInBlock(block, *fundingTxID)
_, err = tempMiner.Client.Generate(15)
require.NoError(ht, err, "unable to generate blocks")

Expand Down Expand Up @@ -116,7 +116,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {

// Cleanup by mining the funding tx again, then closing the channel.
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, fundingTxID)
ht.AssertTxInBlock(block, *fundingTxID)

ht.CloseChannel(alice, chanPoint)
}
Expand Down
16 changes: 8 additions & 8 deletions itest/lnd_psbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func runPsbtChanFunding(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,

txHash := finalTx.TxHash()
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, &txHash)
ht.AssertTxInBlock(block, txHash)
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertTopologyChannelOpen(carol, chanPoint2)

Expand Down Expand Up @@ -481,7 +481,7 @@ func runPsbtChanFundingExternal(ht *lntest.HarnessTest, carol,
// Now we can mine a block to get the transaction confirmed, then wait
// for the new channel to be propagated through the network.
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, &txHash)
ht.AssertTxInBlock(block, txHash)
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertTopologyChannelOpen(carol, chanPoint2)

Expand Down Expand Up @@ -638,7 +638,7 @@ func runPsbtChanFundingSingleStep(ht *lntest.HarnessTest, carol,

txHash := finalTx.TxHash()
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, &txHash)
ht.AssertTxInBlock(block, txHash)
ht.AssertTopologyChannelOpen(carol, chanPoint)

// Next, to make sure the channel functions as normal, we'll make some
Expand Down Expand Up @@ -1337,7 +1337,7 @@ func extractPublishAndMine(ht *lntest.HarnessTest, node *node.HarnessNode,
// Mine one block which should contain two transactions.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
txHash := finalTx.TxHash()
ht.AssertTxInBlock(block, &txHash)
ht.AssertTxInBlock(block, txHash)

return finalTx
}
Expand Down Expand Up @@ -1443,8 +1443,8 @@ func assertPsbtSpend(ht *lntest.HarnessTest, alice *node.HarnessNode,
block := ht.MineBlocksAndAssertNumTxes(1, 2)[0]
firstTxHash := prevTx.TxHash()
secondTxHash := finalTx.TxHash()
ht.AssertTxInBlock(block, &firstTxHash)
ht.AssertTxInBlock(block, &secondTxHash)
ht.AssertTxInBlock(block, firstTxHash)
ht.AssertTxInBlock(block, secondTxHash)
}

// assertPsbtFundSignSpend funds a PSBT from the internal wallet and then
Expand Down Expand Up @@ -1807,7 +1807,7 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {

txHash := finalTx.TxHash()
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &txHash)
ht.AssertTxInBlock(block, txHash)

// Now we do the same but instead use preselected utxos to verify that
// these utxos respects the utxo restrictions on sweeper unconfirmed
Expand Down Expand Up @@ -1951,5 +1951,5 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {

txHash = finalTx.TxHash()
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.AssertTxInBlock(block, &txHash)
ht.AssertTxInBlock(block, txHash)
}
24 changes: 12 additions & 12 deletions itest/lnd_revocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
// ordering, the first output in this breach tx is the to_remote
// output.
toRemoteOp := wire.OutPoint{
Hash: *breachTXID,
Hash: breachTXID,
Index: 0,
}

Expand All @@ -151,7 +151,7 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
// Assert that all the inputs of this transaction are spending outputs
// generated by Bob's breach transaction above.
for _, txIn := range justiceTx.TxIn {
require.Equal(ht, *breachTXID, txIn.PreviousOutPoint.Hash,
require.Equal(ht, breachTXID, txIn.PreviousOutPoint.Hash,
"justice tx not spending commitment utxo")
}

Expand All @@ -174,7 +174,7 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
// transaction which was just accepted into the mempool.
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
justiceTxid := justiceTx.TxHash()
ht.AssertTxInBlock(block, &justiceTxid)
ht.AssertTxInBlock(block, justiceTxid)

ht.AssertNodeNumChannels(carol, 0)

Expand Down Expand Up @@ -318,7 +318,7 @@ func revokedCloseRetributionZeroValueRemoteOutputCase(ht *lntest.HarnessTest,
// ordering, the first output in this breach tx is the to_local
// output.
toLocalOp := wire.OutPoint{
Hash: *breachTXID,
Hash: breachTXID,
Index: 0,
}

Expand Down Expand Up @@ -363,7 +363,7 @@ func revokedCloseRetributionZeroValueRemoteOutputCase(ht *lntest.HarnessTest,
// transaction which was just accepted into the mempool.
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
justiceTxid := justiceTx.TxHash()
ht.AssertTxInBlock(block, &justiceTxid)
ht.AssertTxInBlock(block, justiceTxid)

// At this point, Dave should have no pending channels.
ht.AssertNodeNumChannels(dave, 0)
Expand Down Expand Up @@ -567,7 +567,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
// outputs to the second level before Dave broadcasts his justice tx,
// we'll search through the mempool for a tx that matches the number of
// expected inputs in the justice tx.
var justiceTxid *chainhash.Hash
var justiceTxid chainhash.Hash
errNotFound := errors.New("justice tx not found")
findJusticeTx := func() (*chainhash.Hash, error) {
mempool := ht.GetRawMempool()
Expand All @@ -579,14 +579,14 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
// NOTE: We don't use `ht.GetRawTransaction`
// which asserts a txid must be found as the HTLC
// spending txes might be aggregated.
tx, err := ht.Miner().Client.GetRawTransaction(txid)
tx, err := ht.Miner().Client.GetRawTransaction(&txid)
if err != nil {
return nil, err
}

exNumInputs := 2 + numInvoices
if len(tx.MsgTx().TxIn) == exNumInputs {
return txid, nil
return &txid, nil
}
}

Expand All @@ -598,7 +598,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
if err != nil {
return err
}
justiceTxid = txid
justiceTxid = *txid

return nil
}, defaultTimeout)
Expand All @@ -619,7 +619,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
return err
}

justiceTxid = txid
justiceTxid = *txid

return nil
}, defaultTimeout)
Expand All @@ -631,7 +631,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
// isSecondLevelSpend checks that the passed secondLevelTxid is a
// potentitial second level spend spending from the commit tx.
isSecondLevelSpend := func(commitTxid,
secondLevelTxid *chainhash.Hash) bool {
secondLevelTxid chainhash.Hash) bool {

secondLevel := ht.GetRawTransaction(secondLevelTxid)

Expand Down Expand Up @@ -661,7 +661,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
// the breach tx, Carol might have had the time to take an
// output to the second level. In that case, check that the
// justice tx is spending this second level output.
if isSecondLevelSpend(breachTXID, &txIn.PreviousOutPoint.Hash) {
if isSecondLevelSpend(breachTXID, txIn.PreviousOutPoint.Hash) {
continue
}
require.Fail(ht, "justice tx not spending commitment utxo "+
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func assertSignOutputRaw(ht *lntest.HarnessTest,
tx := wire.NewMsgTx(2)
tx.TxIn = []*wire.TxIn{{
PreviousOutPoint: wire.OutPoint{
Hash: *txid,
Hash: txid,
Index: uint32(targetOutputIndex),
},
}}
Expand Down
Loading

0 comments on commit f46ae2f

Please sign in to comment.