@@ -4815,6 +4815,26 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
4815
4815
4816
4816
uint256 base_blockhash = metadata.m_base_blockhash ;
4817
4817
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
+
4818
4838
COutPoint outpoint;
4819
4839
Coin coin;
4820
4840
const uint64_t coins_count = metadata.m_coins_count ;
@@ -4905,15 +4925,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
4905
4925
4906
4926
assert (coins_cache.GetBestBlock () == base_blockhash);
4907
4927
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
-
4917
4928
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
4918
4929
auto breakpoint_fnc = [] { /* TODO insert breakpoint here? */ };
4919
4930
@@ -4927,18 +4938,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
4927
4938
}
4928
4939
4929
4940
// 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
-
4942
4941
if (AssumeutxoHash{stats.hashSerialized } != au_data.hash_serialized ) {
4943
4942
LogPrintf (" [snapshot] bad snapshot content hash: expected %s, got %s\n " ,
4944
4943
au_data.hash_serialized .ToString (), stats.hashSerialized .ToString ());
0 commit comments