Skip to content

Commit 43fa355

Browse files
author
MarcoFalke
committed
Merge #13402: Document validationinterace callback blocking deadlock potential.
25bc961 Document validationinterace callback blocking deadlock potential. (Matt Corallo) Pull request description: From the branches-I've-had-lying-around-and-forgot-to-PR department... This is a comment-only PR, but the comments point out an API quirk that isn't exactly trivial. None of our use-cases right now hit this, but if we were to call SyncWithValidationInterfaceQueue (eg to limit queue depth) in ATMP, I'm pretty sure we'd hit a deadlock there. Tree-SHA512: 889dd8fc9eb15d1f2aa5ca467e783bc8f07bc543b166b032741795b0db7a0df11a2846d3cb7c69bafa8d1acf970021001b742f52be06725a932813230c5b4a7b
2 parents 32bf4c6 + 25bc961 commit 43fa355

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
@@ -2698,6 +2698,9 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
26982698
// Block until the validation queue drains. This should largely
26992699
// never happen in normal operation, however may happen during
27002700
// reindex, causing memory blowup if we run too far ahead.
2701+
// Note that if a validationinterface callback ends up calling
2702+
// ActivateBestChain this may lead to a deadlock! We should
2703+
// probably have a DEBUG_LOCKORDER test for this in the future.
27012704
SyncWithValidationInterfaceQueue();
27022705
}
27032706

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)