validation: do not activate snapshot if behind active chain
Summary:
Most easily reviewed with
git show --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This is a partial backport of core#27596
https://github.com/bitcoin/bitcoin/pull/27596/commits/62ac519e718eb7a31dca1102a96ba219fbc7f95d
with a minor change to a log message (work, not height) from core#28562
Depends on D17898
Test Plan:
ninja all check-all
On the dev branch with loadtxoutset implemented:
- call invalidateblock at height 887_000
- call reconsiderblock
- quickly shut down the node with ctrl-c in the terminal window (don't wait for reconsiderblock to return)
- erase mempool.dat
- start node with -blocksonly
- load snapshot before the node reached the snapshot height 888_000
- watch the chain catch up beyond block 888_000 while it's still loading coins, and then flushing the snapshot
- see loadtxoutset fail, check that debug.log has the "activation failed - work does not exceed active chainstate" message
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D17899