Skip to content

Commit 20276ca

Browse files
committed
Replace lock with thread safety annotation in CBlockTreeDB::LoadBlockIndexGuts()
1 parent d4e92d8 commit 20276ca

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/txdb.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
296296

297297
bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
298298
{
299+
AssertLockHeld(::cs_main);
299300
std::unique_ptr<CDBIterator> pcursor(NewIterator());
300-
301301
pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256()));
302302

303303
// Load m_block_index
@@ -311,19 +311,16 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
311311
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
312312
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
313313
pindexNew->nHeight = diskindex.nHeight;
314+
pindexNew->nFile = diskindex.nFile;
315+
pindexNew->nDataPos = diskindex.nDataPos;
316+
pindexNew->nUndoPos = diskindex.nUndoPos;
314317
pindexNew->nVersion = diskindex.nVersion;
315318
pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
316319
pindexNew->nTime = diskindex.nTime;
317320
pindexNew->nBits = diskindex.nBits;
318321
pindexNew->nNonce = diskindex.nNonce;
322+
pindexNew->nStatus = diskindex.nStatus;
319323
pindexNew->nTx = diskindex.nTx;
320-
{
321-
LOCK(::cs_main);
322-
pindexNew->nFile = diskindex.nFile;
323-
pindexNew->nDataPos = diskindex.nDataPos;
324-
pindexNew->nUndoPos = diskindex.nUndoPos;
325-
pindexNew->nStatus = diskindex.nStatus;
326-
}
327324

328325
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) {
329326
return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());

src/txdb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ class CBlockTreeDB : public CDBWrapper
8686
void ReadReindexing(bool &fReindexing);
8787
bool WriteFlag(const std::string &name, bool fValue);
8888
bool ReadFlag(const std::string &name, bool &fValue);
89-
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex);
89+
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
90+
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
9091
};
9192

9293
std::optional<bilingual_str> CheckLegacyTxindex(CBlockTreeDB& block_tree_db);

0 commit comments

Comments
 (0)