Skip to content

Commit

Permalink
Merge bitcoin#15321: doc: Add cs_main lock annotations for mapBlockIndex
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Feb 6, 2019
2 parents 1a60369 + fa2a69f commit 5cdb821
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class CChainState {

public:
CChain chainActive;
BlockMap mapBlockIndex;
BlockMap mapBlockIndex GUARDED_BY(cs_main);
std::multimap<CBlockIndex*, CBlockIndex*> mapBlocksUnlinked;
CBlockIndex *pindexBestInvalid = nullptr;

Expand Down
4 changes: 2 additions & 2 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extern CBlockPolicyEstimator feeEstimator;
extern CTxMemPool mempool;
extern std::atomic_bool g_is_mempool_loaded;
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
extern BlockMap& mapBlockIndex;
extern BlockMap& mapBlockIndex GUARDED_BY(cs_main);
extern uint64_t nLastBlockTx;
extern uint64_t nLastBlockWeight;
extern const std::string strMessageMagic;
Expand Down Expand Up @@ -288,7 +288,7 @@ uint64_t CalculateCurrentUsage();
/**
* Mark one block file as pruned.
*/
void PruneOneBlockFile(const int fileNumber);
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

/**
* Actually unlink the specified files
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/test/wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
CBlockIndex* newTip = chainActive.Tip();

LockAnnotation lock(::cs_main);
auto locked_chain = chain->lock();

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

LockAnnotation lock(::cs_main);
auto locked_chain = chain->lock();

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

0 comments on commit 5cdb821

Please sign in to comment.