From 1c5ea38c681d82a1ae8a30a15ef377f77e9c507a Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Fri, 28 Jan 2022 20:25:50 +0100 Subject: [PATCH] merge bitcoin#24197: Replace lock with thread safety annotation in CBlockTreeDB::LoadBlockIndexGuts() --- src/txdb.cpp | 13 +++++-------- src/txdb.h | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 5ff270faa410a..bdaeda42c90a5 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -408,8 +408,8 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) { bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex) { + AssertLockHeld(::cs_main); std::unique_ptr pcursor(NewIterator()); - pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256())); // Load m_block_index @@ -423,19 +423,16 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash()); pindexNew->pprev = insertBlockIndex(diskindex.hashPrev); pindexNew->nHeight = diskindex.nHeight; + pindexNew->nFile = diskindex.nFile; + pindexNew->nDataPos = diskindex.nDataPos; + pindexNew->nUndoPos = diskindex.nUndoPos; pindexNew->nVersion = diskindex.nVersion; pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot; pindexNew->nTime = diskindex.nTime; pindexNew->nBits = diskindex.nBits; pindexNew->nNonce = diskindex.nNonce; + pindexNew->nStatus = diskindex.nStatus; pindexNew->nTx = diskindex.nTx; - { - LOCK(::cs_main); - pindexNew->nFile = diskindex.nFile; - pindexNew->nDataPos = diskindex.nDataPos; - pindexNew->nUndoPos = diskindex.nUndoPos; - pindexNew->nStatus = diskindex.nStatus; - } if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) { return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString()); diff --git a/src/txdb.h b/src/txdb.h index 54c79ade140fe..d00e5629ee04a 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -104,7 +104,8 @@ class CBlockTreeDB : public CDBWrapper bool WriteFlag(const std::string &name, bool fValue); bool ReadFlag(const std::string &name, bool &fValue); - bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex); + bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex) + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); }; #endif // BITCOIN_TXDB_H