[#Chainstate-ActivateBestChain]
= xref:Chainstate.adoc[Chainstate]::ActivateBestChain
:relfileprefix: ../
:mrdocs:

Find the best known block, and make it the tip of the block chain&period; The result is either failure or an activated best chain&period; pblock is either nullptr or a pointer to a block that is already loaded (to avoid loading it again from disk)&period;

== Synopsis

Declared in `&lt;validation&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
&lsqb;&lsqb;requires&lowbar;capability(0x7f2e1ba842c8), locks&lowbar;excluded(0x7f2e1ba84398), requires&lowbar;capability(0x7f2e14563f18), locks&lowbar;excluded(0x7f2e14563fe8), requires&lowbar;capability(0x7f2e373bd0c8), locks&lowbar;excluded(0x7f2e373bd198), requires&lowbar;capability(0x7f2e36e33d18), locks&lowbar;excluded(0x7f2e36e33de8)&rsqb;&rsqb;
bool
ActivateBestChain(
    xref:BlockValidationState.adoc[BlockValidationState]& state,
    std::shared&lowbar;ptr&lt;CBlock const&gt; pblock = nullptr);
----

== Description

ActivateBestChain is split into steps (see ActivateBestChainStep) so that we avoid holding cs&lowbar;main for an extended period of time&semi; the length of this call may be quite long during reindexing or a substantial reorg&period;

May not be called with cs&lowbar;main held&period; May not be called in a validationinterface callback&period;

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&period; `cs&lowbar;main` will be held during this time&period;

== Return Value

true unless a system error occurred

== Parameters

[cols="1,4"]
|===
| Name| Description
| *state* [in]
| Validation state updated if a system error occurs&period;
| *pblock* [in]
| Optional already&hyphen;loaded block to avoid re&hyphen;reading it from disk&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
