Skip to content

Commit ef89e93

Browse files
dongcarlFabcien
authored andcommitted
init: Delay RPC block notif until warmup finished
Summary: Partial backport of [[bitcoin/bitcoin#23280 | core#23280]]: bitcoin/bitcoin@2414ebc Test Plan: ninja all check-all Reviewers: #bitcoin_abc, sdulfari Reviewed By: #bitcoin_abc, sdulfari Differential Revision: https://reviews.bitcoinabc.org/D12576
1 parent 5c1a099 commit ef89e93

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/init.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -2911,7 +2911,17 @@ bool AppInitMain(Config &config, RPCServer &rpcServer,
29112911

29122912
// Step 13: finished
29132913

2914+
// At this point, the RPC is "started", but still in warmup, which means it
2915+
// cannot yet be called. Before we make it callable, we need to make sure
2916+
// that the RPC's view of the best block is valid and consistent with
2917+
// ChainstateManager's ActiveTip.
2918+
//
2919+
// If we do not do this, RPC's view of the best block will be height=0 and
2920+
// hash=0x0. This will lead to erroroneous responses for things like
2921+
// waitforblockheight.
2922+
RPCNotifyBlockChange(chainman.ActiveTip());
29142923
SetRPCWarmupFinished();
2924+
29152925
uiInterface.InitMessage(_("Done loading").translated);
29162926

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

src/node/chainstate.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <chainparams.h>
88
#include <config.h>
99
#include <node/blockstorage.h>
10-
#include <rpc/blockchain.h>
1110
#include <shutdown.h>
1211
#include <util/time.h>
1312
#include <validation.h>
@@ -154,7 +153,6 @@ VerifyLoadedChainstate(ChainstateManager &chainman, bool fReset,
154153
for (CChainState *chainstate : chainman.GetAll()) {
155154
if (!is_coinsview_empty(chainstate)) {
156155
const CBlockIndex *tip = chainstate->m_chain.Tip();
157-
RPCNotifyBlockChange(tip);
158156
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
159157
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
160158
}

0 commit comments

Comments
 (0)