Skip to content

Commit ed342d6

Browse files
committed
lntest: make sure chain backend is synced to miner
We sometimes see `timeout waiting for UTXOs` error from bitcoind-related itests due to the chain backend not synced to the miner. We now assert it's synced before continue.
1 parent 4f345f3 commit ed342d6

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

lntest/harness.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ func (h *HarnessTest) NewNode(name string,
481481
err = node.Start(h.runCtx)
482482
require.NoError(h, err, "failed to start node %s", node.Name())
483483

484+
// Get the miner's best block hash.
485+
bestBlock, err := h.miner.Client.GetBestBlockHash()
486+
require.NoError(h, err, "unable to get best block hash")
487+
488+
// Wait until the node's chain backend is synced to the miner's best
489+
// block.
490+
h.WaitForBlockchainSyncTo(node, *bestBlock)
491+
484492
return node
485493
}
486494

@@ -490,12 +498,7 @@ func (h *HarnessTest) NewNode(name string,
490498
func (h *HarnessTest) NewNodeWithCoins(name string,
491499
extraArgs []string) *node.HarnessNode {
492500

493-
node, err := h.manager.newNode(h.T, name, extraArgs, nil, false)
494-
require.NoErrorf(h, err, "unable to create new node for %s", name)
495-
496-
// Start the node.
497-
err = node.Start(h.runCtx)
498-
require.NoError(h, err, "failed to start node %s", node.Name())
501+
node := h.NewNode(name, extraArgs)
499502

500503
// Load up the wallets of the node with 5 outputs of 1 BTC each.
501504
const (

lntest/harness_assertion.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
6161

6262
// WaitForBlockchainSyncTo waits until the node is synced to bestBlock.
6363
func (h *HarnessTest) WaitForBlockchainSyncTo(hn *node.HarnessNode,
64-
bestBlock *wire.MsgBlock) {
64+
bestBlock chainhash.Hash) {
6565

66-
bestBlockHash := bestBlock.BlockHash().String()
66+
bestBlockHash := bestBlock.String()
6767
err := wait.NoError(func() error {
6868
resp := hn.RPC.GetInfo()
6969
if resp.SyncedToChain {
@@ -1629,7 +1629,7 @@ func (h *HarnessTest) AssertActiveNodesSynced() {
16291629

16301630
// AssertActiveNodesSyncedTo asserts all active nodes have synced to the
16311631
// provided bestBlock.
1632-
func (h *HarnessTest) AssertActiveNodesSyncedTo(bestBlock *wire.MsgBlock) {
1632+
func (h *HarnessTest) AssertActiveNodesSyncedTo(bestBlock chainhash.Hash) {
16331633
for _, node := range h.manager.activeNodes {
16341634
h.WaitForBlockchainSyncTo(node, bestBlock)
16351635
}

lntest/harness_miner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (h *HarnessTest) MineBlocks(num int) {
4141
// Check the block doesn't have any txns except the coinbase.
4242
if len(block.Transactions) <= 1 {
4343
// Make sure all the active nodes are synced.
44-
h.AssertActiveNodesSyncedTo(block)
44+
h.AssertActiveNodesSyncedTo(block.BlockHash())
4545

4646
// Mine the next block.
4747
continue
@@ -116,7 +116,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
116116

117117
// Finally, make sure all the active nodes are synced.
118118
bestBlock := blocks[len(blocks)-1]
119-
h.AssertActiveNodesSyncedTo(bestBlock)
119+
h.AssertActiveNodesSyncedTo(bestBlock.BlockHash())
120120

121121
return blocks
122122
}
@@ -157,7 +157,7 @@ func (h *HarnessTest) cleanMempool() {
157157
bestBlock = blocks[len(blocks)-1]
158158

159159
// Make sure all the active nodes are synced.
160-
h.AssertActiveNodesSyncedTo(bestBlock)
160+
h.AssertActiveNodesSyncedTo(bestBlock.BlockHash())
161161

162162
return fmt.Errorf("still have %d txes in mempool", len(mem))
163163
}, wait.MinerMempoolTimeout)

0 commit comments

Comments
 (0)