From b72993c9dd1e4f2122ea4908ad27b31260bc1125 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Wed, 7 Dec 2022 15:23:29 -0600 Subject: [PATCH 1/2] lntemp: after mining, sync to latest block Ensure active nodes are synced to the latest block mined. There are two scenarios where they might not be synced to the correct block even when SyncedToChain is true: 1. The backend may have rejected a newly mined block (e.g., see #7241). 2. The backend might not have fully processed the new blocks yet. In either case SyncedToChain will (correctly) be true since the node is indeed fully synced to the backend. This commit makes sure we detect case 1 above, while making sure we continue to wait in case 2. --- lntemp/harness.go | 6 ++++-- lntemp/harness_assertion.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) 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 { From 55a146d4e47010df264fe3043f920db0b1a4b813 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Fri, 9 Dec 2022 10:41:22 -0600 Subject: [PATCH 2/2] docs: update release notes --- docs/release-notes/release-notes-0.16.0.md | 1 + 1 file changed, 1 insertion(+) 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.