Skip to content

Commit 49c1aa5

Browse files
author
MarcoFalke
committed
Merge #15971: validation: Add compile-time checking for negative locking requirement in LimitValidationInterfaceQueue
62d50ef Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main) (practicalswift) Pull request description: This PR adds compile-time checking for negative locking requirements that follow from the run-time locking requirement `AssertLockNotHeld(cs_main)` in `LimitValidationInterfaceQueue(...)`. Changes: * Add `LOCKS_EXCLUDED(cs_main)` to `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)` * Add `LOCKS_EXCLUDED(cs_main)` to `CChainState::ActivateBestChain(…)`, `CChainState:: InvalidateBlock(…)` and `CChainState::RewindBlockIndex(…)` which all call `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)` * Add `LOCKS_EXCLUDED(cs_main)` to `InvalidateBlock(…)` which calls `CChainState::InvalidateBlock(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)` * Add `LOCKS_EXCLUDED(cs_main)` to `RewindBlockIndex(…)` which calls `CChainState::RewindBlockIndex(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)` ACKs for commit 62d50e: MarcoFalke: utACK 62d50ef Tree-SHA512: 73d092ccd08c851ae3c5d60370c369fc030c5793f5507e2faccb6f91c851ddc0ce059fbea3899f2856330d7a8c78f2ac6a2988e8268b03154f946be9e60e3be1
2 parents bbb7119 + 62d50ef commit 49c1aa5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class CChainState {
166166

167167
bool LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
168168

169-
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock);
169+
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) LOCKS_EXCLUDED(cs_main);
170170

171171
/**
172172
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
@@ -185,11 +185,11 @@ class CChainState {
185185

186186
// Manual block validity manipulation:
187187
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
188-
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex);
188+
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
189189
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
190190

191191
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
192-
bool RewindBlockIndex(const CChainParams& params);
192+
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
193193
bool LoadGenesisBlock(const CChainParams& chainparams);
194194

195195
void PruneBlockIndexCandidates();
@@ -2651,7 +2651,7 @@ static void NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
26512651
}
26522652
}
26532653

2654-
static void LimitValidationInterfaceQueue() {
2654+
static void LimitValidationInterfaceQueue() LOCKS_EXCLUDED(cs_main) {
26552655
AssertLockNotHeld(cs_main);
26562656

26572657
if (GetMainSignals().CallbacksPending() > 10) {

src/validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa
393393
bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
394394

395395
/** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
396-
bool RewindBlockIndex(const CChainParams& params);
396+
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
397397

398398
/** Update uncommitted block structures (currently: only the witness reserved value). This is safe for submitted blocks. */
399399
void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
@@ -430,7 +430,7 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
430430
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main);
431431

432432
/** Mark a block as invalid. */
433-
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex);
433+
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
434434

435435
/** Remove invalidity status from a block and its descendants. */
436436
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

0 commit comments

Comments
 (0)