@@ -4815,6 +4815,26 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
48154815
48164816 uint256 base_blockhash = metadata.m_base_blockhash ;
48174817
4818+ CBlockIndex* snapshot_start_block = WITH_LOCK (::cs_main, return m_blockman.LookupBlockIndex (base_blockhash));
4819+
4820+ if (!snapshot_start_block) {
4821+ // Needed for GetUTXOStats and ExpectedAssumeutxo to determine the height and to avoid a crash when base_blockhash.IsNull()
4822+ LogPrintf (" [snapshot] Did not find snapshot start blockheader %s\n " ,
4823+ base_blockhash.ToString ());
4824+ return false ;
4825+ }
4826+
4827+ int base_height = snapshot_start_block->nHeight ;
4828+ auto maybe_au_data = ExpectedAssumeutxo (base_height, ::Params ());
4829+
4830+ if (!maybe_au_data) {
4831+ LogPrintf (" [snapshot] assumeutxo height in snapshot metadata not recognized " /* Continued */
4832+ " (%d) - refusing to load snapshot\n " , base_height);
4833+ return false ;
4834+ }
4835+
4836+ const AssumeutxoData& au_data = *maybe_au_data;
4837+
48184838 COutPoint outpoint;
48194839 Coin coin;
48204840 const uint64_t coins_count = metadata.m_coins_count ;
@@ -4905,15 +4925,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
49054925
49064926 assert (coins_cache.GetBestBlock () == base_blockhash);
49074927
4908- CBlockIndex* snapshot_start_block = WITH_LOCK (::cs_main, return m_blockman.LookupBlockIndex (base_blockhash));
4909-
4910- if (!snapshot_start_block) {
4911- // Needed for GetUTXOStats to determine the height
4912- LogPrintf (" [snapshot] Did not find snapshot start blockheader %s\n " ,
4913- base_blockhash.ToString ());
4914- return false ;
4915- }
4916-
49174928 CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
49184929 auto breakpoint_fnc = [] { /* TODO insert breakpoint here? */ };
49194930
@@ -4927,18 +4938,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
49274938 }
49284939
49294940 // Assert that the deserialized chainstate contents match the expected assumeutxo value.
4930-
4931- int base_height = snapshot_start_block->nHeight ;
4932- auto maybe_au_data = ExpectedAssumeutxo (base_height, ::Params ());
4933-
4934- if (!maybe_au_data) {
4935- LogPrintf (" [snapshot] assumeutxo height in snapshot metadata not recognized " /* Continued */
4936- " (%d) - refusing to load snapshot\n " , base_height);
4937- return false ;
4938- }
4939-
4940- const AssumeutxoData& au_data = *maybe_au_data;
4941-
49424941 if (AssumeutxoHash{stats.hashSerialized } != au_data.hash_serialized ) {
49434942 LogPrintf (" [snapshot] bad snapshot content hash: expected %s, got %s\n " ,
49444943 au_data.hash_serialized .ToString (), stats.hashSerialized .ToString ());
0 commit comments