Skip to content

Commit f7aef8d

Browse files
committed
init: Delay RPC block notif until warmup finished
1 parent 94c0ceb commit f7aef8d

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
@@ -2400,7 +2400,17 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
24002400

24012401
// ********************************************************* Step 13: finished
24022402

2403+
// At this point, the RPC is "started", but still in warmup, which means it
2404+
// cannot yet be called. Before we make it callable, we need to make sure
2405+
// that the RPC's view of the best block is valid and consistent with
2406+
// ChainstateManager's ActiveTip.
2407+
//
2408+
// If we do not do this, RPC's view of the best block will be height=0 and
2409+
// hash=0x0. This will lead to erroroneous responses for things like
2410+
// waitforblockheight.
2411+
RPCNotifyBlockChange(chainman.ActiveTip());
24032412
SetRPCWarmupFinished();
2413+
24042414
uiInterface.InitMessage(_("Done loading").translated);
24052415

24062416
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
@@ -6,7 +6,6 @@
66

77
#include <chainparams.h> // for CChainParams
88
#include <deploymentstatus.h> // for DeploymentActiveAfter
9-
#include <rpc/blockchain.h> // for RPCNotifyBlockChange
109
#include <util/time.h> // for GetTime
1110
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
1211
#include <shutdown.h> // for ShutdownRequested
@@ -246,7 +245,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
246245
for (CChainState* chainstate : chainman.GetAll()) {
247246
if (!is_coinsview_empty(chainstate)) {
248247
const CBlockIndex* tip = chainstate->m_chain.Tip();
249-
RPCNotifyBlockChange(tip);
250248
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
251249
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
252250
}

0 commit comments

Comments
 (0)