Skip to content

Commit b641f60

Browse files
committed
Merge #13481: doc: Rewrite some validation docs as lock annotations
fa324a8 doc: Rewrite some validation doc as lock annotations (MarcoFalke) Pull request description: #13402 added some lock annotations in comments. This pull removes them and adds clang-readable locking annotations instead. Tree-SHA512: 2d392efa8ac4978830a9df08b2009e69d6f1ac031f62be2275ae8d7c7e483331c7f8d458d865443af907a7af27a592421c6cca6b2df3f2877e0f369b9198f383
2 parents 3a3eabe + fa324a8 commit b641f60

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/validation.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ class CChainState {
157157
std::multimap<CBlockIndex*, CBlockIndex*> mapBlocksUnlinked;
158158
CBlockIndex *pindexBestInvalid = nullptr;
159159

160-
bool LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree);
160+
bool LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
161161

162162
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock);
163163

164164
/**
165165
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
166166
* that it doesn't descend from an invalid block, and then add it to mapBlockIndex.
167167
*/
168-
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex);
169-
bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock);
168+
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
169+
bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
170170

171171
// Block (dis)connection on a given view:
172172
DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view);
@@ -177,9 +177,9 @@ class CChainState {
177177
bool DisconnectTip(CValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions *disconnectpool);
178178

179179
// Manual block validity manipulation:
180-
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
181-
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
182-
bool ResetBlockFailureFlags(CBlockIndex *pindex);
180+
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
181+
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
182+
bool ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
183183

184184
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
185185
bool RewindBlockIndex(const CChainParams& params);
@@ -193,9 +193,9 @@ class CChainState {
193193
bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace);
194194
bool ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool);
195195

196-
CBlockIndex* AddToBlockIndex(const CBlockHeader& block);
196+
CBlockIndex* AddToBlockIndex(const CBlockHeader& block) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
197197
/** Create a new block index entry for a given block hash */
198-
CBlockIndex * InsertBlockIndex(const uint256& hash);
198+
CBlockIndex* InsertBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
199199
/**
200200
* Make various assertions about the state of the block index.
201201
*
@@ -204,11 +204,11 @@ class CChainState {
204204
void CheckBlockIndex(const Consensus::Params& consensusParams);
205205

206206
void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state);
207-
CBlockIndex* FindMostWorkChain();
208-
void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
207+
CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
208+
void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
209209

210210

211-
bool RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs, const CChainParams& params);
211+
bool RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs, const CChainParams& params) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
212212
} g_chainstate;
213213

214214

@@ -2645,7 +2645,7 @@ bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainPar
26452645
return true;
26462646
}
26472647

2648-
static void NotifyHeaderTip() {
2648+
static void NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
26492649
bool fNotify = false;
26502650
bool fInitialBlockDownload = false;
26512651
static CBlockIndex* pindexHeaderOld = nullptr;
@@ -3395,7 +3395,7 @@ bool CChainState::AcceptBlockHeader(const CBlockHeader& block, CValidationState&
33953395
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state));
33963396

33973397
// If the previous block index isn't valid, determine if it descends from any block which
3398-
// has been found invalid (g_failed_blocks), then mark pindexPrev and any blocks
3398+
// has been found invalid (m_failed_blocks), then mark pindexPrev and any blocks
33993399
// between them as failed.
34003400
if (!pindexPrev->IsValid(BLOCK_VALID_SCRIPTS)) {
34013401
for (const CBlockIndex* failedit : m_failed_blocks) {
@@ -3826,7 +3826,7 @@ CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash)
38263826

38273827
bool CChainState::LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree)
38283828
{
3829-
if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash){ return this->InsertBlockIndex(hash); }))
3829+
if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); }))
38303830
return false;
38313831

38323832
boost::this_thread::interruption_point();
@@ -3876,7 +3876,7 @@ bool CChainState::LoadBlockIndex(const Consensus::Params& consensus_params, CBlo
38763876
return true;
38773877
}
38783878

3879-
bool static LoadBlockIndexDB(const CChainParams& chainparams)
3879+
bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
38803880
{
38813881
if (!g_chainstate.LoadBlockIndex(chainparams.GetConsensus(), *pblocktree))
38823882
return false;

src/validation.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,20 @@ static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
233233
* Note that we guarantee that either the proof-of-work is valid on pblock, or
234234
* (and possibly also) BlockChecked will have been called.
235235
*
236-
* May not be called with cs_main held. May not be called in a
236+
* May not be called in a
237237
* validationinterface callback.
238238
*
239239
* @param[in] pblock The block we want to process.
240240
* @param[in] fForceProcessing Process this block even if unrequested; used for non-network block sources and whitelisted peers.
241241
* @param[out] fNewBlock A boolean which is set to indicate if the block was first received via this call
242242
* @return True if state.IsValid()
243243
*/
244-
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock);
244+
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock) LOCKS_EXCLUDED(cs_main);
245245

246246
/**
247247
* Process incoming block headers.
248248
*
249-
* May not be called with cs_main held. May not be called in a
249+
* May not be called in a
250250
* validationinterface callback.
251251
*
252252
* @param[in] block The block headers themselves
@@ -255,7 +255,7 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
255255
* @param[out] ppindex If set, the pointer will be set to point to the last new block index object for the given headers
256256
* @param[out] first_invalid First header that fails validation, if one exists
257257
*/
258-
bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=nullptr, CBlockHeader *first_invalid=nullptr);
258+
bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr, CBlockHeader* first_invalid = nullptr) LOCKS_EXCLUDED(cs_main);
259259

260260
/** Check whether enough disk space is available for an incoming block */
261261
bool CheckDiskSpace(uint64_t nAdditionalBytes = 0, bool blocks_dir = false);
@@ -269,7 +269,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
269269
bool LoadGenesisBlock(const CChainParams& chainparams);
270270
/** Load the block tree and coins database from disk,
271271
* initializing state if we're running with -reindex. */
272-
bool LoadBlockIndex(const CChainParams& chainparams);
272+
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
273273
/** Update the chain tip based on database information. */
274274
bool LoadChainTip(const CChainParams& chainparams);
275275
/** Unload database information */
@@ -413,8 +413,8 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const CBlockIndex* pindex
413413
/** Context-independent validity checks */
414414
bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
415415

416-
/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
417-
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
416+
/** Check a block is completely valid from start to finish (only works on top of our current best block) */
417+
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
418418

419419
/** Check whether witness commitments are required for block. */
420420
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
@@ -454,16 +454,16 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
454454

455455
/** Mark a block as precious and reorganize.
456456
*
457-
* May not be called with cs_main held. May not be called in a
457+
* May not be called in a
458458
* validationinterface callback.
459459
*/
460-
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
460+
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main);
461461

462462
/** Mark a block as invalid. */
463-
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
463+
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
464464

465465
/** Remove invalidity status from a block and its descendants. */
466-
bool ResetBlockFailureFlags(CBlockIndex *pindex);
466+
bool ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
467467

468468
/** The currently-connected chain of blocks (protected by cs_main). */
469469
extern CChain& chainActive;

0 commit comments

Comments
 (0)