mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-27 03:33:27 -03:00
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).
This commit is contained in:
parent
fa530bcb9c
commit
fa97a528d6
1 changed files with 2 additions and 2 deletions
|
@ -1751,12 +1751,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
// At this point, the RPC is "started", but still in warmup, which means it
|
// At this point, the RPC is "started", but still in warmup, which means it
|
||||||
// cannot yet be called. Before we make it callable, we need to make sure
|
// cannot yet be called. Before we make it callable, we need to make sure
|
||||||
// that the RPC's view of the best block is valid and consistent with
|
// that the RPC's view of the best block is valid and consistent with
|
||||||
// ChainstateManager's ActiveTip.
|
// ChainstateManager's active tip.
|
||||||
//
|
//
|
||||||
// If we do not do this, RPC's view of the best block will be height=0 and
|
// If we do not do this, RPC's view of the best block will be height=0 and
|
||||||
// hash=0x0. This will lead to erroroneous responses for things like
|
// hash=0x0. This will lead to erroroneous responses for things like
|
||||||
// waitforblockheight.
|
// waitforblockheight.
|
||||||
RPCNotifyBlockChange(chainman.ActiveTip());
|
RPCNotifyBlockChange(WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip()));
|
||||||
SetRPCWarmupFinished();
|
SetRPCWarmupFinished();
|
||||||
|
|
||||||
uiInterface.InitMessage(_("Done loading").translated);
|
uiInterface.InitMessage(_("Done loading").translated);
|
||||||
|
|
Loading…
Add table
Reference in a new issue