mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Fix assumeutxo crash due to missing base_blockhash
This commit is contained in:
parent
fa8fffebe8
commit
fa9b74f5ea
2 changed files with 14 additions and 25 deletions
|
@ -259,6 +259,11 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Determi
|
||||||
// Coins count is smaller than coins in file
|
// Coins count is smaller than coins in file
|
||||||
metadata.m_coins_count -= 1;
|
metadata.m_coins_count -= 1;
|
||||||
}));
|
}));
|
||||||
|
BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot(
|
||||||
|
m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) {
|
||||||
|
// Wrong hash
|
||||||
|
metadata.m_base_blockhash = uint256::ONE;
|
||||||
|
}));
|
||||||
|
|
||||||
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(m_node, m_path_root));
|
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(m_node, m_path_root));
|
||||||
|
|
||||||
|
|
|
@ -5423,6 +5423,15 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
||||||
|
|
||||||
assert(coins_cache.GetBestBlock() == base_blockhash);
|
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;
|
CCoinsStats stats;
|
||||||
auto breakpoint_fnc = [] { /* TODO insert breakpoint here? */ };
|
auto breakpoint_fnc = [] { /* TODO insert breakpoint here? */ };
|
||||||
|
|
||||||
|
@ -5435,31 +5444,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the base blockhash appears in the known chain of valid headers. We're willing to
|
|
||||||
// wait a bit here because the snapshot may have been loaded on startup, before we've
|
|
||||||
// received headers from the network.
|
|
||||||
|
|
||||||
int max_secs_to_wait_for_headers = 60 * 10;
|
|
||||||
CBlockIndex* snapshot_start_block = nullptr;
|
|
||||||
|
|
||||||
while (max_secs_to_wait_for_headers > 0) {
|
|
||||||
snapshot_start_block = WITH_LOCK(::cs_main,
|
|
||||||
return m_blockman.LookupBlockIndex(base_blockhash));
|
|
||||||
--max_secs_to_wait_for_headers;
|
|
||||||
|
|
||||||
if (!snapshot_start_block) {
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (snapshot_start_block == nullptr) {
|
|
||||||
LogPrintf("[snapshot] timed out waiting for snapshot start blockheader %s\n",
|
|
||||||
base_blockhash.ToString());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert that the deserialized chainstate contents match the expected assumeutxo value.
|
// Assert that the deserialized chainstate contents match the expected assumeutxo value.
|
||||||
|
|
||||||
int base_height = snapshot_start_block->nHeight;
|
int base_height = snapshot_start_block->nHeight;
|
||||||
|
|
Loading…
Add table
Reference in a new issue