mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-27 01:02:56 +02:00
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.
This commit is contained in:
parent
1dec926165
commit
7ab4081ffd
@ -481,6 +481,14 @@ func (h *HarnessTest) NewNode(name string,
|
|||||||
err = node.Start(h.runCtx)
|
err = node.Start(h.runCtx)
|
||||||
require.NoError(h, err, "failed to start node %s", node.Name())
|
require.NoError(h, err, "failed to start node %s", node.Name())
|
||||||
|
|
||||||
|
// Get the miner's best block hash.
|
||||||
|
bestBlock, err := h.miner.Client.GetBestBlockHash()
|
||||||
|
require.NoError(h, err, "unable to get best block hash")
|
||||||
|
|
||||||
|
// Wait until the node's chain backend is synced to the miner's best
|
||||||
|
// block.
|
||||||
|
h.WaitForBlockchainSyncTo(node, *bestBlock)
|
||||||
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,12 +498,7 @@ func (h *HarnessTest) NewNode(name string,
|
|||||||
func (h *HarnessTest) NewNodeWithCoins(name string,
|
func (h *HarnessTest) NewNodeWithCoins(name string,
|
||||||
extraArgs []string) *node.HarnessNode {
|
extraArgs []string) *node.HarnessNode {
|
||||||
|
|
||||||
node, err := h.manager.newNode(h.T, name, extraArgs, nil, false)
|
node := h.NewNode(name, extraArgs)
|
||||||
require.NoErrorf(h, err, "unable to create new node for %s", name)
|
|
||||||
|
|
||||||
// Start the node.
|
|
||||||
err = node.Start(h.runCtx)
|
|
||||||
require.NoError(h, err, "failed to start node %s", node.Name())
|
|
||||||
|
|
||||||
// Load up the wallets of the node with 5 outputs of 1 BTC each.
|
// Load up the wallets of the node with 5 outputs of 1 BTC each.
|
||||||
const (
|
const (
|
||||||
|
@ -61,9 +61,9 @@ func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
|
|||||||
|
|
||||||
// WaitForBlockchainSyncTo waits until the node is synced to bestBlock.
|
// WaitForBlockchainSyncTo waits until the node is synced to bestBlock.
|
||||||
func (h *HarnessTest) WaitForBlockchainSyncTo(hn *node.HarnessNode,
|
func (h *HarnessTest) WaitForBlockchainSyncTo(hn *node.HarnessNode,
|
||||||
bestBlock *wire.MsgBlock) {
|
bestBlock chainhash.Hash) {
|
||||||
|
|
||||||
bestBlockHash := bestBlock.BlockHash().String()
|
bestBlockHash := bestBlock.String()
|
||||||
err := wait.NoError(func() error {
|
err := wait.NoError(func() error {
|
||||||
resp := hn.RPC.GetInfo()
|
resp := hn.RPC.GetInfo()
|
||||||
if resp.SyncedToChain {
|
if resp.SyncedToChain {
|
||||||
@ -1629,7 +1629,7 @@ func (h *HarnessTest) AssertActiveNodesSynced() {
|
|||||||
|
|
||||||
// AssertActiveNodesSyncedTo asserts all active nodes have synced to the
|
// AssertActiveNodesSyncedTo asserts all active nodes have synced to the
|
||||||
// provided bestBlock.
|
// provided bestBlock.
|
||||||
func (h *HarnessTest) AssertActiveNodesSyncedTo(bestBlock *wire.MsgBlock) {
|
func (h *HarnessTest) AssertActiveNodesSyncedTo(bestBlock chainhash.Hash) {
|
||||||
for _, node := range h.manager.activeNodes {
|
for _, node := range h.manager.activeNodes {
|
||||||
h.WaitForBlockchainSyncTo(node, bestBlock)
|
h.WaitForBlockchainSyncTo(node, bestBlock)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func (h *HarnessTest) MineBlocks(num int) {
|
|||||||
// Check the block doesn't have any txns except the coinbase.
|
// Check the block doesn't have any txns except the coinbase.
|
||||||
if len(block.Transactions) <= 1 {
|
if len(block.Transactions) <= 1 {
|
||||||
// Make sure all the active nodes are synced.
|
// Make sure all the active nodes are synced.
|
||||||
h.AssertActiveNodesSyncedTo(block)
|
h.AssertActiveNodesSyncedTo(block.BlockHash())
|
||||||
|
|
||||||
// Mine the next block.
|
// Mine the next block.
|
||||||
continue
|
continue
|
||||||
@ -116,7 +116,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
|
|||||||
|
|
||||||
// Finally, make sure all the active nodes are synced.
|
// Finally, make sure all the active nodes are synced.
|
||||||
bestBlock := blocks[len(blocks)-1]
|
bestBlock := blocks[len(blocks)-1]
|
||||||
h.AssertActiveNodesSyncedTo(bestBlock)
|
h.AssertActiveNodesSyncedTo(bestBlock.BlockHash())
|
||||||
|
|
||||||
return blocks
|
return blocks
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ func (h *HarnessTest) cleanMempool() {
|
|||||||
bestBlock = blocks[len(blocks)-1]
|
bestBlock = blocks[len(blocks)-1]
|
||||||
|
|
||||||
// Make sure all the active nodes are synced.
|
// Make sure all the active nodes are synced.
|
||||||
h.AssertActiveNodesSyncedTo(bestBlock)
|
h.AssertActiveNodesSyncedTo(bestBlock.BlockHash())
|
||||||
|
|
||||||
return fmt.Errorf("still have %d txes in mempool", len(mem))
|
return fmt.Errorf("still have %d txes in mempool", len(mem))
|
||||||
}, wait.MinerMempoolTimeout)
|
}, wait.MinerMempoolTimeout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user