aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2022-01-28 20:25:50 +0100
committerJon Atack <jon@atack.com>2022-01-28 20:52:53 +0100
commit20276ca5d124285bdd1bda4cd777ca186b378555 (patch)
tree5c326059e1c15c802cda0969a52e1209f60d2166 /src
parentd4e92d843650b0480b86d15ce46ed02b6fd9b5be (diff)
Replace lock with thread safety annotation in CBlockTreeDB::LoadBlockIndexGuts()
Diffstat (limited to 'src')
-rw-r--r--src/txdb.cpp13
-rw-r--r--src/txdb.h3
2 files changed, 7 insertions, 9 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index e2aed1da7c..5e4379a60a 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -296,8 +296,8 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
{
+ AssertLockHeld(::cs_main);
std::unique_ptr<CDBIterator> pcursor(NewIterator());
-
pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256()));
// Load m_block_index
@@ -311,19 +311,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 d1f47719c4..e70f3cd1f2 100644
--- a/src/txdb.h
+++ b/src/txdb.h
@@ -86,7 +86,8 @@ public:
void ReadReindexing(bool &fReindexing);
bool WriteFlag(const std::string &name, bool fValue);
bool ReadFlag(const std::string &name, bool &fValue);
- bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex);
+ bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
+ EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
};
std::optional<bilingual_str> CheckLegacyTxindex(CBlockTreeDB& block_tree_db);