test: fix block file integrity check in feature_blocksxor.py #37051

Manually merged
theStack merged 1 commit from test-fix-blocksxor-verifychain-assert into master 2026-12-03 10:34:24 +00:00 AGit
theStack commented 2026-12-02 16:16:56 +00:00 (Migrated from github.com)

This PR is a late follow-up fix for #30657 (commit faa1b9b0e6): 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).

This PR is a late follow-up fix for #30657 (commit faa1b9b0e6de7d213699fbdbc2e25a2a81c35cdc): The `verifychain` RPC [returns false on failure](https://github.com/bitcoin/bitcoin/blob/e3a72a374435ad3266c8931846bbcdb7b0e5e7c2/src/rpc/blockchain.cpp#L1301) 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): ```diff --- 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).
DrahtBot commented 2026-12-02 16:24:13 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK maflcko, l0rinc

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37051 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37051.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37051#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/37051#issuecomment-7352974757), [l0rinc](https://github.com/bitcoin/bitcoin/pull/37051#issuecomment-7353141766) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
maflcko commented 2026-12-02 17:09:14 +00:00 (Migrated from github.com)

lgtm ACK 219c5c8ef7

lgtm ACK 219c5c8ef79a7a521562b5112d7a77b3a27d13dd
l0rinc commented 2026-12-02 17:16:59 +00:00 (Migrated from github.com)
ACK 219c5c8ef79a7a521562b5112d7a77b3a27d13dd
fanquake commented 2026-12-03 10:38:12 +00:00 (Migrated from github.com)

Backported to 32.x in #37052.

Backported to `32.x` in #37052.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!37051
No description provided.