diff --git a/lntemp/harness.go b/lntemp/harness.go index 5a4d62ae80..d69cc330a6 100644 --- a/lntemp/harness.go +++ b/lntemp/harness.go @@ -1291,7 +1291,8 @@ func (h *HarnessTest) MineBlocks(num uint32) []*wire.MsgBlock { blocks := h.Miner.MineBlocksSlow(num) // Make sure all the active nodes are synced. - h.AssertActiveNodesSynced() + bestBlock := blocks[len(blocks)-1] + h.AssertActiveNodesSyncedTo(bestBlock) return blocks } @@ -1318,7 +1319,8 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32, } // Finally, make sure all the active nodes are synced. - h.AssertActiveNodesSynced() + bestBlock := blocks[len(blocks)-1] + h.AssertActiveNodesSyncedTo(bestBlock) return blocks } diff --git a/lntemp/harness_assertion.go b/lntemp/harness_assertion.go index d48c5ada22..fbd58335ad 100644 --- a/lntemp/harness_assertion.go +++ b/lntemp/harness_assertion.go @@ -39,6 +39,29 @@ func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) { require.NoError(h, err, "timeout waiting for blockchain sync") } +// WaitForBlockchainSyncTo waits until the node is synced to bestBlock. +func (h *HarnessTest) WaitForBlockchainSyncTo(hn *node.HarnessNode, + bestBlock *wire.MsgBlock) { + + bestBlockHash := bestBlock.BlockHash().String() + err := wait.NoError(func() error { + resp := hn.RPC.GetInfo() + if resp.SyncedToChain { + if resp.BlockHash == bestBlockHash { + return nil + } + + return fmt.Errorf("%s's backend is synced to the "+ + "wrong block (expected=%s, actual=%s)", + hn.Name(), bestBlockHash, resp.BlockHash) + } + + return fmt.Errorf("%s is not synced to chain", hn.Name()) + }, DefaultTimeout) + + require.NoError(h, err, "timeout waiting for blockchain sync") +} + // AssertPeerConnected asserts that the given node b is connected to a. func (h *HarnessTest) AssertPeerConnected(a, b *node.HarnessNode) { err := wait.NoError(func() error { @@ -1324,6 +1347,14 @@ func (h *HarnessTest) AssertActiveNodesSynced() { } } +// AssertActiveNodesSyncedTo asserts all active nodes have synced to the +// provided bestBlock. +func (h *HarnessTest) AssertActiveNodesSyncedTo(bestBlock *wire.MsgBlock) { + for _, node := range h.manager.activeNodes { + h.WaitForBlockchainSyncTo(node, bestBlock) + } +} + // AssertPeerNotConnected asserts that the given node b is not connected to a. func (h *HarnessTest) AssertPeerNotConnected(a, b *node.HarnessNode) { err := wait.NoError(func() error {