aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/test/validation_chainstatemanager_tests.cpp3
-rw-r--r--src/validation.cpp13
2 files changed, 13 insertions, 3 deletions
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp
index be9e05a65e..ca38f9d5fa 100644
--- a/src/test/validation_chainstatemanager_tests.cpp
+++ b/src/test/validation_chainstatemanager_tests.cpp
@@ -232,6 +232,9 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
*chainman.ActiveChainstate().m_from_snapshot_blockhash,
*chainman.SnapshotBlockhash());
+ // Ensure that the genesis block was not marked assumed-valid.
+ BOOST_CHECK(!chainman.ActiveChain().Genesis()->IsAssumedValid());
+
const AssumeutxoData& au_data = *ExpectedAssumeutxo(snapshot_height, ::Params());
const CBlockIndex* tip = chainman.ActiveTip();
diff --git a/src/validation.cpp b/src/validation.cpp
index 207cdc8233..110218de36 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4909,7 +4909,14 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
// Fake various pieces of CBlockIndex state:
CBlockIndex* index = nullptr;
- for (int i = 0; i <= snapshot_chainstate.m_chain.Height(); ++i) {
+
+ // Don't make any modifications to the genesis block.
+ // This is especially important because we don't want to erroneously
+ // apply BLOCK_ASSUMED_VALID to genesis, which would happen if we didn't skip
+ // it here (since it apparently isn't BLOCK_VALID_SCRIPTS).
+ constexpr int AFTER_GENESIS_START{1};
+
+ for (int i = AFTER_GENESIS_START; i <= snapshot_chainstate.m_chain.Height(); ++i) {
index = snapshot_chainstate.m_chain[i];
// Fake nTx so that LoadBlockIndex() loads assumed-valid CBlockIndex
@@ -4918,7 +4925,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
index->nTx = 1;
}
// Fake nChainTx so that GuessVerificationProgress reports accurately
- index->nChainTx = index->pprev ? index->pprev->nChainTx + index->nTx : 1;
+ index->nChainTx = index->pprev->nChainTx + index->nTx;
// Mark unvalidated block index entries beneath the snapshot base block as assumed-valid.
if (!index->IsValid(BLOCK_VALID_SCRIPTS)) {
@@ -4929,7 +4936,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
// Fake BLOCK_OPT_WITNESS so that CChainState::NeedsRedownload()
// won't ask to rewind the entire assumed-valid chain on startup.
- if (index->pprev && DeploymentActiveAt(*index, ::Params().GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) {
+ if (DeploymentActiveAt(*index, ::Params().GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) {
index->nStatus |= BLOCK_OPT_WITNESS;
}