lntemp+lntest: always wait for nodes sync after mining blocks

In this commit, we introduce two mining methods, `MineBlocks` and
`MineBlocksAndAssertNumTxes`, to `HarnessTest`. These methods are
different from the miner's methods as they would 1) mine the blocks
slowly and 2) assert all active nodes have synced. The miner's methods
are kept for future tests such as mining blocks really fast and see the
behavior of `lnd`.
This commit is contained in:
yyforyongyu 2022-08-24 05:28:31 +08:00
parent f202d27324
commit ab62109865
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
5 changed files with 125 additions and 95 deletions

View File

@ -194,7 +194,7 @@ func (h *HarnessTest) SetupStandbyNodes() {
// We generate several blocks in order to give the outputs created
// above a good number of confirmations.
h.Miner.MineBlocks(2)
h.MineBlocks(2)
// Now we want to wait for the nodes to catch up.
h.WaitForBlockchainSync(h.Alice)
@ -749,7 +749,7 @@ func (h *HarnessTest) OpenChannel(alice, bob *node.HarnessNode,
// channel has been opened. The funding transaction should be found
// within the first newly mined block. We mine 6 blocks so that in the
// case that the channel is public, it is announced to the network.
block := h.Miner.MineBlocksAndAssertNumTxes(6, 1)[0]
block := h.MineBlocksAndAssertNumTxes(6, 1)[0]
// Wait for the channel open event.
fundingChanPoint := h.WaitForChannelOpenEvent(chanOpenUpdate)
@ -938,7 +938,7 @@ func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode,
// Otherwise, we'll generate 1 new blocks to ensure the output gains a
// sufficient number of confirmations and wait for the balance to
// reflect what's expected.
h.Miner.MineBlocks(1)
h.MineBlocks(1)
expectedBalance := btcutil.Amount(initialBalance.ConfirmedBalance) + amt
h.WaitForBalanceConfirmed(target, expectedBalance)
@ -1091,11 +1091,11 @@ func (h *HarnessTest) CleanupForceClose(hn *node.HarnessNode,
//
// The commit sweep resolver is able to broadcast the sweep tx up to
// one block before the CSV elapses, so wait until defaulCSV-1.
h.Miner.MineBlocks(lntest.DefaultCSV - 1)
h.MineBlocks(lntest.DefaultCSV - 1)
// The node should now sweep the funds, clean up by mining the sweeping
// tx.
h.Miner.MineBlocksAndAssertNumTxes(1, 1)
h.MineBlocksAndAssertNumTxes(1, 1)
// Mine blocks to get any second level HTLC resolved. If there are no
// HTLCs, this will behave like h.AssertNumPendingCloseChannels.
@ -1120,7 +1120,7 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
resp := hn.RPC.PendingChannels()
total := len(resp.PendingForceClosingChannels)
if total != 0 {
h.Miner.MineBlocksSlow(1)
h.MineBlocks(1)
return fmt.Errorf("expected num of pending force " +
"close channel to be zero")
@ -1191,22 +1191,44 @@ func (h *HarnessTest) RestartNodeAndRestoreDB(hn *node.HarnessNode) {
h.WaitForBlockchainSync(hn)
}
// MineBlocksAssertNodesSync mines blocks and asserts all active nodes have
// synced to the chain. Use this method when more than 3 blocks are mined to
// make sure the nodes stay synced.
// MineBlocks mines blocks and asserts all active nodes have synced to the
// chain.
//
// TODO(yy): replace directly mining with this one.
func (h *HarnessTest) MineBlocksAssertNodesSync(num uint32) {
// If we are mining more than 3 blocks, use the slow mining.
if num > 3 {
h.Miner.MineBlocksSlow(num)
} else {
// Mine the blocks.
h.Miner.MineBlocks(num)
}
// NOTE: this differs from miner's `MineBlocks` as it requires the nodes to be
// synced.
func (h *HarnessTest) MineBlocks(num uint32) []*wire.MsgBlock {
// Mining the blocks slow to give `lnd` more time to sync.
blocks := h.Miner.MineBlocksSlow(num)
// Make sure all the active nodes are synced.
for _, node := range h.manager.activeNodes {
h.WaitForBlockchainSync(node)
}
h.AssertActiveNodesSynced()
return blocks
}
// MineBlocksAndAssertNumTxes mines blocks and asserts the number of
// transactions are found in the first block. It also asserts all active nodes
// have synced to the chain.
//
// NOTE: this differs from miner's `MineBlocks` as it requires the nodes to be
// synced.
func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
numTxs int) []*wire.MsgBlock {
// 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)
// Mine blocks.
blocks := h.Miner.MineBlocksSlow(num)
// Assert that all the transactions were included in the first block.
for _, txid := range txids {
h.Miner.AssertTxInBlock(blocks[0], txid)
}
// Finally, make sure all the active nodes are synced.
h.AssertActiveNodesSynced()
return blocks
}

View File

@ -498,7 +498,7 @@ func (h *HarnessTest) AssertStreamChannelCoopClosed(hn *node.HarnessNode,
if anchors {
expectedTxes = 2
}
block := h.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
block := h.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
// Consume one close event and assert the closing txid can be found in
// the block.
@ -542,7 +542,7 @@ func (h *HarnessTest) AssertStreamChannelForceClosed(hn *node.HarnessNode,
if anchors {
expectedTxes = 2
}
block := h.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
block := h.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
// Consume one close event and assert the closing txid can be found in
// the block.
@ -1287,3 +1287,10 @@ func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
return target
}
// AssertActiveNodesSynced asserts all active nodes have synced to the chain.
func (h *HarnessTest) AssertActiveNodesSynced() {
for _, node := range h.manager.activeNodes {
h.WaitForBlockchainSync(node)
}
}

View File

@ -29,7 +29,8 @@ const (
// minerLogDir is the default log dir for the miner node.
minerLogDir = ".minerlogs"
slowMineDelay = 20 * time.Millisecond
// slowMineDelay defines a wait period between mining new blocks.
slowMineDelay = 100 * time.Millisecond
)
var harnessNetParams = &chaincfg.RegressionNetParams

View File

@ -92,7 +92,7 @@ func newChanRestoreScenario(ht *lntemp.HarnessTest, ct lnrpc.CommitmentType,
ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, dave)
// Mine a block to confirm the funds.
ht.MineBlocksAssertNodesSync(1)
ht.MineBlocks(1)
// For the anchor output case we need two UTXOs for Carol so she can
// sweep both the local and remote anchor.
@ -510,7 +510,7 @@ func runChanRestoreScenarioUnConfirmed(ht *lntemp.HarnessTest, useFile bool) {
// the only backup we have. We should still be able to restore it. To
// simulate time passing, we mine some blocks to get the channel
// confirmed _after_ we saved the backup.
ht.Miner.MineBlocksAndAssertNumTxes(6, 1)
ht.MineBlocksAndAssertNumTxes(6, 1)
// In our nodeRestorer function, we'll restore the node from seed, then
// manually recover the channel backup.
@ -759,7 +759,7 @@ func runChanRestoreScenarioForceClose(ht *lntemp.HarnessTest, zeroConf bool) {
ht.Shutdown(dave)
// Mine a block to confirm the closing tx from Dave.
ht.Miner.MineBlocksAndAssertNumTxes(1, 2)
ht.MineBlocksAndAssertNumTxes(1, 2)
// To make sure the channel state is advanced correctly if the channel
// peer is not online at first, we also shutdown Carol.
@ -1274,7 +1274,7 @@ func testDataLossProtection(ht *lntemp.HarnessTest) {
// Mine a block to confirm the sweep, and make sure Dave got his
// balance back.
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
ht.MineBlocksAndAssertNumTxes(1, 1)
ht.AssertNodeNumChannels(dave, 0)
err := wait.NoError(func() error {
@ -1376,7 +1376,7 @@ func createLegacyRevocationChannel(ht *lntemp.HarnessTest,
OutputIndex: upd.ChanPending.OutputIndex,
}
ht.Miner.MineBlocksAndAssertNumTxes(6, 1)
ht.MineBlocksAndAssertNumTxes(6, 1)
ht.AssertTopologyChannelOpen(from, chanPoint)
ht.AssertTopologyChannelOpen(to, chanPoint)
}
@ -1449,7 +1449,7 @@ func assertTimeLockSwept(ht *lntemp.HarnessTest, carol, dave *node.HarnessNode,
ht.AssertNumPendingForceClose(dave, 1)
// Mine the sweep (and anchor) tx(ns).
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Now Carol should consider the channel fully closed.
ht.AssertNumPendingForceClose(carol, 0)
@ -1467,9 +1467,9 @@ func assertTimeLockSwept(ht *lntemp.HarnessTest, carol, dave *node.HarnessNode,
// The commit sweep resolver publishes the sweep tx at defaultCSV-1 and
// we already mined one block after the commitment was published, so
// take that into account.
ht.MineBlocksAssertNodesSync(defaultCSV - 1 - 1)
ht.MineBlocks(defaultCSV - 1 - 1)
daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, daveSweep)
// Now the channel should be fully closed also from Dave's POV.
@ -1534,7 +1534,7 @@ func assertDLPExecuted(ht *lntemp.HarnessTest,
ht.RestartNode(dave)
// Generate a single block, which should confirm the closing tx.
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Dave should consider the channel pending force close (since he is
// waiting for his sweep to confirm).
@ -1550,7 +1550,7 @@ func assertDLPExecuted(ht *lntemp.HarnessTest,
ht.Miner.AssertNumTxsInMempool(1)
// Mine Dave's anchor sweep tx.
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
ht.MineBlocksAndAssertNumTxes(1, 1)
// After Carol's output matures, she should also reclaim her
// funds.
@ -1558,8 +1558,8 @@ func assertDLPExecuted(ht *lntemp.HarnessTest,
// The commit sweep resolver publishes the sweep tx at
// defaultCSV-1 and we already mined one block after the
// commitmment was published, so take that into account.
ht.Miner.MineBlocks(defaultCSV - 1 - 1)
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
ht.MineBlocks(defaultCSV - 1 - 1)
ht.MineBlocksAndAssertNumTxes(1, 1)
// Now the channel should be fully closed also from Carol's POV.
ht.AssertNumPendingForceClose(carol, 0)
@ -1571,8 +1571,8 @@ func assertDLPExecuted(ht *lntemp.HarnessTest,
resp.PendingForceClosingChannels[0].BlocksTilMaturity
require.Positive(ht, blocksTilMaturity)
ht.Miner.MineBlocks(uint32(blocksTilMaturity))
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
ht.MineBlocks(uint32(blocksTilMaturity))
ht.MineBlocksAndAssertNumTxes(1, 1)
// Now Dave should consider the channel fully closed.
ht.AssertNumPendingForceClose(dave, 0)
@ -1583,7 +1583,7 @@ func assertDLPExecuted(ht *lntemp.HarnessTest,
ht.Miner.AssertNumTxsInMempool(expectedTxes)
// Mine the sweep tx.
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Now Dave should consider the channel fully closed.
ht.AssertNumPendingForceClose(dave, 0)
@ -1594,8 +1594,8 @@ func assertDLPExecuted(ht *lntemp.HarnessTest,
// The commit sweep resolver publishes the sweep tx at
// defaultCSV-1 and we already mined one block after the
// commitmment was published, so take that into account.
ht.Miner.MineBlocks(defaultCSV - 1 - 1)
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
ht.MineBlocks(defaultCSV - 1 - 1)
ht.MineBlocksAndAssertNumTxes(1, 1)
// Now the channel should be fully closed also from Carol's
// POV.

View File

@ -264,7 +264,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntemp.HarnessTest,
numBlocks := padCLTV(
uint32(finalCltvDelta - lncfg.DefaultOutgoingBroadcastDelta),
)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// Bob's force close transaction should now be found in the mempool. If
// there are anchors, we also expect Bob's anchor sweep.
@ -279,7 +279,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntemp.HarnessTest,
closeTx := ht.Miner.AssertOutpointInMempool(op)
// Mine a block to confirm the closing transaction.
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// At this point, Bob should have canceled backwards the dust HTLC
// that we sent earlier. This means Alice should now only have a single
@ -303,7 +303,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntemp.HarnessTest,
).TxHash()
// Mine a block to confirm the expected transactions.
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// With Bob's HTLC timeout transaction confirmed, there should be no
// active HTLC's on the commitment transaction from Alice -> Bob.
@ -326,7 +326,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntemp.HarnessTest,
// CLTV on top of the usual CSV delay on any outputs that he can
// sweep back to his wallet.
blocksTilMaturity := uint32(forceCloseChan.BlocksTilMaturity)
ht.MineBlocksAssertNodesSync(blocksTilMaturity)
ht.MineBlocks(blocksTilMaturity)
// Check that the sweep spends the expected inputs.
ht.Miner.AssertOutpointInMempool(commitOutpoint)
@ -337,24 +337,24 @@ func runMultiHopHtlcLocalTimeout(ht *lntemp.HarnessTest,
// sweep back to his wallet. We'll subtract one block from our
// current maturity period to assert on the mempool.
numBlocks := uint32(forceCloseChan.BlocksTilMaturity - 1)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// Check that the sweep spends from the mined commitment.
ht.Miner.AssertOutpointInMempool(commitOutpoint)
// Mine a block to confirm Bob's commit sweep tx and assert it
// was in fact mined.
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
ht.MineBlocksAndAssertNumTxes(1, 1)
// Mine an additional block to prompt Bob to broadcast their
// second layer sweep due to the CSV on the HTLC timeout output.
ht.Miner.MineBlocksAndAssertNumTxes(1, 0)
ht.MineBlocksAndAssertNumTxes(1, 0)
ht.Miner.AssertOutpointInMempool(htlcTimeoutOutpoint)
}
// Next, we'll mine a final block that should confirm the sweeping
// transactions left.
ht.MineBlocksAssertNodesSync(1)
ht.MineBlocks(1)
// Once this transaction has been confirmed, Bob should detect that he
// no longer has any pending channels.
@ -440,7 +440,7 @@ func runMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
numBlocks := padCLTV(uint32(
invoiceReq.CltvExpiry - lncfg.DefaultIncomingBroadcastDelta,
))
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// At this point, Carol should broadcast her active commitment
// transaction in order to go to the chain and sweep her HTLC. If there
@ -458,7 +458,7 @@ func runMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
closingTxid := closingTx.TxHash()
// Confirm the commitment.
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Restart bob again.
require.NoError(ht, restartBob())
@ -497,7 +497,7 @@ func runMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
// We'll now mine an additional block which should confirm both the
// second layer transactions.
ht.MineBlocksAssertNodesSync(1)
ht.MineBlocks(1)
// Carol's pending channel report should now show two outputs under
// limbo: her commitment output, as well as the second-layer claim
@ -511,7 +511,7 @@ func runMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
// If we mine 4 additional blocks, then Carol can sweep the second level
// HTLC output.
ht.MineBlocksAssertNodesSync(defaultCSV)
ht.MineBlocks(defaultCSV)
// We should have a new transaction in the mempool.
ht.Miner.AssertNumTxsInMempool(1)
@ -519,7 +519,7 @@ func runMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
// Finally, if we mine an additional block to confirm these two sweep
// transactions, Carol should not show a pending channel in her report
// afterwards.
ht.MineBlocksAssertNodesSync(1)
ht.MineBlocks(1)
ht.AssertNumPendingForceClose(carol, 0)
// The invoice should show as settled for Carol, indicating that it was
@ -550,10 +550,10 @@ func runMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
// Mine enough blocks for Bob's commit output's CLTV to expire
// and sweep it.
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
commitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
ht.Miner.AssertOutpointInMempool(commitOutpoint)
ht.MineBlocksAssertNodesSync(1)
ht.MineBlocks(1)
}
ht.AssertNumPendingForceClose(bob, 0)
@ -644,13 +644,13 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
// CSV expires and the commitment was already mined inside
// AssertStreamChannelForceClosed(), so mine one block less
// than defaultCSV in order to perform mempool assertions.
ht.MineBlocksAssertNodesSync(defaultCSV - blocksMined)
ht.MineBlocks(defaultCSV - blocksMined)
commitSweepTx := ht.Miner.AssertOutpointInMempool(
bobCommitOutpoint,
)
txid := commitSweepTx.TxHash()
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, &txid)
blocksMined = defaultCSV + 1
@ -659,7 +659,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
// We'll now mine enough blocks for the HTLC to expire. After this, Bob
// should hand off the now expired HTLC output to the utxo nursery.
numBlocks := padCLTV(finalCltvDelta)
ht.MineBlocksAssertNodesSync(numBlocks - blocksMined)
ht.MineBlocks(numBlocks - blocksMined)
// Bob's pending channel report should show that he has a single HTLC
// that's now in stage one.
@ -671,7 +671,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
// Next, we'll mine an additional block. This should serve to confirm
// the second layer timeout transaction.
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, &timeoutTx)
// With the second layer timeout transaction confirmed, Bob should have
@ -694,7 +694,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
require.Positive(ht, pendingHtlc.BlocksTilMaturity)
numBlocks = uint32(pendingHtlc.BlocksTilMaturity)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// Now that the CSV/CLTV timelock has expired, the transaction should
// either only sweep the HTLC timeout transaction, or sweep both the
@ -708,7 +708,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
ht.Miner.AssertOutpointInMempool(bobCommitOutpoint)
}
block = ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, &sweepTx)
// At this point, Bob should no longer show any channels as pending
@ -818,7 +818,7 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
// point, Bob should hand off the output to his internal utxo nursery,
// which will broadcast a sweep transaction.
numBlocks := padCLTV(finalCltvDelta - 1)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// If we check Bob's pending channel report, it should show that he has
// a single HTLC that's now in the second stage, as skip the initial
@ -826,7 +826,7 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
ht.AssertNumHTLCsAndStage(bob, bobChanPoint, 1, 2)
// We need to generate an additional block to trigger the sweep.
ht.MineBlocksAssertNodesSync(1)
ht.MineBlocks(1)
// Bob's sweeping transaction should now be found in the mempool at
// this point.
@ -834,7 +834,7 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
// If we mine an additional block, then this should confirm Bob's
// transaction which sweeps the direct HTLC output.
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, sweepTx)
// Now that the sweeping transaction has been confirmed, Bob should
@ -854,14 +854,14 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
require.Positive(ht, forceCloseChan.BlocksTilMaturity)
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
bobCommitOutpoint := wire.OutPoint{Hash: *closeTx, Index: 3}
bobCommitSweep := ht.Miner.AssertOutpointInMempool(
bobCommitOutpoint,
)
bobCommitSweepTxid := bobCommitSweep.TxHash()
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, &bobCommitSweepTxid)
}
ht.AssertNumPendingForceClose(bob, 0)
@ -981,8 +981,8 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
// We'll now mine enough blocks so Carol decides that she needs to go
// on-chain to claim the HTLC as Bob has been inactive.
numBlocks := padCLTV(uint32(invoiceReq.CltvExpiry-
lncfg.DefaultIncomingBroadcastDelta)) - 1
ht.MineBlocksAssertNodesSync(numBlocks)
lncfg.DefaultIncomingBroadcastDelta) - 1)
ht.MineBlocks(numBlocks)
// Carol's commitment transaction should now be in the mempool. If
// there is an anchor, Carol will sweep that too.
@ -1000,7 +1000,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
// Mine a block that should confirm the commit tx, the anchor if
// present and the coinbase.
block := ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
block := ht.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
ht.Miner.AssertTxInBlock(block, &closingTxid)
// Restart bob again.
@ -1041,7 +1041,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
restartAlice := ht.SuspendNode(alice)
// Mine a block to confirm the expected transactions (+ the coinbase).
block = ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
block = ht.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
require.Len(ht, block.Transactions, expectedTxes+1)
// For non-anchor channel types, the nursery will handle sweeping the
@ -1083,7 +1083,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
// We'll now mine a block which should confirm Bob's second layer
// transaction.
block = ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
bobSecondLvlTxid := bobSecondLvlTx.TxHash()
ht.Miner.AssertTxInBlock(block, &bobSecondLvlTxid)
@ -1098,13 +1098,13 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
// If we then mine 3 additional blocks, Carol's second level tx should
// mature, and she can pull the funds from it with a sweep tx.
ht.MineBlocksAssertNodesSync(carolSecondLevelCSV)
ht.MineBlocks(carolSecondLevelCSV)
carolSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
// Mining one additional block, Bob's second level tx is mature, and he
// can sweep the output.
bobSecondLevelCSV -= carolSecondLevelCSV
block = ht.Miner.MineBlocksAndAssertNumTxes(bobSecondLevelCSV, 1)[0]
block = ht.MineBlocksAndAssertNumTxes(bobSecondLevelCSV, 1)[0]
ht.Miner.AssertTxInBlock(block, carolSweep)
bobSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
@ -1116,7 +1116,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
// When we mine one additional block, that will confirm Bob's sweep.
// Now Bob should have no pending channels anymore, as this just
// resolved it by the confirmation of the sweep transaction.
block = ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, &bobSweepTxid)
// With the script-enforced lease commitment type, Alice and Bob still
@ -1138,7 +1138,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
// Mine enough blocks for the timelock to expire.
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// Both Alice and Bob show broadcast their commit sweeps.
aliceCommitOutpoint := wire.OutPoint{
@ -1153,7 +1153,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
).TxHash()
// Confirm their sweeps.
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 2)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 2)[0]
ht.Miner.AssertTxInBlock(block, &aliceCommitSweep)
ht.Miner.AssertTxInBlock(block, &bobCommitSweep)
}
@ -1262,7 +1262,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
// commit sweep tx will be broadcast immediately before it can
// be included in a block, so mine one less than defaultCSV in
// order to perform mempool assertions.
ht.MineBlocksAssertNodesSync(defaultCSV - blocksMined)
ht.MineBlocks(defaultCSV - blocksMined)
blocksMined = defaultCSV
// Alice should now sweep her funds.
@ -1284,7 +1284,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
numBlocks := padCLTV(uint32(
invoiceReq.CltvExpiry - lncfg.DefaultIncomingBroadcastDelta,
))
ht.MineBlocksAssertNodesSync(numBlocks - blocksMined)
ht.MineBlocks(numBlocks - blocksMined)
expectedTxes := 1
if hasAnchors {
@ -1304,7 +1304,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
// Mine a block, which should contain: the commitment, possibly an
// anchor sweep and the coinbase tx.
block := ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
block := ht.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
ht.Miner.AssertTxInBlock(block, &closingTxid)
// Restart bob again.
@ -1342,7 +1342,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
ht.AssertAllTxesSpendFrom(txes, closingTxid)
// Mine a block to confirm the two transactions (+ coinbase).
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Keep track of the second level tx maturity.
carolSecondLevelCSV := uint32(defaultCSV)
@ -1358,7 +1358,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
// We'll now mine a block which should confirm Bob's HTLC sweep
// transaction.
block = ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, &bobHtlcSweepTxid)
carolSecondLevelCSV--
@ -1377,12 +1377,12 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
// If we then mine 3 additional blocks, Carol's second level tx will
// mature, and she should pull the funds.
ht.MineBlocksAssertNodesSync(carolSecondLevelCSV)
ht.MineBlocks(carolSecondLevelCSV)
carolSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
// When Carol's sweep gets confirmed, she should have no more pending
// channels.
block = ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, carolSweep)
ht.AssertNumPendingForceClose(carol, 0)
@ -1401,7 +1401,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
// Mine enough blocks for the timelock to expire.
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// Both Alice and Bob show broadcast their commit sweeps.
aliceCommitOutpoint := wire.OutPoint{
@ -1418,7 +1418,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
bobCommitSweepTxid := bobCommitSweep.TxHash()
// Confirm their sweeps.
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 2)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 2)[0]
ht.Miner.AssertTxInBlock(block, &aliceCommitSweepTxid)
ht.Miner.AssertTxInBlock(block, &bobCommitSweepTxid)
@ -1583,7 +1583,7 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
numBlocks := padCLTV(
uint32(finalCltvDelta - lncfg.DefaultOutgoingBroadcastDelta),
)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
// Bob's force close transaction should now be found in the mempool. If
// there are anchors, we also expect Bob's anchor sweep.
@ -1635,7 +1635,7 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
require.NoError(ht, restartCarol())
// Mine a block to confirm the closing transaction.
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Let Alice settle her invoices. When Bob now gets the preimages, he
// has no other option than to broadcast his second-level transactions
@ -1709,7 +1709,7 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
// Mine a block to confirm the all the transactions, including Carol's
// commitment tx, anchor tx(optional), and the second-level timeout and
// success txes.
ht.Miner.MineBlocksAndAssertNumTxes(1, expectedTxes)
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// At this point, Bob should have broadcast his second layer success
// transaction, and should have sent it to the nursery for incubation,
@ -1723,7 +1723,7 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
if c != lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
// If we then mine additional blocks, Bob can sweep his
// commitment output.
ht.MineBlocksAssertNodesSync(defaultCSV - 2)
ht.MineBlocks(defaultCSV - 2)
// Find the commitment sweep.
bobCommitSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
@ -1756,13 +1756,13 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
// the nursery waits an extra block before sweeping. Before the blocks
// are mined, we should expect to see Bob's commit sweep in the mempool.
case lnrpc.CommitmentType_LEGACY:
ht.Miner.MineBlocksAndAssertNumTxes(2, 1)
ht.MineBlocksAndAssertNumTxes(2, 1)
// Mining one additional block, Bob's second level tx is mature, and he
// can sweep the output. Before the blocks are mined, we should expect
// to see Bob's commit sweep in the mempool.
case lnrpc.CommitmentType_ANCHORS:
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
ht.MineBlocksAndAssertNumTxes(1, 1)
// Since Bob is the initiator of the Bob-Carol script-enforced leased
// channel, he incurs an additional CLTV when sweeping outputs back to
@ -1779,7 +1779,7 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
_, height := ht.Miner.GetBestBlock()
bob.AddToLogf("itest: now mine %d blocks at height %d",
numBlocks, height)
ht.MineBlocksAssertNodesSync(numBlocks)
ht.MineBlocks(numBlocks)
default:
ht.Fatalf("unhandled commitment type %v", c)
@ -1810,7 +1810,7 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
// When we mine one additional block, that will confirm Bob's second
// level sweep. Now Bob should have no pending channels anymore, as
// this just resolved it by the confirmation of the sweep transaction.
block := ht.Miner.MineBlocksAndAssertNumTxes(1, 1)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, &bobSweep)
ht.AssertNumPendingForceClose(bob, 0)
@ -1861,7 +1861,7 @@ func createThreeHopNetwork(ht *lntemp.HarnessTest,
ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, carol)
// Mine 1 block to get the above coins confirmed.
ht.MineBlocksAssertNodesSync(1)
ht.MineBlocks(1)
}
// We'll start the test by creating a channel between Alice and Bob,