mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-25 06:55:32 +01:00
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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user