This PR is a late follow-up fix for #30657 (commit faa1b9b0e6de7d213699fbdbc2e25a2a81c35cdc): The verifychain RPC returns false on failure instead of raising, so the block/undo file integrity check after manually un-XORing the files could never fail. Corruption in recent blocks is still caught by the startup check (-checkblocks, default 6), but older blocks are only read by verifychain(nblocks=0), whose result was ignored.
The fix can be verified with the following diff, which makes the node write blocks at heights 1-99 without obfuscation (the genesis block is excluded, as it is read back right after writing):
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -1155,6 +1155,7 @@ FlatFilePos BlockManager::WriteBlock(const CBlock& block, int nHeight)
return FlatFilePos();
}
AutoFile file{OpenBlockFile(pos, /*fReadOnly=*/false)};
+ if (nHeight > 0 && nHeight < 100) file.SetObfuscation({});
if (file.IsNull()) {
LogError("OpenBlockFile failed for %s while writing block", pos.ToString());
m_opts.notifications.fatalError(_("Failed to write block."));
Running the test with this patch applied passes on master, but fails on this PR (use test_runner.py to use a fresh blocks cache for each run).