diff --git a/docs/release-notes/release-notes-0.16.0.md b/docs/release-notes/release-notes-0.16.0.md index 97cf2cf06..0f14bc3e5 100644 --- a/docs/release-notes/release-notes-0.16.0.md +++ b/docs/release-notes/release-notes-0.16.0.md @@ -294,6 +294,7 @@ details. Along the way, several PRs([6776](https://github.com/lightningnetwork/lnd/pull/6776), [6822](https://github.com/lightningnetwork/lnd/pull/6822), [7172](https://github.com/lightningnetwork/lnd/pull/7172), +[7242](https://github.com/lightningnetwork/lnd/pull/7242), [7245](https://github.com/lightningnetwork/lnd/pull/7245)) have been made to refactor the itest for code health and maintenance. diff --git a/lntemp/harness.go b/lntemp/harness.go index 5a4d62ae8..d69cc330a 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 d48c5ada2..fbd58335a 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 {