mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 11:50:39 +00:00
test: add functional test for XORed block/undo files (-blocksxor option) #30657
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!30657
Loading…
Reference in a new issue
No description provided.
Delete branch "202408-add_blocksxor_test"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds a dedicated functional test for XORed block data/undo file support (bitcoind option
-blocksxor, see PR #28052). In order to verify that the XOR pattern has been applied, the {blk,rev}*.dat files are rewritten un-XORed manually by the test while the node is shut down; the node is then started again with-blocksxor=0, and both the data and undo files are verified via theverifychainRPC (with checklevel=2). Note that starting bitcoind with-blocksxor=0fails if a xor key is present already, which is also tested explicitly.Fixes #30599.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Code Coverage
For detailed information about the code coverage, see the test coverage report.
Reviews
See the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Concept ACK
Approach ACK.
Nice additions.
Left a comment and a nit.
The help for
-blocksxormentionsThe created XOR-key will be zeros for an existing blocksdir or when-blocksxor=0is set.After the
verifychain, could test that a newxor.datis created (consisting of all zeros) when the node is started with noxor.datand with-blocksxor=0. Something like:or maybe lift
NUM_XOR_BYTESout ofread_xor_keyto enableor even add a constant in
util.pyto enable
nitty nit: Since this is being moved, could update to use a more descriptive function name (e.g.
xor_bytes). Feel free to ignore.ACK
faa1b9b0e6nit: Any reason to make this a global function and pass a node to it? Seems clearer to just make it a member function on the node, like
blocks_path(), no?This fails for me locally, because somehow I have 0000000000000000 as my xor key... but it fails consistently. Unsure if that's supposed to be possible?
Maybe a leftover previous
bitcoindwas used? Can you trymake clean, just to double check? Otherwise, the combined log could be useful.Tested ACK
faa1b9b0e6I added a
if (opts.use_xor) assert(xor_key != decltype(xor_key){});which hit, so not an old bitcoind. Attaching combined log.logs_30657.txt
Can you also print/log/debug the result of
fs::is_empty(opts.blocks_dir)andfs::exists(xor_key_path)?logs_30657_2.txt
Ah interesting,
fs::is_empty(opts.blocks_dir)is 0^so clearly this isn't a problem with the test
Fascinating. What is your compiler, stdlib version, OS and filesystem for
/tmp/and./?Does the issue happen when you create a non-
/tmp/folder? (I presume/tmp/is a ramdisk?)Also, what is
ls --all /tmp/bitcoin_func_test_fj812gkv/node0/regtest/blocksIs it Apple https://en.wikipedia.org/wiki/.DS_Store ?
It's jammy with clang 17, indeed it works with a non-
/tmpfolder. Nothing out of place inls. HmmmJammy doesn't have clang 17, so I guess it is installed from the nightly llvm apt and then
CC=clang-17 CXX=clang++-17 ../configure(using the libstdc++-11, not libc++-17)?Next steps to test would be:
df --human-readable /tmp/(to confirm the filesystem type)CC=gcc CXX=g++ ./configure(using the libstdc++-11)CC=clang-17 CXX='clang++-17 -stdlib=libc++-17' ./configure(using libc++-17)/tmp/dirty)?It worked with gcc.
./configuredidn't like libc++-17. After reboot I can't get it to fail anymore (also I don't mean to hold up this PR)ACK
faa1b9b0e6Thanks for checking. This is really helpful to make sure that the feature isn't shipped to users with bugs included.
My random guess would be that there was a process running on your machine which accidentally or intentionally put files into all folders in
/tmp/. However, based on your check withls --allon the temp folder, which didn't reveal any hidden files, this may be something else, or a race (as the files were deleted again by the same process or a different one).It would be useful, if an Apple person tried to break this feature with https://en.wikipedia.org/wiki/.DS_Store. The process would be:
I tried this on my apple machine and am able to make this test fail if I add a sleep right before the line checking
fs::is_empty. No sign of DS_Store. It kind of seems more like blk0000.dat, rev0000.dat, and index/ are showing up early... I don't think I know init well enough to know exactly what order everything should happen in.edit: ah, maybe I am not looking hard enough
Thanks for checking!
I honestly don't known if this should be considered a bug in Bitcoin Core. If so, are we going to enumerate all external programs that write to the blocksdir without permission and add workarounds for them?
To me it seems like this is something that Apple should fix, or Apple users (by not using Apple, or by adjusting the Finder settings to leave Bitcoin Core alone).
I guess
fs::is_empty(opts.blocks_dir)could be replaced bynot fs::exists("blk0000.dat")?fwiw the sleepy version doesn't seem to use 0 as xor key when I start a node (tried a few times with mainnet, regtest) normally. I also never have problems when I use a non-tmp folder. So maybe your guess about temp directory paranormal activity is correct.
Going to merge this test since there's not a problem with it.
No strong reason. Personally I first look into util.py for helpers and tend to forget that there are also some implemented as
TestNodemethods, but I agree that the latter makes sense. Could be picked up in a follow-up, e.g. #30669.Found this here because I saw #30833 and it got me to look into
blocksxorfor the first time. I see the same failures @glozow describes (also on macos) and I can confirm the findings here about the use of the temp folders because it does not happen when the test uses a clean chain, e.g. using a clean chain like this made the test robust for me:github.com/fjahr/bitcoin@ef00b8eab4I didn't find anything new beyond that so far but I thought it should be noted that it's not on @glozow 's machine alone.Thanks for checking. Using a clean chain means that the cache won't be used, which normally lives on the storage unit where the build dir lives, so only the temp dir should be used. However, given the prior result that a non-tmp folder was generally fine, I would have expected the opposite result (Test would be less fragile by using the persisted cache on a non-tmp dir). However, I don't have a macOS to test this, so I don't know for sure what is going on. Also, if this "fixes" the test, it will just silence the symptoms, but it may be better to fix the underlying issue itself. The suggested replacement in https://github.com/bitcoin/bitcoin/pull/30657#discussion_r1719955094 may be a good try.
I think that alone wouldn't work if the user upgrades a pruned node to v28?
Anyway, I was going to revisit this today but I simply don't see the failures anymore currently 🤷♂️ I will get back to it if I see them occur again.