Add feature_dbcrash_replay.py, a deterministic functional test for Chainstate::ReplayBlocks.
ReplayBlocks is currently only exercised by feature_dbcrash.py, which relies on random crash points and reorgs, takes several minutes and is in EXTENDED_SCRIPTS, so it never runs on PRs.
feature_dbcrash_replay.py finish in ~1s and deterministically kills at least these 2 mutants:
diff --git a/src/validation.cpp b/src/validation.cpp
index 6bed39ba5f..f4a0094df9 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4903,7 +4903,7 @@ bool Chainstate::ReplayBlocks()
const int nForkHeight{pindexFork ? pindexFork->nHeight : 0};
if (pindexOld != pindexFork) {
LogInfo("Rolling back from %s (%i to %i)", pindexOld->GetBlockHash().ToString(), pindexOld->nHeight, nForkHeight);
- while (pindexOld != pindexFork) {
+ while (pindexOld->pprev != pindexFork) {
if (pindexOld->nHeight > 0) { // Never disconnect the genesis block.
CBlock block;
if (!m_blockman.ReadBlock(block, *pindexOld)) {
diff --git a/src/validation.cpp b/src/validation.cpp
index 6bed39b..e006c9a 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4931,7 +4931,7 @@ bool Chainstate::ReplayBlocks()
// Roll forward from the forking point to the new tip.
if (nForkHeight < pindexNew->nHeight) {
LogInfo("Rolling forward to %s (%i to %i)", pindexNew->GetBlockHash().ToString(), nForkHeight, pindexNew->nHeight);
- for (int nHeight = nForkHeight + 1; nHeight <= pindexNew->nHeight; ++nHeight) {
+ for (int nHeight = nForkHeight + 1; nHeight < pindexNew->nHeight; ++nHeight) {
const CBlockIndex& pindex{*Assert(pindexNew->GetAncestor(nHeight))};
if (nHeight % 10'000 == 0) {