Skip to content

Commit 871d3ae

Browse files
committed
Merge #16757: doc: CChainState return values
fa912a8 doc: move-only ActivateBestChain doxygen comment to header (MarcoFalke) fa99efd doc: ActivateBestChainStep return value (MarcoFalke) Pull request description: It will always return true, unless a system error such as #15305 occurred ACKs for top commit: laanwj: ACK fa912a8 Tree-SHA512: d439da844a467f9705014b946d7d987fb62cb63fe6a325b2fdbbb73a6578fc0ade3f60892044f02face43948204fc4e3c9fa70d108233d4ca8eef27984059689
2 parents 19f301d + fa912a8 commit 871d3ae

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/validation.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,8 @@ void CChainState::PruneBlockIndexCandidates() {
25082508
/**
25092509
* Try to make some progress towards making pindexMostWork the active block.
25102510
* pblock is either nullptr or a pointer to a CBlock corresponding to pindexMostWork.
2511+
*
2512+
* @returns true unless a system error occurred
25112513
*/
25122514
bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace)
25132515
{
@@ -2627,15 +2629,6 @@ static void LimitValidationInterfaceQueue() LOCKS_EXCLUDED(cs_main) {
26272629
}
26282630
}
26292631

2630-
/**
2631-
* Make the best chain active, in multiple steps. The result is either failure
2632-
* or an activated best chain. pblock is either nullptr or a pointer to a block
2633-
* that is already loaded (to avoid loading it again from disk).
2634-
*
2635-
* ActivateBestChain is split into steps (see ActivateBestChainStep) so that
2636-
* we avoid holding cs_main for an extended period of time; the length of this
2637-
* call may be quite long during reindexing or a substantial reorg.
2638-
*/
26392632
bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) {
26402633
// Note that while we're often called here from ProcessNewBlock, this is
26412634
// far from a guarantee. Things in the P2P/RPC will often end up calling
@@ -2683,8 +2676,10 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
26832676

26842677
bool fInvalidFound = false;
26852678
std::shared_ptr<const CBlock> nullBlockPtr;
2686-
if (!ActivateBestChainStep(state, chainparams, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fInvalidFound, connectTrace))
2679+
if (!ActivateBestChainStep(state, chainparams, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fInvalidFound, connectTrace)) {
2680+
// A system error occurred
26872681
return false;
2682+
}
26882683
blocks_connected = true;
26892684

26902685
if (fInvalidFound) {

src/validation.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
211211
* @param[in] pblock The block we want to process.
212212
* @param[in] fForceProcessing Process this block even if unrequested; used for non-network block sources and whitelisted peers.
213213
* @param[out] fNewBlock A boolean which is set to indicate if the block was first received via this call
214-
* @return True if state.IsValid()
214+
* @returns If the block was processed, independently of block validity
215215
*/
216216
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock) LOCKS_EXCLUDED(cs_main);
217217

@@ -653,6 +653,8 @@ class CChainState {
653653
*
654654
* If FlushStateMode::NONE is used, then FlushStateToDisk(...) won't do anything
655655
* besides checking if we need to prune.
656+
*
657+
* @returns true unless a system error occurred
656658
*/
657659
bool FlushStateToDisk(
658660
const CChainParams& chainparams,
@@ -667,7 +669,20 @@ class CChainState {
667669
//! if we pruned.
668670
void PruneAndFlush();
669671

670-
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) LOCKS_EXCLUDED(cs_main);
672+
/**
673+
* Make the best chain active, in multiple steps. The result is either failure
674+
* or an activated best chain. pblock is either nullptr or a pointer to a block
675+
* that is already loaded (to avoid loading it again from disk).
676+
*
677+
* ActivateBestChain is split into steps (see ActivateBestChainStep) so that
678+
* we avoid holding cs_main for an extended period of time; the length of this
679+
* call may be quite long during reindexing or a substantial reorg.
680+
*
681+
* @returns true unless a system error occurred
682+
*/
683+
bool ActivateBestChain(CValidationState& state,
684+
const CChainParams& chainparams,
685+
std::shared_ptr<const CBlock> pblock) LOCKS_EXCLUDED(cs_main);
671686

672687
bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
673688

0 commit comments

Comments
 (0)