[#Chainstate-ActivateBestChain] = xref:Chainstate.adoc[Chainstate]::ActivateBestChain :relfileprefix: ../ :mrdocs: Find the best known block, and make it the tip of the block chain. The result is either failure or an activated best chain. pblock is either nullptr or a pointer to a block that is already loaded (to avoid loading it again from disk). == Synopsis Declared in `<validation.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- [[requires_capability(0x7f2e1ba842c8), locks_excluded(0x7f2e1ba84398), requires_capability(0x7f2e14563f18), locks_excluded(0x7f2e14563fe8), requires_capability(0x7f2e373bd0c8), locks_excluded(0x7f2e373bd198), requires_capability(0x7f2e36e33d18), locks_excluded(0x7f2e36e33de8)]] bool ActivateBestChain( xref:BlockValidationState.adoc[BlockValidationState]& state, std::shared_ptr<CBlock const> pblock = nullptr); ---- == Description ActivateBestChain is split into steps (see ActivateBestChainStep) so that we avoid holding cs_main for an extended period of time; the length of this call may be quite long during reindexing or a substantial reorg. May not be called with cs_main held. May not be called in a validationinterface callback. Note that if this is called while a snapshot chainstate is active, and if it is called on a validated chainstate whose tip has reached the base block of the snapshot, its execution will take _MINUTES_ while it hashes the UTXO set to verify the assumeutxo value the snapshot was activated with. `cs_main` will be held during this time. == Return Value true unless a system error occurred == Parameters [cols="1,4"] |=== | Name| Description | *state* [in] | Validation state updated if a system error occurs. | *pblock* [in] | Optional already‐loaded block to avoid re‐reading it from disk. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#