aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@chaincode.com>2023-06-06 18:35:37 -0400
committerSuhas Daftuar <sdaftuar@chaincode.com>2023-07-14 17:10:49 -0400
commit3cfc75366e6596942cbc84f354f42dfd7fc5c073 (patch)
treeea10a8c7df7e61a8b15b9308a20e5ebe0e69e5e5 /src
parent272fbc370c4e133d31d9f1d34e327cc265c5fad2 (diff)
test: Clear block index flags when testing snapshots
When simulating a snapshot, remove the HAVE_DATA status for blocks below the snapshot height, to simulate never having downloaded them at all. This makes tests more realistic (and more closely match what will happen when using assumeutxo).
Diffstat (limited to 'src')
-rw-r--r--src/test/util/chainstate.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/util/chainstate.h b/src/test/util/chainstate.h
index bf8f8b5819..9ff2c08807 100644
--- a/src/test/util/chainstate.h
+++ b/src/test/util/chainstate.h
@@ -71,6 +71,7 @@ CreateAndActivateUTXOSnapshot(
// This is a stripped-down version of node::LoadChainstate which
// preserves the block index.
LOCK(::cs_main);
+ CBlockIndex *orig_tip = node.chainman->ActiveChainstate().m_chain.Tip();
uint256 gen_hash = node.chainman->ActiveChainstate().m_chain[0]->GetBlockHash();
node.chainman->ResetChainstates();
node.chainman->InitializeChainstate(node.mempool.get());
@@ -83,6 +84,22 @@ CreateAndActivateUTXOSnapshot(
chain.setBlockIndexCandidates.insert(node.chainman->m_blockman.LookupBlockIndex(gen_hash));
chain.LoadChainTip();
node.chainman->MaybeRebalanceCaches();
+
+ // Reset the HAVE_DATA flags below the snapshot height, simulating
+ // never-having-downloaded them in the first place.
+ // TODO: perhaps we could improve this by using pruning to delete
+ // these blocks instead
+ CBlockIndex *pindex = orig_tip;
+ while (pindex && pindex != chain.m_chain.Tip()) {
+ pindex->nStatus &= ~BLOCK_HAVE_DATA;
+ pindex->nStatus &= ~BLOCK_HAVE_UNDO;
+ // We have to set the ASSUMED_VALID flag, because otherwise it
+ // would not be possible to have a block index entry without HAVE_DATA
+ // and with nTx > 0 (since we aren't setting the pruned flag);
+ // see CheckBlockIndex().
+ pindex->nStatus |= BLOCK_ASSUMED_VALID;
+ pindex = pindex->pprev;
+ }
}
BlockValidationState state;
if (!node.chainman->ActiveChainstate().ActivateBestChain(state)) {