Merge #19413: refactor: Remove confusing BlockIndex global

fa0dfdf447 refactor: Remove confusing BlockIndex global (MarcoFalke)

Pull request description:

  The global `::BlockIndex()` is problematic for several reasons:

  * It returns a mutable reference to the block tree, without the appropriate lock annotation (`m_block_index` is guarded by `cs_main`). The current code is fine, but in the future this might lead to accidental races and data corruption.
  * The rpc server shouldn't rely on node globals, but rather a context that is passed in to the RPC method.
  * Tests might want to spin up their own block tree, and thus should also not rely on a single global.

  Fix all issues by removing the global

ACKs for top commit:
  promag:
    Code review ACK fa0dfdf447.
  jonatack:
    re-ACK fa0dfdf

Tree-SHA512: 8f158fc5e1c67e73588a21c25677b3fa0fe442313b13ec24b87054806c59607d6ba0c062a865ce3e0ee568706bd0d1faa84febda21aff5bcd65dab172f74c52f
This commit is contained in:
MarcoFalke 2020-07-03 07:37:15 -04:00
commit 915ac8a861
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
5 changed files with 22 additions and 32 deletions

View file

@ -1321,12 +1321,6 @@ bool CChainState::IsInitialBlockDownload() const
static CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
BlockMap& BlockIndex()
{
LOCK(::cs_main);
return g_chainman.m_blockman.m_block_index;
}
static void AlertNotify(const std::string& strMessage)
{
uiInterface.NotifyAlertChanged();