lntest+itest: continue removing direct call to Miner

This commit is contained in:
yyforyongyu 2024-05-01 19:40:05 +08:00 committed by yyforyongyu
parent 976bb37972
commit 6bd8baea38
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
18 changed files with 124 additions and 93 deletions

View file

@ -624,7 +624,7 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
var fundingShim *lnrpc.FundingShim
if ct == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
_, minerHeight := ht.Miner.GetBestBlock()
_, minerHeight := ht.GetBestBlock()
thawHeight := uint32(minerHeight + thawHeightDelta)
fundingShim, _ = deriveFundingShim(

View file

@ -160,7 +160,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
// Fetch starting height of this test so we can compute the block
// heights we expect certain events to take place.
_, curHeight := ht.Miner.GetBestBlock()
_, curHeight := ht.GetBestBlock()
// Using the current height of the chain, derive the relevant heights
// for incubating two-stage htlcs.
@ -214,7 +214,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
ht.AssertNumUTXOs(alice, expectedUtxos)
// We expect to see Alice's force close tx in the mempool.
ht.Miner.GetNumTxsFromMempool(1)
ht.GetNumTxsFromMempool(1)
// Mine a block which should confirm the commitment transaction
// broadcast as a result of the force closure. Once mined, we also
@ -278,7 +278,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
// Carol's sweep tx should be in the mempool already, as her output is
// not timelocked.
carolTx := ht.Miner.GetNumTxsFromMempool(1)[0]
carolTx := ht.GetNumTxsFromMempool(1)[0]
// Carol's sweeping tx should have 2-input-1-output shape.
require.Len(ht, carolTx.TxIn, 2)
@ -431,7 +431,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
ht.MineBlocksAndAssertNumTxes(1, 1)
// Update current height
_, curHeight = ht.Miner.GetBestBlock()
_, curHeight = ht.GetBestBlock()
// checkForceClosedChannelNumHtlcs verifies that a force closed channel
// has the proper number of htlcs.
@ -485,7 +485,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
// number 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 height, and add the block padding.
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
cltvHeightDelta := int(htlcExpiryHeight - uint32(currentHeight) - 1)
// Advance the blockchain until just before the CLTV expires, nothing
@ -662,7 +662,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
// Advance the chain until just before the 2nd-layer CSV delays expire.
// For anchor channels this is one block earlier.
_, currentHeight = ht.Miner.GetBestBlock()
_, currentHeight = ht.GetBestBlock()
ht.Logf("current height: %v, htlcCsvMaturityHeight=%v", currentHeight,
htlcCsvMaturityHeight)
numBlocks := int(htlcCsvMaturityHeight - uint32(currentHeight) - 2)

View file

@ -316,7 +316,7 @@ func testGraphTopologyNtfns(ht *lntest.HarnessTest, pinned bool) {
ht.AssertNumNodeAnns(alice, alice.PubKeyStr, 1)
ht.AssertNumNodeAnns(alice, bob.PubKeyStr, 1)
_, blockHeight := ht.Miner.GetBestBlock()
_, blockHeight := ht.GetBestBlock()
// Now we'll test that updates are properly sent after channels are
// closed within the network.

View file

@ -117,7 +117,7 @@ func coopCloseWithHTLCs(ht *lntest.HarnessTest) {
)
// Wait for the close tx to be in the Mempool.
ht.Miner.AssertTxInMempool(&closeTxid)
ht.AssertTxInMempool(&closeTxid)
// Wait for it to get mined and finish tearing down.
ht.AssertStreamChannelCoopClosed(alice, chanPoint, false, closeClient)

View file

@ -862,7 +862,7 @@ func testChannelFundingPersistence(ht *lntest.HarnessTest) {
ht.AssertTxInBlock(block, fundingTxID)
// Get the height that our transaction confirmed at.
_, height := ht.Miner.GetBestBlock()
_, height := ht.GetBestBlock()
// Restart both nodes to test that the appropriate state has been
// persisted and that both nodes recover gracefully.

View file

@ -59,7 +59,7 @@ func testHoldInvoiceForceClose(ht *lntest.HarnessTest) {
require.Len(ht, channel.PendingHtlcs, 1)
activeHtlc := channel.PendingHtlcs[0]
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
// Now we will mine blocks until the htlc expires, and wait for each
// node to sync to our latest height. Sanity check that we won't

View file

@ -248,7 +248,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
// Bob's force close transaction should now be found in the mempool.
ht.AssertNumTxsInMempool(1)
op := ht.OutPointFromChannelPoint(bobChanPoint)
closeTx := ht.Miner.AssertOutpointInMempool(op)
closeTx := ht.AssertOutpointInMempool(op)
// Bob's anchor output should be offered to his sweep since Bob has
// time-sensitive HTLCs - we expect both anchors are offered.
@ -280,7 +280,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
htlcOutpoint := wire.OutPoint{Hash: closeTx.TxHash(), Index: 2}
commitOutpoint := wire.OutPoint{Hash: closeTx.TxHash(), Index: 3}
htlcTimeoutTxid := ht.Miner.AssertOutpointInMempool(
htlcTimeoutTxid := ht.AssertOutpointInMempool(
htlcOutpoint,
).TxHash()
@ -330,7 +330,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
ht.AssertNumPendingSweeps(bob, 2)
// Assert that the HTLC timeout tx is now in the mempool.
ht.Miner.AssertOutpointInMempool(htlcTimeoutOutpoint)
ht.AssertOutpointInMempool(htlcTimeoutOutpoint)
// We now wait for 30 seconds to overcome the flake - there's a
// block race between contractcourt and sweeper, causing the
@ -363,7 +363,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
pendingChanResp := bob.RPC.PendingChannels()
if len(pendingChanResp.PendingForceClosingChannels) != 0 {
// Check that the sweep spends the expected inputs.
ht.Miner.AssertOutpointInMempool(commitOutpoint)
ht.AssertOutpointInMempool(commitOutpoint)
ht.MineBlocksAndAssertNumTxes(1, 1)
}
} else {
@ -381,14 +381,14 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
ht.MineEmptyBlocks(1)
// Check that the sweep spends from the mined commitment.
ht.Miner.AssertOutpointInMempool(commitOutpoint)
ht.AssertOutpointInMempool(commitOutpoint)
// Mine one more block to trigger the timeout path.
ht.MineBlocksAndAssertNumTxes(1, 1)
// Bob's sweeper should now broadcast his second layer sweep
// due to the CSV on the HTLC timeout output.
ht.Miner.AssertOutpointInMempool(htlcTimeoutOutpoint)
ht.AssertOutpointInMempool(htlcTimeoutOutpoint)
// Next, we'll mine a final block that should confirm the
// sweeping transactions left.
@ -503,7 +503,7 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest,
// transaction in order to go to the chain and sweep her HTLC.
ht.AssertNumTxsInMempool(1)
closingTx := ht.Miner.AssertOutpointInMempool(
closingTx := ht.AssertOutpointInMempool(
ht.OutPointFromChannelPoint(bobChanPoint),
)
closingTxid := closingTx.TxHash()
@ -572,7 +572,7 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest,
ht.MineEmptyBlocks(1)
// All transactions should be spending from the commitment transaction.
txes := ht.Miner.GetNumTxsFromMempool(expectedTxes)
txes := ht.GetNumTxsFromMempool(expectedTxes)
ht.AssertAllTxesSpendFrom(txes, closingTxid)
// We'll now mine an additional block which should confirm both the
@ -644,7 +644,7 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest,
ht.MineEmptyBlocks(1)
commitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
ht.Miner.AssertOutpointInMempool(commitOutpoint)
ht.AssertOutpointInMempool(commitOutpoint)
ht.MineBlocksAndAssertNumTxes(1, 1)
}
@ -756,7 +756,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
ht.MineEmptyBlocks(1)
blocksMined++
commitSweepTx := ht.Miner.AssertOutpointInMempool(
commitSweepTx := ht.AssertOutpointInMempool(
bobCommitOutpoint,
)
txid := commitSweepTx.TxHash()
@ -784,7 +784,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
// We should also now find a transaction in the mempool, as Bob should
// have broadcast his second layer timeout transaction.
timeoutTx := ht.Miner.AssertOutpointInMempool(htlcOutpoint).TxHash()
timeoutTx := ht.AssertOutpointInMempool(htlcOutpoint).TxHash()
// Next, we'll mine an additional block. This should serve to confirm
// the second layer timeout transaction.
@ -837,7 +837,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
// Assert the sweeping tx is found in the mempool.
htlcTimeoutOutpoint := wire.OutPoint{Hash: timeoutTx, Index: 0}
ht.Miner.AssertOutpointInMempool(htlcTimeoutOutpoint)
ht.AssertOutpointInMempool(htlcTimeoutOutpoint)
// Mine a block to confirm the sweep.
ht.MineBlocksAndAssertNumTxes(1, numExpected)
@ -1042,7 +1042,7 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
ht.MineEmptyBlocks(1)
bobCommitOutpoint := wire.OutPoint{Hash: *closeTx, Index: 3}
bobCommitSweep := ht.Miner.AssertOutpointInMempool(
bobCommitSweep := ht.AssertOutpointInMempool(
bobCommitOutpoint,
)
bobCommitSweepTxid := bobCommitSweep.TxHash()
@ -1219,7 +1219,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
// Look up the closing transaction. It should be spending from the
// funding transaction,
closingTx := ht.Miner.AssertOutpointInMempool(
closingTx := ht.AssertOutpointInMempool(
ht.OutPointFromChannelPoint(bobChanPoint),
)
closingTxid := closingTx.TxHash()
@ -1300,7 +1300,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
carolSecondLevelCSV--
// Check Bob's second level tx.
bobSecondLvlTx := ht.Miner.GetNumTxsFromMempool(1)[0]
bobSecondLvlTx := ht.GetNumTxsFromMempool(1)[0]
// It should spend from the commitment in the channel with Alice.
ht.AssertTxSpendFrom(bobSecondLvlTx, *bobForceClose)
@ -1355,7 +1355,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
block = ht.MineBlocksAndAssertNumTxes(bobSecondLevelCSV, 1)[0]
ht.AssertTxInBlock(block, carolSweep)
bobSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
bobSweep := ht.GetNumTxsFromMempool(1)[0]
bobSweepTxid := bobSweep.TxHash()
// When we mine one additional block, that will confirm Bob's sweep.
@ -1399,11 +1399,11 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
aliceCommitOutpoint := wire.OutPoint{
Hash: *bobForceClose, Index: 3,
}
ht.Miner.AssertOutpointInMempool(
ht.AssertOutpointInMempool(
aliceCommitOutpoint,
).TxHash()
bobCommitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
ht.Miner.AssertOutpointInMempool(
ht.AssertOutpointInMempool(
bobCommitOutpoint,
).TxHash()
@ -1562,7 +1562,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
// The closing transaction should be spending from the funding
// transaction.
closingTx := ht.Miner.AssertOutpointInMempool(
closingTx := ht.AssertOutpointInMempool(
ht.OutPointFromChannelPoint(bobChanPoint),
)
closingTxid := closingTx.TxHash()
@ -1624,7 +1624,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
// NOTE: after Bob is restarted, the sweeping of the direct preimage
// spent will happen immediately so we don't need to mine a block to
// trigger Bob's sweeper to sweep it.
bobHtlcSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
bobHtlcSweep := ht.GetNumTxsFromMempool(1)[0]
bobHtlcSweepTxid := bobHtlcSweep.TxHash()
// It should spend from the commitment in the channel with Alice.
@ -1692,9 +1692,9 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
aliceCommitOutpoint := wire.OutPoint{
Hash: *aliceForceClose, Index: 3,
}
ht.Miner.AssertOutpointInMempool(aliceCommitOutpoint)
ht.AssertOutpointInMempool(aliceCommitOutpoint)
bobCommitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
ht.Miner.AssertOutpointInMempool(bobCommitOutpoint)
ht.AssertOutpointInMempool(bobCommitOutpoint)
// Confirm their sweeps.
ht.MineBlocksAndAssertNumTxes(1, 2)
@ -1887,7 +1887,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
// other for local.
ht.AssertNumPendingSweeps(bob, 2)
closeTx := ht.Miner.AssertOutpointInMempool(
closeTx := ht.AssertOutpointInMempool(
ht.OutPointFromChannelPoint(bobChanPoint),
)
closeTxid := closeTx.TxHash()
@ -1977,7 +1977,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
ht.MineBlocksAndAssertNumTxes(1, 1)
// Assert the sweeping txns are found in the mempool.
txes := ht.Miner.GetNumTxsFromMempool(expectedTxes)
txes := ht.GetNumTxsFromMempool(expectedTxes)
// Since Bob can aggregate the transactions, we expect a single
// transaction, that have multiple spends from the commitment.
@ -2048,7 +2048,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
ht.MineEmptyBlocks(1)
// Find the commitment sweep.
bobCommitSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
bobCommitSweep := ht.GetNumTxsFromMempool(1)[0]
ht.AssertTxSpendFrom(bobCommitSweep, closeTxid)
// Also ensure it is not spending from any of the HTLC output.
@ -2092,7 +2092,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
// Add debug log.
_, height := ht.Miner.GetBestBlock()
_, height := ht.GetBestBlock()
bob.AddToLogf("itest: now mine %d blocks at height %d",
numBlocks, height)
ht.MineEmptyBlocks(int(numBlocks) - 1)
@ -2135,7 +2135,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
ht.Logf("Checking mempool got: %v", err)
// Make sure it spends from the second level tx.
secondLevelSweep := ht.Miner.GetNumTxsFromMempool(numExpected)[0]
secondLevelSweep := ht.GetNumTxsFromMempool(numExpected)[0]
bobSweep := secondLevelSweep.TxHash()
// It should be sweeping all the second-level outputs.
@ -2232,7 +2232,7 @@ func createThreeHopNetwork(ht *lntest.HarnessTest,
var aliceFundingShim *lnrpc.FundingShim
var thawHeight uint32
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
_, minerHeight := ht.Miner.GetBestBlock()
_, minerHeight := ht.GetBestBlock()
thawHeight = uint32(minerHeight + thawHeightDelta)
aliceFundingShim, _ = deriveFundingShim(
ht, alice, bob, chanAmt, thawHeight, true, c,
@ -2449,7 +2449,7 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
// Get the current height to compute number of blocks to mine to
// trigger the htlc timeout resolver from Bob.
_, height := ht.Miner.GetBestBlock()
_, height := ht.GetBestBlock()
// We'll now mine enough blocks to trigger Bob's timeout resolver.
numBlocks = htlc.ExpirationHeight - uint32(height) -
@ -2680,7 +2680,7 @@ func runExtraPreimageFromLocalCommit(ht *lntest.HarnessTest,
// Get the current height to compute number of blocks to mine to
// trigger the timeout resolver from Bob.
_, height := ht.Miner.GetBestBlock()
_, height := ht.GetBestBlock()
// We'll now mine enough blocks to trigger Bob's htlc timeout resolver
// to act. Once his timeout resolver starts, it will extract the
@ -2701,7 +2701,7 @@ func runExtraPreimageFromLocalCommit(ht *lntest.HarnessTest,
// preimage from the blocks.
if ht.IsNeutrinoBackend() {
// Make sure the direct spend tx is still in the mempool.
ht.Miner.AssertOutpointInMempool(htlcOutpoint)
ht.AssertOutpointInMempool(htlcOutpoint)
// Mine a block to confirm Carol's direct spend tx.
ht.MineBlocks(1)

View file

@ -486,7 +486,7 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) {
// We now update the anchor sweep's deadline to be different than the
// commit sweep so they can won't grouped together.
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
deadline := int32(commit.DeadlineHeight) - currentHeight
require.Positive(ht, deadline)
ht.Logf("Found commit deadline %d, anchor deadline %d",
@ -520,7 +520,7 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) {
// Mine one block to trigger Alice's sweeper to reconsider the anchor
// sweeping - it will be swept with her commit output together in one
// tx.
txns := ht.Miner.GetNumTxsFromMempool(2)
txns := ht.GetNumTxsFromMempool(2)
aliceSweep := txns[0]
if aliceSweep.TxOut[0].Value > txns[1].TxOut[0].Value {
aliceSweep = txns[1]
@ -600,7 +600,7 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) {
Hash: *forceCloseTxID,
Index: 1,
}
ht.Miner.AssertOutpointInMempool(commitSweepOp)
ht.AssertOutpointInMempool(commitSweepOp)
ht.MineBlocks(1)
ht.AssertNumWaitingClose(alice, 0)
@ -727,7 +727,7 @@ func testRemoveTx(ht *lntest.HarnessTest) {
require.Lenf(ht, unconfirmed, 2, "number of unconfirmed tx")
// Get the raw transaction to calculate the exact fee.
tx := ht.Miner.GetNumTxsFromMempool(1)[0]
tx := ht.GetNumTxsFromMempool(1)[0]
// Calculate the tx fee so we can compare the end amounts. We are
// sending from the internal wallet to the internal wallet so only
@ -836,7 +836,7 @@ func testListSweeps(ht *lntest.HarnessTest) {
ht.MineEmptyBlocks(1)
// Get the current block height.
_, blockHeight := ht.Miner.GetBestBlock()
_, blockHeight := ht.GetBestBlock()
// Close the second channel and also sweep the funds.
ht.ForceCloseChannel(alice, chanPoints[1])

View file

@ -238,7 +238,7 @@ func testRestAPI(ht *lntest.HarnessTest) {
func wsTestCaseSubscription(ht *lntest.HarnessTest) {
// Find out the current best block so we can subscribe to the next one.
hash, height := ht.Miner.GetBestBlock()
hash, height := ht.GetBestBlock()
// Create a new subscription to get block epoch events.
req := &chainrpc.BlockEpoch{
@ -314,7 +314,7 @@ func wsTestCaseSubscription(ht *lntest.HarnessTest) {
func wsTestCaseSubscriptionMacaroon(ht *lntest.HarnessTest) {
// Find out the current best block so we can subscribe to the next one.
hash, height := ht.Miner.GetBestBlock()
hash, height := ht.GetBestBlock()
// Create a new subscription to get block epoch events.
req := &chainrpc.BlockEpoch{

View file

@ -146,7 +146,7 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
// sweeping transactions in the mempool. Thus we directly assert that
// the breach transaction's outpoint is seen in the mempool instead of
// checking the number of transactions.
justiceTx := ht.Miner.AssertOutpointInMempool(toRemoteOp)
justiceTx := ht.AssertOutpointInMempool(toRemoteOp)
// Assert that all the inputs of this transaction are spending outputs
// generated by Bob's breach transaction above.
@ -338,7 +338,7 @@ func revokedCloseRetributionZeroValueRemoteOutputCase(ht *lntest.HarnessTest,
// sweeping transactions in the mempool. Thus we directly assert that
// the breach transaction's outpoint is seen in the mempool instead of
// checking the number of transactions.
justiceTx := ht.Miner.AssertOutpointInMempool(toLocalOp)
justiceTx := ht.AssertOutpointInMempool(toLocalOp)
// Assert that all the inputs of this transaction are spending outputs
// generated by Carol's breach transaction above.

View file

@ -117,7 +117,7 @@ func testSingleHopSendToRouteCase(ht *lntest.HarnessTest,
// Assert Carol and Dave are synced to the chain before proceeding, to
// ensure the queried route will have a valid final CLTV once the HTLC
// reaches Dave.
_, minerHeight := ht.Miner.GetBestBlock()
_, minerHeight := ht.GetBestBlock()
ht.WaitForNodeBlockHeight(carol, minerHeight)
ht.WaitForNodeBlockHeight(dave, minerHeight)

View file

@ -209,7 +209,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
//
// We should see Bob's anchor sweeping tx triggered by the above
// block, along with his force close tx.
txns := ht.Miner.GetNumTxsFromMempool(2)
txns := ht.GetNumTxsFromMempool(2)
// Find the sweeping tx.
sweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
@ -261,7 +261,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
// Make sure Bob's old sweeping tx has been removed from the
// mempool.
ht.Miner.AssertTxNotInMempool(sweepTx.TxHash())
ht.AssertTxNotInMempool(sweepTx.TxHash())
// We expect to see two txns in the mempool,
// - Bob's force close tx.
@ -276,7 +276,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
// We should see Bob's anchor sweeping tx being fee bumped
// since it's not confirmed, along with his force close tx.
txns = ht.Miner.GetNumTxsFromMempool(2)
txns = ht.GetNumTxsFromMempool(2)
// Find the sweeping tx.
sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
@ -311,11 +311,11 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
ht.MineEmptyBlocks(1)
// Make sure Bob's old sweeping tx has been removed from the mempool.
ht.Miner.AssertTxNotInMempool(sweepTx.TxHash())
ht.AssertTxNotInMempool(sweepTx.TxHash())
// Get the last sweeping tx - we should see two txns here, Bob's anchor
// sweeping tx and his force close tx.
txns = ht.Miner.GetNumTxsFromMempool(2)
txns = ht.GetNumTxsFromMempool(2)
// Find the sweeping tx.
sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
@ -336,7 +336,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
//
// We expect two txns here, one for the anchor sweeping, the other for
// the force close tx.
txns = ht.Miner.GetNumTxsFromMempool(2)
txns = ht.GetNumTxsFromMempool(2)
// Find the sweeping tx.
currentSweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
@ -912,7 +912,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// Bob should now have one sweep and one sweeping tx in the mempool.
ht.AssertNumPendingSweeps(bob, 1)
outgoingSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
outgoingSweep := ht.GetNumTxsFromMempool(1)[0]
// Check the shape of the sweeping tx - we expect it to be
// 2-input-2-output as a wallet utxo is used and a required output is
@ -986,13 +986,13 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// Make sure Bob's old sweeping tx has been removed from the
// mempool.
ht.Miner.AssertTxNotInMempool(outgoingSweep.TxHash())
ht.AssertTxNotInMempool(outgoingSweep.TxHash())
// Bob should still have the outgoing HTLC sweep.
ht.AssertNumPendingSweeps(bob, 1)
// We should see Bob's replacement tx in the mempool.
outgoingSweep = ht.Miner.GetNumTxsFromMempool(1)[0]
outgoingSweep = ht.GetNumTxsFromMempool(1)[0]
// Bob's outgoing HTLC sweeping tx should be fee bumped.
assertSweepFeeRate(
@ -1018,7 +1018,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// We should see two txns in the mempool:
// 1. Bob's outgoing HTLC sweeping tx.
// 2. Bob's force close tx for Alice->Bob.
txns := ht.Miner.GetNumTxsFromMempool(2)
txns := ht.GetNumTxsFromMempool(2)
// Find the force close tx - we expect it to have a single input.
closeTx := txns[0]
@ -1051,7 +1051,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// 1. the outgoing HTLC sweeping tx.
// 2. the incoming HTLC sweeping tx.
// 3. the anchor sweeping tx.
txns = ht.Miner.GetNumTxsFromMempool(3)
txns = ht.GetNumTxsFromMempool(3)
abCloseTxid := closeTx.TxHash()
@ -1102,7 +1102,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// We should see two txns in the mempool:
// 1. the outgoing HTLC sweeping tx.
// 2. the incoming HTLC sweeping tx.
txns = ht.Miner.GetNumTxsFromMempool(2)
txns = ht.GetNumTxsFromMempool(2)
var incoming, outgoing *wire.MsgTx
@ -1160,8 +1160,8 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// Make sure Bob's old sweeping txns have been removed from the
// mempool.
ht.Miner.AssertTxNotInMempool(outgoingSweep.TxHash())
ht.Miner.AssertTxNotInMempool(incomingSweep.TxHash())
ht.AssertTxNotInMempool(outgoingSweep.TxHash())
ht.AssertTxNotInMempool(incomingSweep.TxHash())
// Bob should have two pending sweeps:
// 1. the outgoing HTLC output on Bob->Carol.
@ -1370,7 +1370,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
// - Alice's anchor sweeping tx must have been failed due to the fee
// rate chosen in this test - the anchor sweep tx has no output.
// - Bob's sweeping tx, which sweeps both his anchor and commit outputs.
bobSweepTx := ht.Miner.GetNumTxsFromMempool(1)[0]
bobSweepTx := ht.GetNumTxsFromMempool(1)[0]
// We expect two pending sweeps for Bob - anchor and commit outputs.
pendingSweepBob := ht.AssertNumPendingSweeps(bob, 2)[0]
@ -1466,7 +1466,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
// created and published.
aliceStartPosition = 1
txns := ht.Miner.GetNumTxsFromMempool(2)
txns := ht.GetNumTxsFromMempool(2)
aliceFirstSweepTx = txns[0]
// Reassign if the second tx is larger.
@ -1503,7 +1503,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
// commit output together because they have different deadlines.
// - Bob's previous sweeping tx, which sweeps both his anchor and
// commit outputs, at the starting fee rate.
txns := ht.Miner.GetNumTxsFromMempool(2)
txns := ht.GetNumTxsFromMempool(2)
// Assume the first tx is Alice's sweeping tx, if the second tx has a
// larger output value, then that's Alice's as her to_local value is
@ -1611,7 +1611,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
// commit outputs, using the increased fee rate.
// - Bob's previous sweeping tx, which sweeps both his anchor
// and commit outputs, at the possible increased fee rate.
txns = ht.Miner.GetNumTxsFromMempool(2)
txns = ht.GetNumTxsFromMempool(2)
// Assume the first tx is Alice's sweeping tx, if the second tx
// has a larger output value, then that's Alice's as her
@ -1691,14 +1691,14 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
// Make sure Alice's old sweeping tx has been removed from the
// mempool.
ht.Miner.AssertTxNotInMempool(aliceSweepTx.TxHash())
ht.AssertTxNotInMempool(aliceSweepTx.TxHash())
// Make sure Bob's old sweeping tx has been removed from the
// mempool. Since Bob's sweeping tx will only be successfully
// RBFed every 4 blocks, his old sweeping tx only will be
// removed when there are 4 blocks increased.
if bobPosition%4 == 0 {
ht.Miner.AssertTxNotInMempool(bobSweepTx.TxHash())
ht.AssertTxNotInMempool(bobSweepTx.TxHash())
}
// We should see two txns in the mempool:
@ -1706,7 +1706,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
// commit outputs, using the increased fee rate.
// - Bob's previous sweeping tx, which sweeps both his anchor
// and commit outputs, at the possible increased fee rate.
txns := ht.Miner.GetNumTxsFromMempool(2)
txns := ht.GetNumTxsFromMempool(2)
// Assume the first tx is Alice's sweeping tx, if the second tx
// has a larger output value, then that's Alice's as her
@ -1911,7 +1911,7 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
// We expect to see Alice's original tx and her CPFP tx in the
// mempool.
txns := ht.Miner.GetNumTxsFromMempool(2)
txns := ht.GetNumTxsFromMempool(2)
// Find the sweeping tx - assume it's the first item, if it has
// the same txid as the parent tx, use the second item.
@ -1972,7 +1972,7 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
// Since the request doesn't specify a deadline, we expect the default
// deadline to be used.
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
deadline := uint32(currentHeight + sweep.DefaultDeadlineDelta)
// Assert the pending sweep is created with the expected values:
@ -2003,7 +2003,7 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
alice.RPC.BumpFee(bumpFeeReq)
// Alice's old sweeping tx should be replaced.
ht.Miner.AssertTxNotInMempool(sweepTx1.TxHash())
ht.AssertTxNotInMempool(sweepTx1.TxHash())
// Assert the pending sweep is created with the expected values:
// - broadcast attempts: 2.
@ -2035,7 +2035,7 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
alice.RPC.BumpFee(bumpFeeReq)
// Alice's old sweeping tx should be replaced.
ht.Miner.AssertTxNotInMempool(sweepTx2.TxHash())
ht.AssertTxNotInMempool(sweepTx2.TxHash())
// Assert the pending sweep is created with the expected values:
// - broadcast attempts: 3.
@ -2066,7 +2066,7 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
alice.RPC.BumpFee(bumpFeeReq)
// Alice's old sweeping tx should be replaced.
ht.Miner.AssertTxNotInMempool(sweepTx3.TxHash())
ht.AssertTxNotInMempool(sweepTx3.TxHash())
// Assert the pending sweep is created with the expected values:
// - broadcast attempts: 4.
@ -2093,7 +2093,7 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
alice.RPC.BumpFee(bumpFeeReq)
// Alice's old sweeping tx should be replaced.
ht.Miner.AssertTxNotInMempool(sweepTx4.TxHash())
ht.AssertTxNotInMempool(sweepTx4.TxHash())
// Assert the pending sweep is created with the expected values:
// - broadcast attempts: 5.

View file

@ -1535,7 +1535,7 @@ func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
// Before we publish the tx that spends the p2tr transaction, we want to
// register a spend listener that we expect to fire after mining the
// block.
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
// For a Taproot output we cannot leave the outpoint empty. Let's make
// sure the API returns the correct error here.
@ -1609,7 +1609,7 @@ func confirmAddress(ht *lntest.HarnessTest, hn *node.HarnessNode,
addrPkScript, err := txscript.PayToAddrScript(parsedAddr)
require.NoError(ht, err)
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
req := &chainrpc.ConfRequest{
Script: addrPkScript,
Txid: txid[:],

View file

@ -151,7 +151,7 @@ func TestLightningNetworkDaemon(t *testing.T) {
}
}
_, height := harnessTest.Miner.GetBestBlock()
_, height := harnessTest.GetBestBlock()
t.Logf("=========> tests finished for tranche: %v, tested %d "+
"cases, end height: %d\n", trancheIndex, len(testCases), height)
}

View file

@ -962,7 +962,7 @@ func testZeroConfReorg(ht *lntest.HarnessTest) {
ht.Miner.AssertMinerBlockHeightDelta(tempMiner, 1)
// Wait for Carol to sync to the original miner's chain.
_, minerHeight := ht.Miner.GetBestBlock()
_, minerHeight := ht.GetBestBlock()
ht.WaitForNodeBlockHeight(carol, minerHeight)
// Now we'll disconnect Carol's chain backend from the original miner

View file

@ -433,10 +433,10 @@ func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest {
st.feeService.Reset()
// Record block height.
_, startHeight := h.Miner.GetBestBlock()
_, startHeight := h.GetBestBlock()
st.Cleanup(func() {
_, endHeight := h.Miner.GetBestBlock()
_, endHeight := h.GetBestBlock()
st.Logf("finished test: %s, start height=%d, end height=%d, "+
"mined blocks=%d", st.manager.currentTestCase,
@ -2158,7 +2158,7 @@ func (h *HarnessTest) SendCoins(a, b *node.HarnessNode,
TargetConf: 6,
}
a.RPC.SendCoins(sendReq)
tx := h.Miner.GetNumTxsFromMempool(1)[0]
tx := h.GetNumTxsFromMempool(1)[0]
return tx
}

View file

@ -2568,7 +2568,7 @@ func (h *HarnessTest) AssertClosingTxInMempool(cp *lnrpc.ChannelPoint,
// Get the closing tx from the mempool.
op := h.OutPointFromChannelPoint(cp)
closeTx := h.Miner.AssertOutpointInMempool(op)
closeTx := h.AssertOutpointInMempool(op)
return closeTx
}
@ -2582,7 +2582,7 @@ func (h *HarnessTest) MineClosingTx(cp *lnrpc.ChannelPoint) *wire.MsgTx {
// Get the closing tx from the mempool.
op := h.OutPointFromChannelPoint(cp)
closeTx := h.Miner.AssertOutpointInMempool(op)
closeTx := h.AssertOutpointInMempool(op)
// Mine a block to confirm the closing transaction and potential anchor
// sweep.

View file

@ -80,7 +80,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
// If we expect transactions to be included in the blocks we'll mine,
// we wait here until they are seen in the miner's mempool.
txids := h.Miner.AssertNumTxsInMempool(numTxs)
txids := h.AssertNumTxsInMempool(numTxs)
// Mine blocks.
blocks := h.Miner.MineBlocksSlow(num)
@ -118,7 +118,7 @@ func (h *HarnessTest) DisconnectMiner() {
// cleanMempool mines blocks till the mempool is empty and asserts all active
// nodes have synced to the chain.
func (h *HarnessTest) cleanMempool() {
_, startHeight := h.Miner.GetBestBlock()
_, startHeight := h.GetBestBlock()
// Mining the blocks slow to give `lnd` more time to sync.
var bestBlock *wire.MsgBlock
@ -126,7 +126,7 @@ func (h *HarnessTest) cleanMempool() {
// If mempool is empty, exit.
mem := h.Miner.GetRawMempool()
if len(mem) == 0 {
_, height := h.Miner.GetBestBlock()
_, height := h.GetBestBlock()
h.Logf("Mined %d blocks when cleanup the mempool",
height-startHeight)
@ -157,7 +157,7 @@ func (h *HarnessTest) cleanMempool() {
// TODO(yy): remove this workaround when syncing blocks are unified in all the
// subsystems.
func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
_, startHeight := h.Miner.GetBestBlock()
_, startHeight := h.GetBestBlock()
err := wait.NoError(func() error {
resp := hn.RPC.PendingChannels()
@ -169,7 +169,7 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
"close channel to be zero")
}
_, height := h.Miner.GetBestBlock()
_, height := h.GetBestBlock()
h.Logf("Mined %d blocks while waiting for force closed "+
"channel to be resolved", height-startHeight)
@ -179,6 +179,21 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
require.NoErrorf(h, err, "assert force close resolved timeout")
}
// AssertTxInMempool asserts a given transaction can be found in the mempool.
func (h *HarnessTest) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
return h.Miner.AssertTxInMempool(txid)
}
// AssertTxNotInMempool asserts a given transaction cannot be found in the
// mempool. It assumes the mempool is not empty.
//
// NOTE: this should be used after `AssertTxInMempool` to ensure the tx has
// entered the mempool before. Otherwise it might give false positive and the
// tx may enter the mempool after the check.
func (h *HarnessTest) AssertTxNotInMempool(txid chainhash.Hash) *wire.MsgTx {
return h.Miner.AssertTxNotInMempool(txid)
}
// AssertNumTxsInMempool polls until finding the desired number of transactions
// in the provided miner's mempool. It will asserrt if this number is not met
// after the given timeout.
@ -186,9 +201,25 @@ func (h *HarnessTest) AssertNumTxsInMempool(n int) []*chainhash.Hash {
return h.Miner.AssertNumTxsInMempool(n)
}
// AssertOutpointInMempool asserts a given outpoint can be found in the mempool.
func (h *HarnessTest) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx {
return h.Miner.AssertOutpointInMempool(op)
}
// AssertTxInBlock asserts that a given txid can be found in the passed block.
func (h *HarnessTest) AssertTxInBlock(block *wire.MsgBlock,
txid *chainhash.Hash) {
h.Miner.AssertTxInBlock(block, txid)
}
// GetNumTxsFromMempool polls until finding the desired number of transactions
// in the miner's mempool and returns the full transactions to the caller.
func (h *HarnessTest) GetNumTxsFromMempool(n int) []*wire.MsgTx {
return h.Miner.GetNumTxsFromMempool(n)
}
// GetBestBlock makes a RPC request to miner and asserts.
func (h *HarnessTest) GetBestBlock() (*chainhash.Hash, int32) {
return h.Miner.GetBestBlock()
}