Skip to content

Commit f27f9f2

Browse files
authored
Merge pull request #8892 from lightningnetwork/yy-itest-miner
Beat [0/4]: improve itest miner
2 parents 578e1d4 + 9180762 commit f27f9f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1255
-999
lines changed

discovery/gossiper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,8 @@ func (d *AuthenticatedGossiper) Stop() error {
750750
}
751751

752752
func (d *AuthenticatedGossiper) stop() {
753-
log.Info("Authenticated Gossiper is stopping")
754-
defer log.Info("Authenticated Gossiper stopped")
753+
log.Debug("Authenticated Gossiper is stopping")
754+
defer log.Debug("Authenticated Gossiper stopped")
755755

756756
d.blockEpochs.Cancel()
757757

docs/release-notes/release-notes-0.18.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116

117117
## Tooling and Documentation
118118

119+
* [`lntest.HarnessTest` no longer exposes `Miner`
120+
instance](https://github.com/lightningnetwork/lnd/pull/8892). Instead, it's
121+
changed into a private `miner` instance and all mining related assertions are
122+
now only accessible via the harness.
123+
119124
# Contributors (Alphabetical Order)
120125

121126
* Andras Banki-Horvath

htlcswitch/decayedlog.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ func (d *DecayedLog) initBuckets() error {
149149

150150
// Stop halts the garbage collector and closes boltdb.
151151
func (d *DecayedLog) Stop() error {
152+
log.Debugf("DecayedLog shutting down...")
153+
defer log.Debugf("DecayedLog shutdown complete")
154+
152155
if !atomic.CompareAndSwapInt32(&d.stopped, 0, 1) {
153156
return nil
154157
}

itest/lnd_channel_backup_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func newChanRestoreScenario(ht *lntest.HarnessTest, ct lnrpc.CommitmentType,
9494
ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, dave)
9595

9696
// Mine a block to confirm the funds.
97-
ht.MineBlocks(1)
97+
ht.MineBlocksAndAssertNumTxes(1, 2)
9898

9999
// For the anchor output case we need two UTXOs for Carol so she can
100100
// sweep both the local and remote anchor.
@@ -267,7 +267,7 @@ func testChannelBackupRestoreBasic(ht *lntest.HarnessTest) {
267267
// the node from seed, then manually recover
268268
// the channel backup.
269269
return chanRestoreViaRPC(
270-
st, password, mnemonic, multi, oldNode,
270+
st, password, mnemonic, multi,
271271
)
272272
},
273273
},
@@ -291,7 +291,7 @@ func testChannelBackupRestoreBasic(ht *lntest.HarnessTest) {
291291
// create a new nodeRestorer that will restore
292292
// using the on-disk channel.backup.
293293
return chanRestoreViaRPC(
294-
st, password, mnemonic, multi, oldNode,
294+
st, password, mnemonic, multi,
295295
)
296296
},
297297
},
@@ -523,7 +523,7 @@ func runChanRestoreScenarioUnConfirmed(ht *lntest.HarnessTest, useFile bool) {
523523
// In our nodeRestorer function, we'll restore the node from seed, then
524524
// manually recover the channel backup.
525525
restoredNodeFunc := chanRestoreViaRPC(
526-
ht, crs.password, crs.mnemonic, multi, dave,
526+
ht, crs.password, crs.mnemonic, multi,
527527
)
528528

529529
// Test the scenario.
@@ -624,8 +624,8 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
624624

625625
var fundingShim *lnrpc.FundingShim
626626
if ct == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
627-
_, minerHeight := ht.Miner.GetBestBlock()
628-
thawHeight := uint32(minerHeight + thawHeightDelta)
627+
minerHeight := ht.CurrentHeight()
628+
thawHeight := minerHeight + thawHeightDelta
629629

630630
fundingShim, _ = deriveFundingShim(
631631
ht, dave, carol, crs.params.Amt, thawHeight, true, ct,
@@ -658,7 +658,7 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
658658
// Now that we have Dave's backup file, we'll create a new nodeRestorer
659659
// that we'll restore using the on-disk channels.backup.
660660
restoredNodeFunc := chanRestoreViaRPC(
661-
ht, crs.password, crs.mnemonic, multi, dave,
661+
ht, crs.password, crs.mnemonic, multi,
662662
)
663663

664664
// Test the scenario.
@@ -687,7 +687,7 @@ func testChannelBackupRestoreLegacy(ht *lntest.HarnessTest) {
687687
// In our nodeRestorer function, we'll restore the node from seed, then
688688
// manually recover the channel backup.
689689
restoredNodeFunc := chanRestoreViaRPC(
690-
ht, crs.password, crs.mnemonic, multi, dave,
690+
ht, crs.password, crs.mnemonic, multi,
691691
)
692692

693693
// Test the scenario.
@@ -779,11 +779,11 @@ func runChanRestoreScenarioForceClose(ht *lntest.HarnessTest, zeroConf bool) {
779779
// Now that we have Dave's backup file, we'll create a new nodeRestorer
780780
// that will restore using the on-disk channel.backup.
781781
restoredNodeFunc := chanRestoreViaRPC(
782-
ht, crs.password, crs.mnemonic, multi, dave,
782+
ht, crs.password, crs.mnemonic, multi,
783783
)
784784

785785
// We now wait until both Dave's closing tx.
786-
ht.Miner.AssertNumTxsInMempool(1)
786+
ht.AssertNumTxsInMempool(1)
787787

788788
// Now that we're able to make our restored now, we'll shutdown the old
789789
// Dave node as we'll be storing it shortly below.
@@ -1272,7 +1272,7 @@ func testDataLossProtection(ht *lntest.HarnessTest) {
12721272
ht.MineBlocks(1)
12731273

12741274
// Dave should sweep his funds.
1275-
ht.Miner.AssertNumTxsInMempool(1)
1275+
ht.AssertNumTxsInMempool(1)
12761276

12771277
// Mine a block to confirm the sweep, and make sure Dave got his
12781278
// balance back.
@@ -1388,8 +1388,7 @@ func createLegacyRevocationChannel(ht *lntest.HarnessTest,
13881388
// instance which will restore the target node from a password+seed, then
13891389
// trigger a SCB restore using the RPC interface.
13901390
func chanRestoreViaRPC(ht *lntest.HarnessTest, password []byte,
1391-
mnemonic []string, multi []byte,
1392-
oldNode *node.HarnessNode) nodeRestorer {
1391+
mnemonic []string, multi []byte) nodeRestorer {
13931392

13941393
backup := &lnrpc.RestoreChanBackupRequest_MultiChanBackup{
13951394
MultiChanBackup: multi,
@@ -1428,7 +1427,7 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
14281427

14291428
// Mine a block to trigger the sweeps.
14301429
ht.MineBlocks(1)
1431-
ht.Miner.AssertNumTxsInMempool(expectedTxes)
1430+
ht.AssertNumTxsInMempool(expectedTxes)
14321431

14331432
// Carol should consider the channel pending force close (since she is
14341433
// waiting for her sweep to confirm).
@@ -1462,9 +1461,9 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
14621461

14631462
// Mine a block to trigger the sweeps.
14641463
ht.MineEmptyBlocks(1)
1465-
daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
1464+
daveSweep := ht.AssertNumTxsInMempool(1)[0]
14661465
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1467-
ht.Miner.AssertTxInBlock(block, daveSweep)
1466+
ht.AssertTxInBlock(block, daveSweep)
14681467

14691468
// Now the channel should be fully closed also from Dave's POV.
14701469
ht.AssertNumPendingForceClose(dave, 0)
@@ -1510,7 +1509,7 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
15101509

15111510
// Upon reconnection, the nodes should detect that Dave is out of sync.
15121511
// Carol should force close the channel using her latest commitment.
1513-
ht.Miner.AssertNumTxsInMempool(1)
1512+
ht.AssertNumTxsInMempool(1)
15141513

15151514
// Channel should be in the state "waiting close" for Carol since she
15161515
// broadcasted the force close tx.

itest/lnd_channel_force_close_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
160160

161161
// Fetch starting height of this test so we can compute the block
162162
// heights we expect certain events to take place.
163-
_, curHeight := ht.Miner.GetBestBlock()
163+
curHeight := int32(ht.CurrentHeight())
164164

165165
// Using the current height of the chain, derive the relevant heights
166166
// for incubating two-stage htlcs.
@@ -214,7 +214,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
214214
ht.AssertNumUTXOs(alice, expectedUtxos)
215215

216216
// We expect to see Alice's force close tx in the mempool.
217-
ht.Miner.GetNumTxsFromMempool(1)
217+
ht.GetNumTxsFromMempool(1)
218218

219219
// Mine a block which should confirm the commitment transaction
220220
// broadcast as a result of the force closure. Once mined, we also
@@ -278,7 +278,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
278278

279279
// Carol's sweep tx should be in the mempool already, as her output is
280280
// not timelocked.
281-
carolTx := ht.Miner.GetNumTxsFromMempool(1)[0]
281+
carolTx := ht.GetNumTxsFromMempool(1)[0]
282282

283283
// Carol's sweeping tx should have 2-input-1-output shape.
284284
require.Len(ht, carolTx.TxIn, 2)
@@ -389,11 +389,11 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
389389
// So we fetch the node's mempool to ensure it has been properly
390390
// broadcast.
391391
ht.MineEmptyBlocks(1)
392-
sweepingTXID := ht.Miner.AssertNumTxsInMempool(1)[0]
392+
sweepingTXID := ht.AssertNumTxsInMempool(1)[0]
393393

394394
// Fetch the sweep transaction, all input it's spending should be from
395395
// the commitment transaction which was broadcast on-chain.
396-
sweepTx := ht.Miner.GetRawTransaction(sweepingTXID)
396+
sweepTx := ht.GetRawTransaction(sweepingTXID)
397397
for _, txIn := range sweepTx.MsgTx().TxIn {
398398
require.Equal(ht, &txIn.PreviousOutPoint.Hash, closingTxID,
399399
"sweep transaction not spending from commit")
@@ -431,7 +431,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
431431
ht.MineBlocksAndAssertNumTxes(1, 1)
432432

433433
// Update current height
434-
_, curHeight = ht.Miner.GetBestBlock()
434+
curHeight = int32(ht.CurrentHeight())
435435

436436
// checkForceClosedChannelNumHtlcs verifies that a force closed channel
437437
// has the proper number of htlcs.
@@ -485,7 +485,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
485485
// number of blocks we have generated since adding it to the nursery,
486486
// and take an additional block off so that we end up one block shy of
487487
// the expiry height, and add the block padding.
488-
_, currentHeight := ht.Miner.GetBestBlock()
488+
currentHeight := int32(ht.CurrentHeight())
489489
cltvHeightDelta := int(htlcExpiryHeight - uint32(currentHeight) - 1)
490490

491491
// Advance the blockchain until just before the CLTV expires, nothing
@@ -547,7 +547,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
547547
// NOTE: after restart, all the htlc timeout txns will be offered to
548548
// the sweeper with `Immediate` set to true, so they won't be
549549
// aggregated.
550-
htlcTxIDs := ht.Miner.AssertNumTxsInMempool(numInvoices)
550+
htlcTxIDs := ht.AssertNumTxsInMempool(numInvoices)
551551

552552
// Retrieve each htlc timeout txn from the mempool, and ensure it is
553553
// well-formed. This entails verifying that each only spends from
@@ -567,7 +567,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
567567
// on-chain. In case of an anchor type channel, we expect one
568568
// extra input that is not spending from the commitment, that
569569
// is added for fees.
570-
htlcTx := ht.Miner.GetRawTransaction(htlcTxID)
570+
htlcTx := ht.GetRawTransaction(htlcTxID)
571571

572572
// Ensure the htlc transaction has the expected number of
573573
// inputs.
@@ -662,7 +662,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
662662

663663
// Advance the chain until just before the 2nd-layer CSV delays expire.
664664
// For anchor channels this is one block earlier.
665-
_, currentHeight = ht.Miner.GetBestBlock()
665+
currentHeight = int32(ht.CurrentHeight())
666666
ht.Logf("current height: %v, htlcCsvMaturityHeight=%v", currentHeight,
667667
htlcCsvMaturityHeight)
668668
numBlocks := int(htlcCsvMaturityHeight - uint32(currentHeight) - 2)
@@ -709,7 +709,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
709709
// NOTE: we don't check `len(mempool) == 1` because it will
710710
// give us false positive.
711711
err := wait.NoError(func() error {
712-
mempool := ht.Miner.GetRawMempool()
712+
mempool := ht.Miner().GetRawMempool()
713713
if len(mempool) == 2 {
714714
return nil
715715
}
@@ -733,10 +733,10 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
733733
}
734734

735735
// Wait for the single sweep txn to appear in the mempool.
736-
htlcSweepTxID := ht.Miner.AssertNumTxsInMempool(1)[0]
736+
htlcSweepTxID := ht.AssertNumTxsInMempool(1)[0]
737737

738738
// Fetch the htlc sweep transaction from the mempool.
739-
htlcSweepTx := ht.Miner.GetRawTransaction(htlcSweepTxID)
739+
htlcSweepTx := ht.GetRawTransaction(htlcSweepTxID)
740740

741741
// Ensure the htlc sweep transaction only has one input for each htlc
742742
// Alice extended before force closing.
@@ -818,7 +818,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
818818
// Generate the final block that sweeps all htlc funds into the user's
819819
// wallet, and make sure the sweep is in this block.
820820
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
821-
ht.Miner.AssertTxInBlock(block, htlcSweepTxID)
821+
ht.AssertTxInBlock(block, htlcSweepTxID)
822822

823823
// Now that the channel has been fully swept, it should no longer show
824824
// up within the pending channels RPC.
@@ -935,7 +935,7 @@ func testFailingChannel(ht *lntest.HarnessTest) {
935935
ht.MineEmptyBlocks(1)
936936

937937
// Carol should have broadcast her sweeping tx.
938-
ht.Miner.AssertNumTxsInMempool(1)
938+
ht.AssertNumTxsInMempool(1)
939939

940940
// Mine two blocks to confirm Carol's sweeping tx, which will by now
941941
// Alice's commit output should be offered to her sweeper.

itest/lnd_channel_funding_fund_max_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/lightningnetwork/lnd/lnwallet"
1616
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1717
"github.com/lightningnetwork/lnd/lnwire"
18-
"github.com/stretchr/testify/require"
1918
)
2019

2120
type chanFundMaxTestCase struct {
@@ -317,8 +316,7 @@ func fundingFee(numInput int, change bool) btcutil.Amount {
317316
// sweepNodeWalletAndAssert sweeps funds from a node wallet.
318317
func sweepNodeWalletAndAssert(ht *lntest.HarnessTest, node *node.HarnessNode) {
319318
// New miner address we will sweep all funds to.
320-
minerAddr, err := ht.Miner.NewAddress()
321-
require.NoError(ht, err)
319+
minerAddr := ht.NewMinerAddress()
322320

323321
// Send all funds back to the miner node.
324322
node.RPC.SendCoins(&lnrpc.SendCoinsRequest{

itest/lnd_channel_graph_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func testGraphTopologyNtfns(ht *lntest.HarnessTest, pinned bool) {
316316
ht.AssertNumNodeAnns(alice, alice.PubKeyStr, 1)
317317
ht.AssertNumNodeAnns(alice, bob.PubKeyStr, 1)
318318

319-
_, blockHeight := ht.Miner.GetBestBlock()
319+
blockHeight := ht.CurrentHeight()
320320

321321
// Now we'll test that updates are properly sent after channels are
322322
// closed within the network.
@@ -326,7 +326,7 @@ func testGraphTopologyNtfns(ht *lntest.HarnessTest, pinned bool) {
326326
// notification indicating so.
327327
closedChan := ht.AssertTopologyChannelClosed(alice, chanPoint)
328328

329-
require.Equal(ht, uint32(blockHeight+1), closedChan.ClosedHeight,
329+
require.Equal(ht, blockHeight+1, closedChan.ClosedHeight,
330330
"close heights of channel mismatch")
331331

332332
fundingTxid := ht.OutPointFromChannelPoint(chanPoint)

itest/lnd_coop_close_with_htlcs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func coopCloseWithHTLCs(ht *lntest.HarnessTest) {
117117
)
118118

119119
// Wait for the close tx to be in the Mempool.
120-
ht.Miner.AssertTxInMempool(&closeTxid)
120+
ht.AssertTxInMempool(&closeTxid)
121121

122122
// Wait for it to get mined and finish tearing down.
123123
ht.AssertStreamChannelCoopClosed(alice, chanPoint, false, closeClient)

itest/lnd_estimate_route_fee_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ func testEstimateRouteFee(ht *lntest.HarnessTest) {
359359

360360
mts.ht.CloseChannelAssertPending(mts.bob, channelPointBobPaula, false)
361361
mts.ht.CloseChannelAssertPending(mts.eve, channelPointEvePaula, false)
362+
ht.MineBlocksAndAssertNumTxes(1, 2)
363+
362364
mts.closeChannels()
363365
}
364366

0 commit comments

Comments
 (0)