From ed3cb2618855a62dfeeee5ecb2916319f0e21acf Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 17 Oct 2024 07:14:51 +0800 Subject: [PATCH] itest+lntest: stop using pointer to `chainhash.Hash` This commit fixes the methods used in `lntest` so they stop using pointers to chainhash. --- itest/lnd_channel_force_close_test.go | 2 +- itest/lnd_coop_close_with_htlcs_test.go | 2 +- itest/lnd_funding_test.go | 6 ++--- itest/lnd_multi-hop_test.go | 30 +++++++++++----------- itest/lnd_nonstd_sweep_test.go | 2 +- itest/lnd_open_channel_test.go | 4 +-- itest/lnd_psbt_test.go | 16 ++++++------ itest/lnd_revocation_test.go | 24 +++++++++--------- itest/lnd_signer_test.go | 2 +- itest/lnd_sweep_test.go | 18 +++++++------- itest/lnd_taproot_test.go | 8 +++--- itest/lnd_wallet_import_test.go | 4 +-- lntest/harness.go | 21 ++++++++-------- lntest/harness_assertion.go | 8 +++--- lntest/harness_miner.go | 12 ++++----- lntest/miner/miner.go | 33 ++++++++++++++----------- 16 files changed, 99 insertions(+), 93 deletions(-) diff --git a/itest/lnd_channel_force_close_test.go b/itest/lnd_channel_force_close_test.go index 34df5ab59..6d0280401 100644 --- a/itest/lnd_channel_force_close_test.go +++ b/itest/lnd_channel_force_close_test.go @@ -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 diff --git a/itest/lnd_coop_close_with_htlcs_test.go b/itest/lnd_coop_close_with_htlcs_test.go index 56f9e801b..55d4d6d20 100644 --- a/itest/lnd_coop_close_with_htlcs_test.go +++ b/itest/lnd_coop_close_with_htlcs_test.go @@ -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) diff --git a/itest/lnd_funding_test.go b/itest/lnd_funding_test.go index a1c2e292d..8d715067d 100644 --- a/itest/lnd_funding_test.go +++ b/itest/lnd_funding_test.go @@ -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()) @@ -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 diff --git a/itest/lnd_multi-hop_test.go b/itest/lnd_multi-hop_test.go index c28910f58..67dcf9d16 100644 --- a/itest/lnd_multi-hop_test.go +++ b/itest/lnd_multi-hop_test.go @@ -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 @@ -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++ } @@ -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. @@ -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) @@ -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. @@ -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. @@ -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 @@ -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, @@ -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. @@ -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 @@ -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} @@ -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. diff --git a/itest/lnd_nonstd_sweep_test.go b/itest/lnd_nonstd_sweep_test.go index f83daa669..1e20e2bfe 100644 --- a/itest/lnd_nonstd_sweep_test.go +++ b/itest/lnd_nonstd_sweep_test.go @@ -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) diff --git a/itest/lnd_open_channel_test.go b/itest/lnd_open_channel_test.go index 52ec622cf..a196d71c5 100644 --- a/itest/lnd_open_channel_test.go +++ b/itest/lnd_open_channel_test.go @@ -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") @@ -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) } diff --git a/itest/lnd_psbt_test.go b/itest/lnd_psbt_test.go index bedc61722..d67503972 100644 --- a/itest/lnd_psbt_test.go +++ b/itest/lnd_psbt_test.go @@ -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) @@ -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) @@ -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 @@ -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 } @@ -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 @@ -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 @@ -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) } diff --git a/itest/lnd_revocation_test.go b/itest/lnd_revocation_test.go index 82415e039..a8cef5007 100644 --- a/itest/lnd_revocation_test.go +++ b/itest/lnd_revocation_test.go @@ -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, } @@ -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") } @@ -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) @@ -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, } @@ -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) @@ -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() @@ -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 } } @@ -598,7 +598,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest, if err != nil { return err } - justiceTxid = txid + justiceTxid = *txid return nil }, defaultTimeout) @@ -619,7 +619,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest, return err } - justiceTxid = txid + justiceTxid = *txid return nil }, defaultTimeout) @@ -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) @@ -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 "+ diff --git a/itest/lnd_signer_test.go b/itest/lnd_signer_test.go index bf9033cad..931069988 100644 --- a/itest/lnd_signer_test.go +++ b/itest/lnd_signer_test.go @@ -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), }, }} diff --git a/itest/lnd_sweep_test.go b/itest/lnd_sweep_test.go index 84e27b9a9..fbe3e6e4c 100644 --- a/itest/lnd_sweep_test.go +++ b/itest/lnd_sweep_test.go @@ -214,7 +214,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) { txns := ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - sweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + sweepTx := ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Get the weight for Bob's anchor sweeping tx. txWeight := ht.CalculateTxWeight(sweepTx) @@ -281,7 +281,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) { txns = ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + sweepTx = ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Calculate the fee rate of Bob's new sweeping tx. feeRate = uint64(ht.CalculateTxFeeRate(sweepTx)) @@ -320,7 +320,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) { txns = ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + sweepTx = ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Calculate the fee of Bob's new sweeping tx. fee = uint64(ht.CalculateTxFee(sweepTx)) @@ -341,7 +341,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) { txns = ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - currentSweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + currentSweepTx := ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Assert the anchor sweep tx stays unchanged. require.Equal(ht, sweepTx.TxHash(), currentSweepTx.TxHash()) @@ -553,7 +553,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) { txns := ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - sweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + sweepTx := ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Get the weight for Bob's anchor sweeping tx. txWeight := ht.CalculateTxWeight(sweepTx) @@ -620,7 +620,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) { txns = ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + sweepTx = ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Calculate the fee rate of Bob's new sweeping tx. feeRate = uint64(ht.CalculateTxFeeRate(sweepTx)) @@ -659,7 +659,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) { txns = ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + sweepTx = ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Calculate the fee of Bob's new sweeping tx. fee = uint64(ht.CalculateTxFee(sweepTx)) @@ -680,7 +680,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) { txns = ht.GetNumTxsFromMempool(2) // Find the sweeping tx. - currentSweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0] + currentSweepTx := ht.FindSweepingTxns(txns, 1, closeTxid)[0] // Assert the anchor sweep tx stays unchanged. require.Equal(ht, sweepTx.TxHash(), currentSweepTx.TxHash()) @@ -2274,7 +2274,7 @@ func testBumpForceCloseFee(ht *lntest.HarnessTest) { // this anchor sweep transaction (because of the small fee delta). ht.MineEmptyBlocks(1) cpfpHash1 := cpfpSweep1.TxHash() - ht.AssertTxInMempool(&cpfpHash1) + ht.AssertTxInMempool(cpfpHash1) // Now Bump the fee rate again with a bigger starting fee rate of the // fee function. diff --git a/itest/lnd_taproot_test.go b/itest/lnd_taproot_test.go index 9434586a4..b30f8cdaa 100644 --- a/itest/lnd_taproot_test.go +++ b/itest/lnd_taproot_test.go @@ -171,7 +171,7 @@ func testTaprootComputeInputScriptKeySpendBip86(ht *lntest.HarnessTest, ht.AssertUTXOInWallet(alice, op, "") p2trOutpoint := wire.OutPoint{ - Hash: *txid, + Hash: txid, Index: uint32(p2trOutputIndex), } @@ -1413,7 +1413,7 @@ func clearWalletImportedTapscriptBalance(ht *lntest.HarnessTest, // Mine one block which should contain the sweep transaction. block := ht.MineBlocksAndAssertNumTxes(1, 1)[0] sweepTxHash := sweepTx.TxHash() - ht.AssertTxInBlock(block, &sweepTxHash) + ht.AssertTxInBlock(block, sweepTxHash) } // testScriptHashLock returns a simple bitcoin script that locks the funds to @@ -1484,7 +1484,7 @@ func sendToTaprootOutput(ht *lntest.HarnessTest, hn *node.HarnessNode, txid := ht.AssertNumTxsInMempool(1)[0] p2trOutputIndex := ht.GetOutputIndex(txid, tapScriptAddr.String()) p2trOutpoint := wire.OutPoint{ - Hash: *txid, + Hash: txid, Index: uint32(p2trOutputIndex), } @@ -1849,7 +1849,7 @@ func testTaprootCoopClose(ht *lntest.HarnessTest) { // assertTaprootDeliveryUsed returns true if a Taproot addr was used in // the co-op close transaction. - assertTaprootDeliveryUsed := func(closingTxid *chainhash.Hash) bool { + assertTaprootDeliveryUsed := func(closingTxid chainhash.Hash) bool { tx := ht.GetRawTransaction(closingTxid) for _, txOut := range tx.MsgTx().TxOut { if !txscript.IsPayToTaproot(txOut.PkScript) { diff --git a/itest/lnd_wallet_import_test.go b/itest/lnd_wallet_import_test.go index b9cce9f1e..d8fa84dce 100644 --- a/itest/lnd_wallet_import_test.go +++ b/itest/lnd_wallet_import_test.go @@ -372,7 +372,7 @@ func fundChanAndCloseFromImportedAccount(ht *lntest.HarnessTest, srcNode, ) block := ht.MineBlocksAndAssertNumTxes(6, 1)[0] - ht.AssertTxInBlock(block, txHash) + ht.AssertTxInBlock(block, *txHash) confBalanceAfterChan += chanChangeUtxoAmt ht.AssertWalletAccountBalance(srcNode, account, 0, 0) @@ -389,7 +389,7 @@ func fundChanAndCloseFromImportedAccount(ht *lntest.HarnessTest, srcNode, ) block := ht.MineBlocksAndAssertNumTxes(6, 1)[0] - ht.AssertTxInBlock(block, txHash) + ht.AssertTxInBlock(block, *txHash) confBalanceAfterChan += chanChangeUtxoAmt ht.AssertWalletAccountBalance( diff --git a/lntest/harness.go b/lntest/harness.go index 79c1f61ff..09e241835 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -342,6 +342,7 @@ func (h *HarnessTest) SetupStandbyNodes() { // above a good number of confirmations. const totalTxes = 200 h.MineBlocksAndAssertNumTxes(numBlocksSendOutput, totalTxes) + h.MineBlocks(numBlocksSendOutput) // Now we want to wait for the nodes to catch up. h.WaitForBlockchainSync(h.Alice) @@ -913,12 +914,12 @@ func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) error { // GetChanPointFundingTxid takes a channel point and converts it into a chain // hash. func (h *HarnessTest) GetChanPointFundingTxid( - cp *lnrpc.ChannelPoint) *chainhash.Hash { + cp *lnrpc.ChannelPoint) chainhash.Hash { txid, err := lnrpc.GetChanPointFundingTxid(cp) require.NoError(h, err, "unable to get txid") - return txid + return *txid } // OutPointFromChannelPoint creates an outpoint from a given channel point. @@ -927,7 +928,7 @@ func (h *HarnessTest) OutPointFromChannelPoint( txid := h.GetChanPointFundingTxid(cp) return wire.OutPoint{ - Hash: *txid, + Hash: txid, Index: cp.OutputIndex, } } @@ -1263,7 +1264,7 @@ func (h *HarnessTest) OpenChannelAssertErr(srcNode, destNode *node.HarnessNode, // mempool. func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode, cp *lnrpc.ChannelPoint, - force bool) (rpc.CloseChanClient, *chainhash.Hash) { + force bool) (rpc.CloseChanClient, chainhash.Hash) { // Calls the rpc to close the channel. closeReq := &lnrpc.CloseChannelRequest{ @@ -1306,9 +1307,9 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode, pendingClose.ClosePending.Txid) // Assert the closing tx is in the mempool. - h.miner.AssertTxInMempool(closeTxid) + h.miner.AssertTxInMempool(*closeTxid) - return stream, closeTxid + return stream, *closeTxid } // CloseChannel attempts to coop close a non-anchored channel identified by the @@ -1321,7 +1322,7 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode, // 5. the node reports zero waiting close channels. // 6. the node receives a topology update regarding the channel close. func (h *HarnessTest) CloseChannel(hn *node.HarnessNode, - cp *lnrpc.ChannelPoint) *chainhash.Hash { + cp *lnrpc.ChannelPoint) chainhash.Hash { stream, _ := h.CloseChannelAssertPending(hn, cp, false) @@ -1340,7 +1341,7 @@ func (h *HarnessTest) CloseChannel(hn *node.HarnessNode, // 7. mine DefaultCSV-1 blocks. // 8. the node reports zero pending force close channels. func (h *HarnessTest) ForceCloseChannel(hn *node.HarnessNode, - cp *lnrpc.ChannelPoint) *chainhash.Hash { + cp *lnrpc.ChannelPoint) chainhash.Hash { stream, _ := h.CloseChannelAssertPending(hn, cp, true) @@ -1902,7 +1903,7 @@ func (h *HarnessTest) CalculateTxFee(tx *wire.MsgTx) btcutil.Amount { var balance btcutil.Amount for _, in := range tx.TxIn { parentHash := in.PreviousOutPoint.Hash - rawTx := h.miner.GetRawTransaction(&parentHash) + rawTx := h.miner.GetRawTransaction(parentHash) parent := rawTx.MsgTx() value := parent.TxOut[in.PreviousOutPoint.Index].Value @@ -2151,7 +2152,7 @@ func (h *HarnessTest) ReceiveChannelEvent( // GetOutputIndex returns the output index of the given address in the given // transaction. -func (h *HarnessTest) GetOutputIndex(txid *chainhash.Hash, addr string) int { +func (h *HarnessTest) GetOutputIndex(txid chainhash.Hash, addr string) int { // We'll then extract the raw transaction from the mempool in order to // determine the index of the p2tr output. tx := h.miner.GetRawTransaction(txid) diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index add5b91f9..d56e70703 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -534,7 +534,7 @@ func (h *HarnessTest) AssertTopologyChannelClosed(hn *node.HarnessNode, // by consuming a message from the passed close channel stream. Returns the // closing txid if found. func (h HarnessTest) WaitForChannelCloseEvent( - stream rpc.CloseChanClient) *chainhash.Hash { + stream rpc.CloseChanClient) chainhash.Hash { // Consume one event. event, err := h.ReceiveCloseChannelUpdate(stream) @@ -548,7 +548,7 @@ func (h HarnessTest) WaitForChannelCloseEvent( require.NoErrorf(h, err, "wrong format found in closing txid: %v", resp.ChanClose.ClosingTxid) - return txid + return *txid } // AssertNumWaitingClose checks that a PendingChannels response from the node @@ -634,7 +634,7 @@ func (h *HarnessTest) AssertNumPendingForceClose(hn *node.HarnessNode, // - assert the node has seen the channel close update. func (h *HarnessTest) AssertStreamChannelCoopClosed(hn *node.HarnessNode, cp *lnrpc.ChannelPoint, anchors bool, - stream rpc.CloseChanClient) *chainhash.Hash { + stream rpc.CloseChanClient) chainhash.Hash { // Assert the channel is waiting close. resp := h.AssertChannelWaitingClose(hn, cp) @@ -682,7 +682,7 @@ func (h *HarnessTest) AssertStreamChannelCoopClosed(hn *node.HarnessNode, // confirmed. func (h *HarnessTest) AssertStreamChannelForceClosed(hn *node.HarnessNode, cp *lnrpc.ChannelPoint, anchorSweep bool, - stream rpc.CloseChanClient) *chainhash.Hash { + stream rpc.CloseChanClient) chainhash.Hash { // Assert the channel is waiting close. resp := h.AssertChannelWaitingClose(hn, cp) diff --git a/lntest/harness_miner.go b/lntest/harness_miner.go index cf07d4525..0fbfc227e 100644 --- a/lntest/harness_miner.go +++ b/lntest/harness_miner.go @@ -113,7 +113,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32, // Make sure the mempool has been updated. for _, txid := range txids { - h.miner.AssertTxNotInMempool(*txid) + h.miner.AssertTxNotInMempool(txid) } // Finally, make sure all the active nodes are synced. @@ -202,7 +202,7 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) { } // AssertTxInMempool asserts a given transaction can be found in the mempool. -func (h *HarnessTest) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx { +func (h *HarnessTest) AssertTxInMempool(txid chainhash.Hash) *wire.MsgTx { return h.miner.AssertTxInMempool(txid) } @@ -219,7 +219,7 @@ func (h *HarnessTest) AssertTxNotInMempool(txid chainhash.Hash) *wire.MsgTx { // AssertNumTxsInMempool polls until finding the desired number of transactions // in the provided miner's mempool. It will assert if this number is not met // after the given timeout. -func (h *HarnessTest) AssertNumTxsInMempool(n int) []*chainhash.Hash { +func (h *HarnessTest) AssertNumTxsInMempool(n int) []chainhash.Hash { return h.miner.AssertNumTxsInMempool(n) } @@ -230,7 +230,7 @@ func (h *HarnessTest) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx { // AssertTxInBlock asserts that a given txid can be found in the passed block. func (h *HarnessTest) AssertTxInBlock(block *wire.MsgBlock, - txid *chainhash.Hash) { + txid chainhash.Hash) { h.miner.AssertTxInBlock(block, txid) } @@ -263,13 +263,13 @@ func (h *HarnessTest) DisconnectFromMiner(tempMiner *miner.HarnessMiner) { // GetRawMempool makes a RPC call to the miner's GetRawMempool and // asserts. -func (h *HarnessTest) GetRawMempool() []*chainhash.Hash { +func (h *HarnessTest) GetRawMempool() []chainhash.Hash { return h.miner.GetRawMempool() } // GetRawTransaction makes a RPC call to the miner's GetRawTransaction and // asserts. -func (h *HarnessTest) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx { +func (h *HarnessTest) GetRawTransaction(txid chainhash.Hash) *btcutil.Tx { return h.miner.GetRawTransaction(txid) } diff --git a/lntest/miner/miner.go b/lntest/miner/miner.go index 342793b90..a7b7ac2b0 100644 --- a/lntest/miner/miner.go +++ b/lntest/miner/miner.go @@ -156,11 +156,16 @@ func (h *HarnessMiner) GetBestBlock() (*chainhash.Hash, int32) { // GetRawMempool makes a RPC call to the miner's GetRawMempool and // asserts. -func (h *HarnessMiner) GetRawMempool() []*chainhash.Hash { +func (h *HarnessMiner) GetRawMempool() []chainhash.Hash { mempool, err := h.Client.GetRawMempool() require.NoError(h, err, "unable to get mempool") - return mempool + txns := make([]chainhash.Hash, 0, len(mempool)) + for _, txid := range mempool { + txns = append(txns, *txid) + } + + return txns } // GenerateBlocks mine 'num' of blocks and returns them. @@ -198,9 +203,9 @@ func (h *HarnessMiner) MineBlocks(num uint32) []*wire.MsgBlock { // AssertNumTxsInMempool polls until finding the desired number of transactions // in the provided miner's mempool. It will assert if this number is not met // after the given timeout. -func (h *HarnessMiner) AssertNumTxsInMempool(n int) []*chainhash.Hash { +func (h *HarnessMiner) AssertNumTxsInMempool(n int) []chainhash.Hash { var ( - mem []*chainhash.Hash + mem []chainhash.Hash err error ) @@ -222,7 +227,7 @@ func (h *HarnessMiner) AssertNumTxsInMempool(n int) []*chainhash.Hash { // AssertTxInBlock asserts that a given txid can be found in the passed block. func (h *HarnessMiner) AssertTxInBlock(block *wire.MsgBlock, - txid *chainhash.Hash) { + txid chainhash.Hash) { blockTxes := make([]chainhash.Hash, 0) @@ -264,8 +269,8 @@ func (h *HarnessMiner) MineBlocksAndAssertNumTxes(num uint32, // GetRawTransaction makes a RPC call to the miner's GetRawTransaction and // asserts. -func (h *HarnessMiner) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx { - tx, err := h.Client.GetRawTransaction(txid) +func (h *HarnessMiner) GetRawTransaction(txid chainhash.Hash) *btcutil.Tx { + tx, err := h.Client.GetRawTransaction(&txid) require.NoErrorf(h, err, "failed to get raw tx: %v", txid) return tx } @@ -273,15 +278,15 @@ func (h *HarnessMiner) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx { // GetRawTransactionVerbose makes a RPC call to the miner's // GetRawTransactionVerbose and asserts. func (h *HarnessMiner) GetRawTransactionVerbose( - txid *chainhash.Hash) *btcjson.TxRawResult { + txid chainhash.Hash) *btcjson.TxRawResult { - tx, err := h.Client.GetRawTransactionVerbose(txid) + tx, err := h.Client.GetRawTransactionVerbose(&txid) require.NoErrorf(h, err, "failed to get raw tx verbose: %v", txid) return tx } // AssertTxInMempool asserts a given transaction can be found in the mempool. -func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx { +func (h *HarnessMiner) AssertTxInMempool(txid chainhash.Hash) *wire.MsgTx { err := wait.NoError(func() error { // We require the RPC call to be succeeded and won't wait for // it as it's an unexpected behavior. @@ -291,8 +296,8 @@ func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx { return fmt.Errorf("empty mempool") } - isEqual := func(memTx *chainhash.Hash) bool { - return *memTx == *txid + isEqual := func(memTx chainhash.Hash) bool { + return memTx == txid } result := fn.Find(isEqual, mempool) @@ -325,7 +330,7 @@ func (h *HarnessMiner) AssertTxNotInMempool(txid chainhash.Hash) *wire.MsgTx { for _, memTx := range mempool { // Check the values are equal. - if txid.IsEqual(memTx) { + if txid == memTx { return fmt.Errorf("expect txid %v to be NOT "+ "found in mempool", txid) } @@ -418,7 +423,7 @@ func (h *HarnessMiner) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx { // found. For instance, the aggregation logic used in // sweeping HTLC outputs will update the mempool by // replacing the HTLC spending txes with a single one. - tx, err := h.Client.GetRawTransaction(txid) + tx, err := h.Client.GetRawTransaction(&txid) if err != nil { return err }