Skip to content

Commit 5cdb821

Browse files
author
MarcoFalke
committed
Merge #15321: doc: Add cs_main lock annotations for mapBlockIndex
fa2a69f doc: Add cs_main lock annotations for mapBlockIndex (practicalswift) Pull request description: Marked as "doc" because it didn't change the bitcoind on my system with default configure settings for both gcc and clang. Tree-SHA512: ba203f16c1cdc834a61c65bb5fb20bbaf7d8bff0c3a1b8ef46bc1d3669092191221e26abd7e580efab2f9bd5a992dc363251f1b68c6cd68f8204d62675868cf1
2 parents 1a60369 + fa2a69f commit 5cdb821

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class CChainState {
152152

153153
public:
154154
CChain chainActive;
155-
BlockMap mapBlockIndex;
155+
BlockMap mapBlockIndex GUARDED_BY(cs_main);
156156
std::multimap<CBlockIndex*, CBlockIndex*> mapBlocksUnlinked;
157157
CBlockIndex *pindexBestInvalid = nullptr;
158158

src/validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extern CBlockPolicyEstimator feeEstimator;
151151
extern CTxMemPool mempool;
152152
extern std::atomic_bool g_is_mempool_loaded;
153153
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
154-
extern BlockMap& mapBlockIndex;
154+
extern BlockMap& mapBlockIndex GUARDED_BY(cs_main);
155155
extern uint64_t nLastBlockTx;
156156
extern uint64_t nLastBlockWeight;
157157
extern const std::string strMessageMagic;
@@ -288,7 +288,7 @@ uint64_t CalculateCurrentUsage();
288288
/**
289289
* Mark one block file as pruned.
290290
*/
291-
void PruneOneBlockFile(const int fileNumber);
291+
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
292292

293293
/**
294294
* Actually unlink the specified files

src/wallet/test/wallet_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
4444
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
4545
CBlockIndex* newTip = chainActive.Tip();
4646

47+
LockAnnotation lock(::cs_main);
4748
auto locked_chain = chain->lock();
4849

4950
// Verify ScanForWalletTransactions accommodates a null start block.
@@ -123,6 +124,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
123124
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
124125
CBlockIndex* newTip = chainActive.Tip();
125126

127+
LockAnnotation lock(::cs_main);
126128
auto locked_chain = chain->lock();
127129

128130
// Prune the older block file.
@@ -268,6 +270,7 @@ static int64_t AddTx(CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64
268270
SetMockTime(mockTime);
269271
CBlockIndex* block = nullptr;
270272
if (blockTime > 0) {
273+
LockAnnotation lock(::cs_main);
271274
auto locked_chain = wallet.chain().lock();
272275
auto inserted = mapBlockIndex.emplace(GetRandHash(), new CBlockIndex);
273276
assert(inserted.second);

0 commit comments

Comments
 (0)