Skip to content

Commit f1f3410

Browse files
committed
lntest+itest: add new method CurrentHeight
1 parent 14e7b13 commit f1f3410

14 files changed

+66
-41
lines changed

itest/lnd_channel_backup_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.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,

itest/lnd_channel_force_close_test.go

Lines changed: 4 additions & 4 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.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.
@@ -431,7 +431,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
431431
ht.MineBlocksAndAssertNumTxes(1, 1)
432432

433433
// Update current height
434-
_, curHeight = ht.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.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
@@ -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.GetBestBlock()
665+
currentHeight = int32(ht.CurrentHeight())
666666
ht.Logf("current height: %v, htlcCsvMaturityHeight=%v", currentHeight,
667667
htlcCsvMaturityHeight)
668668
numBlocks := int(htlcCsvMaturityHeight - uint32(currentHeight) - 2)

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.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_funding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func testChannelFundingPersistence(ht *lntest.HarnessTest) {
862862
ht.AssertTxInBlock(block, fundingTxID)
863863

864864
// Get the height that our transaction confirmed at.
865-
_, height := ht.GetBestBlock()
865+
height := int32(ht.CurrentHeight())
866866

867867
// Restart both nodes to test that the appropriate state has been
868868
// persisted and that both nodes recover gracefully.

itest/lnd_hold_invoice_force_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ func testHoldInvoiceForceClose(ht *lntest.HarnessTest) {
5959
require.Len(ht, channel.PendingHtlcs, 1)
6060
activeHtlc := channel.PendingHtlcs[0]
6161

62-
_, currentHeight := ht.GetBestBlock()
62+
currentHeight := ht.CurrentHeight()
6363

6464
// Now we will mine blocks until the htlc expires, and wait for each
6565
// node to sync to our latest height. Sanity check that we won't
6666
// underflow.
67-
require.Greater(ht, activeHtlc.ExpirationHeight, uint32(currentHeight),
67+
require.Greater(ht, activeHtlc.ExpirationHeight, currentHeight,
6868
"expected expiry after current height")
69-
blocksTillExpiry := activeHtlc.ExpirationHeight - uint32(currentHeight)
69+
blocksTillExpiry := activeHtlc.ExpirationHeight - currentHeight
7070

7171
// Alice will go to chain with some delta, sanity check that we won't
7272
// underflow and subtract this from our mined blocks.

itest/lnd_multi-hop_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
20922092
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
20932093

20942094
// Add debug log.
2095-
_, height := ht.GetBestBlock()
2095+
height := ht.CurrentHeight()
20962096
bob.AddToLogf("itest: now mine %d blocks at height %d",
20972097
numBlocks, height)
20982098
ht.MineEmptyBlocks(int(numBlocks) - 1)
@@ -2232,8 +2232,8 @@ func createThreeHopNetwork(ht *lntest.HarnessTest,
22322232
var aliceFundingShim *lnrpc.FundingShim
22332233
var thawHeight uint32
22342234
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
2235-
_, minerHeight := ht.GetBestBlock()
2236-
thawHeight = uint32(minerHeight + thawHeightDelta)
2235+
minerHeight := ht.CurrentHeight()
2236+
thawHeight = minerHeight + thawHeightDelta
22372237
aliceFundingShim, _ = deriveFundingShim(
22382238
ht, alice, bob, chanAmt, thawHeight, true, c,
22392239
)
@@ -2449,10 +2449,10 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
24492449

24502450
// Get the current height to compute number of blocks to mine to
24512451
// trigger the htlc timeout resolver from Bob.
2452-
_, height := ht.GetBestBlock()
2452+
height := ht.CurrentHeight()
24532453

24542454
// We'll now mine enough blocks to trigger Bob's timeout resolver.
2455-
numBlocks = htlc.ExpirationHeight - uint32(height) -
2455+
numBlocks = htlc.ExpirationHeight - height -
24562456
lncfg.DefaultOutgoingBroadcastDelta
24572457

24582458
// We should now have Carol's htlc success tx in the mempool.
@@ -2680,12 +2680,12 @@ func runExtraPreimageFromLocalCommit(ht *lntest.HarnessTest,
26802680

26812681
// Get the current height to compute number of blocks to mine to
26822682
// trigger the timeout resolver from Bob.
2683-
_, height := ht.GetBestBlock()
2683+
height := ht.CurrentHeight()
26842684

26852685
// We'll now mine enough blocks to trigger Bob's htlc timeout resolver
26862686
// to act. Once his timeout resolver starts, it will extract the
26872687
// preimage from Carol's direct spend tx found in the mempool.
2688-
numBlocks = htlc.ExpirationHeight - uint32(height) -
2688+
numBlocks = htlc.ExpirationHeight - height -
26892689
lncfg.DefaultOutgoingBroadcastDelta
26902690

26912691
// Decrease the fee rate used by the sweeper so Bob's timeout tx will

itest/lnd_onchain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) {
486486

487487
// We now update the anchor sweep's deadline to be different than the
488488
// commit sweep so they can won't grouped together.
489-
_, currentHeight := ht.GetBestBlock()
489+
currentHeight := int32(ht.CurrentHeight())
490490
deadline := int32(commit.DeadlineHeight) - currentHeight
491491
require.Positive(ht, deadline)
492492
ht.Logf("Found commit deadline %d, anchor deadline %d",
@@ -836,7 +836,7 @@ func testListSweeps(ht *lntest.HarnessTest) {
836836
ht.MineEmptyBlocks(1)
837837

838838
// Get the current block height.
839-
_, blockHeight := ht.GetBestBlock()
839+
blockHeight := int32(ht.CurrentHeight())
840840

841841
// Close the second channel and also sweep the funds.
842842
ht.ForceCloseChannel(alice, chanPoints[1])

itest/lnd_routing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func testSingleHopSendToRouteCase(ht *lntest.HarnessTest,
117117
// Assert Carol and Dave are synced to the chain before proceeding, to
118118
// ensure the queried route will have a valid final CLTV once the HTLC
119119
// reaches Dave.
120-
_, minerHeight := ht.GetBestBlock()
120+
minerHeight := int32(ht.CurrentHeight())
121121
ht.WaitForNodeBlockHeight(carol, minerHeight)
122122
ht.WaitForNodeBlockHeight(dave, minerHeight)
123123

itest/lnd_sweep_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
172172

173173
// Remember the force close height so we can calculate the deadline
174174
// height.
175-
_, forceCloseHeight := ht.GetBestBlock()
175+
forceCloseHeight := ht.CurrentHeight()
176176

177177
// Bob should have two pending sweeps,
178178
// - anchor sweeping from his local commitment.
@@ -188,7 +188,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
188188
sweeps := ht.AssertNumPendingSweeps(bob, 2)
189189

190190
// The two anchor sweeping should have the same deadline height.
191-
deadlineHeight := uint32(forceCloseHeight) + deadlineDeltaAnchor
191+
deadlineHeight := forceCloseHeight + deadlineDeltaAnchor
192192
require.Equal(ht, deadlineHeight, sweeps[0].DeadlineHeight)
193193
require.Equal(ht, deadlineHeight, sweeps[1].DeadlineHeight)
194194

@@ -304,7 +304,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
304304
//
305305
// Once out of the above loop, we expect to be 2 blocks before the CPFP
306306
// deadline.
307-
_, currentHeight := ht.GetBestBlock()
307+
currentHeight := ht.CurrentHeight()
308308
require.Equal(ht, int(anchorDeadline-2), int(currentHeight))
309309

310310
// Mine one more block, we'd use up all the CPFP budget.
@@ -512,8 +512,8 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
512512
forceCloseHeight := htlc.ExpirationHeight - goToChainDelta
513513

514514
// Mine till the goToChainHeight is reached.
515-
_, currentHeight := ht.GetBestBlock()
516-
numBlocks := forceCloseHeight - uint32(currentHeight)
515+
currentHeight := ht.CurrentHeight()
516+
numBlocks := forceCloseHeight - currentHeight
517517
ht.MineEmptyBlocks(int(numBlocks))
518518

519519
// Assert Bob's force closing tx has been broadcast.
@@ -641,7 +641,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
641641
//
642642
// Once out of the above loop, we expect to be 2 blocks before the CPFP
643643
// deadline.
644-
_, currentHeight = ht.GetBestBlock()
644+
currentHeight = ht.CurrentHeight()
645645
require.Equal(ht, int(anchorDeadline-2), int(currentHeight))
646646

647647
// Mine one more block, we'd use up all the CPFP budget.
@@ -1380,7 +1380,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
13801380
//
13811381
// TODO(yy): assert they are equal once blocks are synced via
13821382
// `blockbeat`.
1383-
_, currentHeight := ht.GetBestBlock()
1383+
currentHeight := int32(ht.CurrentHeight())
13841384
actualDeadline := int32(pendingSweepBob.DeadlineHeight) - currentHeight
13851385
if actualDeadline != int32(deadlineB) {
13861386
ht.Logf("!!! Found unsynced block between sweeper and "+
@@ -1438,7 +1438,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
14381438
//
14391439
// TODO(yy): assert they are equal once blocks are synced via
14401440
// `blockbeat`.
1441-
_, currentHeight = ht.GetBestBlock()
1441+
currentHeight = int32(ht.CurrentHeight())
14421442
actualDeadline = int32(aliceCommit.DeadlineHeight) - currentHeight
14431443
if actualDeadline != int32(deadlineA) {
14441444
ht.Logf("!!! Found unsynced block between Alice's sweeper and "+
@@ -1972,7 +1972,7 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
19721972

19731973
// Since the request doesn't specify a deadline, we expect the default
19741974
// deadline to be used.
1975-
_, currentHeight := ht.GetBestBlock()
1975+
currentHeight := int32(ht.CurrentHeight())
19761976
deadline := uint32(currentHeight + sweep.DefaultDeadlineDelta)
19771977

19781978
// Assert the pending sweep is created with the expected values:

itest/lnd_taproot_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,13 +1535,13 @@ func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
15351535
// Before we publish the tx that spends the p2tr transaction, we want to
15361536
// register a spend listener that we expect to fire after mining the
15371537
// block.
1538-
_, currentHeight := ht.GetBestBlock()
1538+
currentHeight := ht.CurrentHeight()
15391539

15401540
// For a Taproot output we cannot leave the outpoint empty. Let's make
15411541
// sure the API returns the correct error here.
15421542
req := &chainrpc.SpendRequest{
15431543
Script: spendRequest.Script,
1544-
HeightHint: uint32(currentHeight),
1544+
HeightHint: currentHeight,
15451545
}
15461546
spendClient := node.RPC.RegisterSpendNtfn(req)
15471547

@@ -1556,7 +1556,7 @@ func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
15561556
req = &chainrpc.SpendRequest{
15571557
Outpoint: spendRequest.Outpoint,
15581558
Script: spendRequest.Script,
1559-
HeightHint: uint32(currentHeight),
1559+
HeightHint: currentHeight,
15601560
}
15611561
spendClient = node.RPC.RegisterSpendNtfn(req)
15621562

@@ -1582,7 +1582,7 @@ func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
15821582
require.NoError(ht, err)
15831583
spend := spendMsg.GetSpend()
15841584
require.NotNil(ht, spend)
1585-
require.Equal(ht, spend.SpendingHeight, uint32(currentHeight+1))
1585+
require.Equal(ht, spend.SpendingHeight, currentHeight+1)
15861586
}
15871587

15881588
// confirmAddress makes sure that a transaction in the mempool spends funds to
@@ -1609,11 +1609,11 @@ func confirmAddress(ht *lntest.HarnessTest, hn *node.HarnessNode,
16091609
addrPkScript, err := txscript.PayToAddrScript(parsedAddr)
16101610
require.NoError(ht, err)
16111611

1612-
_, currentHeight := ht.GetBestBlock()
1612+
currentHeight := ht.CurrentHeight()
16131613
req := &chainrpc.ConfRequest{
16141614
Script: addrPkScript,
16151615
Txid: txid[:],
1616-
HeightHint: uint32(currentHeight),
1616+
HeightHint: currentHeight,
16171617
NumConfs: 1,
16181618
IncludeBlock: true,
16191619
}
@@ -1628,7 +1628,7 @@ func confirmAddress(ht *lntest.HarnessTest, hn *node.HarnessNode,
16281628
require.NoError(ht, err)
16291629
conf := confMsg.GetConf()
16301630
require.NotNil(ht, conf)
1631-
require.Equal(ht, conf.BlockHeight, uint32(currentHeight+1))
1631+
require.Equal(ht, conf.BlockHeight, currentHeight+1)
16321632
require.NotNil(ht, conf.RawBlock)
16331633

16341634
// We should also be able to decode the raw block.

0 commit comments

Comments
 (0)