Skip to content

Commit 02de6a6

Browse files
committed
Assert cs_main is held when accessing mapBlockIndex
1 parent 765a3eb commit 02de6a6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/validation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ namespace {
260260

261261
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator)
262262
{
263+
AssertLockHeld(cs_main);
264+
263265
// Find the first block the caller has in the main chain
264266
for (const uint256& hash : locator.vHave) {
265267
BlockMap::iterator mi = mapBlockIndex.find(hash);
@@ -2774,6 +2776,8 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex) {
27742776

27752777
CBlockIndex* CChainState::AddToBlockIndex(const CBlockHeader& block)
27762778
{
2779+
AssertLockHeld(cs_main);
2780+
27772781
// Check for duplicate
27782782
uint256 hash = block.GetHash();
27792783
BlockMap::iterator it = mapBlockIndex.find(hash);
@@ -3654,6 +3658,8 @@ fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
36543658

36553659
CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash)
36563660
{
3661+
AssertLockHeld(cs_main);
3662+
36573663
if (hash.IsNull())
36583664
return nullptr;
36593665

@@ -3781,6 +3787,8 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
37813787

37823788
bool LoadChainTip(const CChainParams& chainparams)
37833789
{
3790+
AssertLockHeld(cs_main);
3791+
37843792
if (chainActive.Tip() && chainActive.Tip()->GetBlockHash() == pcoinsTip->GetBestBlock()) return true;
37853793

37863794
if (pcoinsTip->GetBestBlock().IsNull() && mapBlockIndex.size() == 1) {

0 commit comments

Comments
 (0)