aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@pm.me>2020-01-29 09:57:56 -0500
committerJames O'Beirne <james.obeirne@pm.me>2020-03-17 14:07:58 -0400
commitc9017ce3bc27665594c9d80f395780d40755bb22 (patch)
tree36ea710a14db1757ed270ff6e8585eb53427e74f /src/validation.cpp
parent2b081c4568e8019886fdb0f2a57babc73d7487f7 (diff)
protect g_chainman with cs_main
I'd previously attempted to create a specialized lock for ChainstateManager, but it turns out that because that lock would be required for functions like ChainActive() and ChainstateActive(), it created irreconcilable lock inversions since those functions are used so broadly throughout the codebase. Instead, I'm just using cs_main to protect the contents of g_chainman. Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 77b6e7c051..84b93180d6 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -81,12 +81,14 @@ ChainstateManager g_chainman;
CChainState& ChainstateActive()
{
+ LOCK(::cs_main);
assert(g_chainman.m_active_chainstate);
return *g_chainman.m_active_chainstate;
}
CChain& ChainActive()
{
+ LOCK(::cs_main);
return ::ChainstateActive().m_chain;
}
@@ -1295,6 +1297,7 @@ static CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
BlockMap& BlockIndex()
{
+ LOCK(::cs_main);
return g_chainman.m_blockman.m_block_index;
}
@@ -4704,7 +4707,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
// Activate the genesis block so normal node progress can continue
if (hash == chainparams.GetConsensus().hashGenesisBlock) {
BlockValidationState state;
- if (!ActivateBestChain(state, chainparams)) {
+ if (!ActivateBestChain(state, chainparams, nullptr)) {
break;
}
}