Skip to content

Commit 25bc961

Browse files
committed
Document validationinterace callback blocking deadlock potential.
1 parent a589f53 commit 25bc961

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/validation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,9 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
27042704
// Block until the validation queue drains. This should largely
27052705
// never happen in normal operation, however may happen during
27062706
// reindex, causing memory blowup if we run too far ahead.
2707+
// Note that if a validationinterface callback ends up calling
2708+
// ActivateBestChain this may lead to a deadlock! We should
2709+
// probably have a DEBUG_LOCKORDER test for this in the future.
27072710
SyncWithValidationInterfaceQueue();
27082711
}
27092712

src/validation.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ 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-
* Call without cs_main held.
236+
* May not be called with cs_main held. May not be called in a
237+
* validationinterface callback.
237238
*
238239
* @param[in] pblock The block we want to process.
239240
* @param[in] fForceProcessing Process this block even if unrequested; used for non-network block sources and whitelisted peers.
@@ -245,7 +246,8 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
245246
/**
246247
* Process incoming block headers.
247248
*
248-
* Call without cs_main held.
249+
* May not be called with cs_main held. May not be called in a
250+
* validationinterface callback.
249251
*
250252
* @param[in] block The block headers themselves
251253
* @param[out] state This may be set to an Error state if any error occurred processing them
@@ -278,7 +280,12 @@ void ThreadScriptCheck();
278280
bool IsInitialBlockDownload();
279281
/** Retrieve a transaction (from memory pool, or from disk, if possible) */
280282
bool GetTransaction(const uint256& hash, CTransactionRef& tx, const Consensus::Params& params, uint256& hashBlock, bool fAllowSlow = false, CBlockIndex* blockIndex = nullptr);
281-
/** Find the best known block, and make it the tip of the block chain */
283+
/**
284+
* Find the best known block, and make it the tip of the block chain
285+
*
286+
* May not be called with cs_main held. May not be called in a
287+
* validationinterface callback.
288+
*/
282289
bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
283290
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
284291

@@ -445,7 +452,11 @@ inline CBlockIndex* LookupBlockIndex(const uint256& hash)
445452
/** Find the last common block between the parameter chain and a locator. */
446453
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
447454

448-
/** Mark a block as precious and reorganize. */
455+
/** Mark a block as precious and reorganize.
456+
*
457+
* May not be called with cs_main held. May not be called in a
458+
* validationinterface callback.
459+
*/
449460
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
450461

451462
/** Mark a block as invalid. */

0 commit comments

Comments
 (0)