aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-04-04 08:23:06 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-05-11 10:41:03 +0200
commitfae33f98e6a8d5934edbdce2eb8688112eac41a8 (patch)
treeea6a7d0ee4a8d6137fc35752e5d1c676125dd4bf /src/validation.cpp
parentfa5668bfb34e2778936af30e9fb6bd3c6bcf41fd (diff)
downloadbitcoin-fae33f98e6a8d5934edbdce2eb8688112eac41a8.tar.xz
Fix assumeutxo crash due to invalid base_blockhash
Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 354ff182e2..65bfbbf999 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4815,6 +4815,26 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
uint256 base_blockhash = metadata.m_base_blockhash;
+ CBlockIndex* snapshot_start_block = WITH_LOCK(::cs_main, return m_blockman.LookupBlockIndex(base_blockhash));
+
+ if (!snapshot_start_block) {
+ // Needed for GetUTXOStats and ExpectedAssumeutxo to determine the height and to avoid a crash when base_blockhash.IsNull()
+ LogPrintf("[snapshot] Did not find snapshot start blockheader %s\n",
+ base_blockhash.ToString());
+ return false;
+ }
+
+ int base_height = snapshot_start_block->nHeight;
+ auto maybe_au_data = ExpectedAssumeutxo(base_height, ::Params());
+
+ if (!maybe_au_data) {
+ LogPrintf("[snapshot] assumeutxo height in snapshot metadata not recognized " /* Continued */
+ "(%d) - refusing to load snapshot\n", base_height);
+ return false;
+ }
+
+ const AssumeutxoData& au_data = *maybe_au_data;
+
COutPoint outpoint;
Coin coin;
const uint64_t coins_count = metadata.m_coins_count;
@@ -4905,15 +4925,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
assert(coins_cache.GetBestBlock() == base_blockhash);
- CBlockIndex* snapshot_start_block = WITH_LOCK(::cs_main, return m_blockman.LookupBlockIndex(base_blockhash));
-
- if (!snapshot_start_block) {
- // Needed for GetUTXOStats to determine the height
- LogPrintf("[snapshot] Did not find snapshot start blockheader %s\n",
- base_blockhash.ToString());
- return false;
- }
-
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
auto breakpoint_fnc = [] { /* TODO insert breakpoint here? */ };
@@ -4927,18 +4938,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
}
// Assert that the deserialized chainstate contents match the expected assumeutxo value.
-
- int base_height = snapshot_start_block->nHeight;
- auto maybe_au_data = ExpectedAssumeutxo(base_height, ::Params());
-
- if (!maybe_au_data) {
- LogPrintf("[snapshot] assumeutxo height in snapshot metadata not recognized " /* Continued */
- "(%d) - refusing to load snapshot\n", base_height);
- return false;
- }
-
- const AssumeutxoData& au_data = *maybe_au_data;
-
if (AssumeutxoHash{stats.hashSerialized} != au_data.hash_serialized) {
LogPrintf("[snapshot] bad snapshot content hash: expected %s, got %s\n",
au_data.hash_serialized.ToString(), stats.hashSerialized.ToString());