Skip to content

Commit fa97a52

Browse files
author
MacroFake
committed
Fix UB/data-race in RPCNotifyBlockChange
ActiveTip() is *not* thread-safe, as the required ::cs_main lock will be released as ActiveChainstate() returns. ActiveTip() is an alias for ActiveChainstate().m_chain.Tip(), so m_chain may be involved in a data-race (UB).
1 parent fa530bc commit fa97a52

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/init.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1751,12 +1751,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17511751
// At this point, the RPC is "started", but still in warmup, which means it
17521752
// cannot yet be called. Before we make it callable, we need to make sure
17531753
// that the RPC's view of the best block is valid and consistent with
1754-
// ChainstateManager's ActiveTip.
1754+
// ChainstateManager's active tip.
17551755
//
17561756
// If we do not do this, RPC's view of the best block will be height=0 and
17571757
// hash=0x0. This will lead to erroroneous responses for things like
17581758
// waitforblockheight.
1759-
RPCNotifyBlockChange(chainman.ActiveTip());
1759+
RPCNotifyBlockChange(WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip()));
17601760
SetRPCWarmupFinished();
17611761

17621762
uiInterface.InitMessage(_("Done loading").translated);

0 commit comments

Comments
 (0)