aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@pm.me>2023-09-17 13:56:12 -0400
committerJames O'Beirne <james.obeirne@pm.me>2023-09-30 06:41:21 -0400
commit62ac519e718eb7a31dca1102a96ba219fbc7f95d (patch)
tree8fd7e2e8ee1472038c7c2b4d603fd1b1f3e818ab /src/test
parent9511fb3616b7bbe1d0d2f54a45ea0a650ba0367b (diff)
validation: do not activate snapshot if behind active chain
Most easily reviewed with git show --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/util/chainstate.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/test/util/chainstate.h b/src/test/util/chainstate.h
index 7f55916870..e2a88eacdd 100644
--- a/src/test/util/chainstate.h
+++ b/src/test/util/chainstate.h
@@ -109,7 +109,23 @@ CreateAndActivateUTXOSnapshot(
0 == WITH_LOCK(node.chainman->GetMutex(), return node.chainman->ActiveHeight()));
}
- return node.chainman->ActivateSnapshot(auto_infile, metadata, in_memory_chainstate);
+ auto& new_active = node.chainman->ActiveChainstate();
+ auto* tip = new_active.m_chain.Tip();
+
+ // Disconnect a block so that the snapshot chainstate will be ahead, otherwise
+ // it will refuse to activate.
+ //
+ // TODO this is a unittest-specific hack, and we should probably rethink how to
+ // better generate/activate snapshots in unittests.
+ if (tip->pprev) {
+ new_active.m_chain.SetTip(*(tip->pprev));
+ }
+
+ bool res = node.chainman->ActivateSnapshot(auto_infile, metadata, in_memory_chainstate);
+
+ // Restore the old tip.
+ new_active.m_chain.SetTip(*tip);
+ return res;
}