diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-07-03 07:37:15 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-07-03 07:38:16 -0400 |
commit | 915ac8a86192b10b753ce774a7d7c51c70a385f8 (patch) | |
tree | 7046fa373aabc889ff0ff410ba8baeced74a20e2 /src/init.cpp | |
parent | f61019f5a2c63d0a293e2ba2e57352d834f2c8d6 (diff) | |
parent | fa0dfdf447d5b84a1849dc823d8508463600136a (diff) |
Merge #19413: refactor: Remove confusing BlockIndex global
fa0dfdf447d5b84a1849dc823d8508463600136a 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 fa0dfdf447d5b84a1849dc823d8508463600136a.
jonatack:
re-ACK fa0dfdf
Tree-SHA512: 8f158fc5e1c67e73588a21c25677b3fa0fe442313b13ec24b87054806c59607d6ba0c062a865ce3e0ee568706bd0d1faa84febda21aff5bcd65dab172f74c52f
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/init.cpp b/src/init.cpp index 19f6e7d038..35e211a9d7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1588,7 +1588,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node) // If the loaded chain has a wrong genesis, bail out immediately // (we're likely using a testnet datadir, or the other way around). - if (!::BlockIndex().empty() && + if (!chainman.BlockIndex().empty() && !LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) { return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?")); } @@ -1868,8 +1868,8 @@ bool AppInitMain(const util::Ref& context, NodeContext& node) //// debug print { LOCK(cs_main); - LogPrintf("block tree size = %u\n", ::BlockIndex().size()); - chain_active_height = ::ChainActive().Height(); + LogPrintf("block tree size = %u\n", chainman.BlockIndex().size()); + chain_active_height = chainman.ActiveChain().Height(); } LogPrintf("nBestHeight = %d\n", chain_active_height); |