Skip to content

Commit 2414ebc

Browse files
committed
init: Delay RPC block notif until warmup finished
See added code comment for more details.
1 parent 8d466a8 commit 2414ebc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/init.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,17 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17771777

17781778
// ********************************************************* Step 13: finished
17791779

1780+
// At this point, the RPC is "started", but still in warmup, which means it
1781+
// cannot yet be called. Before we make it callable, we need to make sure
1782+
// that the RPC's view of the best block is valid and consistent with
1783+
// ChainstateManager's ActiveTip.
1784+
//
1785+
// If we do not do this, RPC's view of the best block will be height=0 and
1786+
// hash=0x0. This will lead to erroroneous responses for things like
1787+
// waitforblockheight.
1788+
RPCNotifyBlockChange(chainman.ActiveTip());
17801789
SetRPCWarmupFinished();
1790+
17811791
uiInterface.InitMessage(_("Done loading").translated);
17821792

17831793
for (const auto& client : node.chain_clients) {

src/node/chainstate.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <node/chainstate.h>
66

77
#include <chainparams.h> // for CChainParams
8-
#include <rpc/blockchain.h> // for RPCNotifyBlockChange
98
#include <util/time.h> // for GetTime
109
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
1110
#include <shutdown.h> // for ShutdownRequested
@@ -144,7 +143,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
144143
for (CChainState* chainstate : chainman.GetAll()) {
145144
if (!is_coinsview_empty(chainstate)) {
146145
const CBlockIndex* tip = chainstate->m_chain.Tip();
147-
RPCNotifyBlockChange(tip);
148146
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
149147
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
150148
}

0 commit comments

Comments
 (0)