test: add functional test for XORed block/undo files (-blocksxor option) #30657

Manually merged
theStack merged 2 commits from 202408-add_blocksxor_test into master 2024-08-16 15:26:08 +00:00 AGit
theStack commented 2024-08-14 15:34:52 +00:00 (Migrated from github.com)

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 the verifychain RPC (with checklevel=2). Note that starting bitcoind with -blocksxor=0 fails if a xor key is present already, which is also tested explicitly.

Fixes #30599.

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 the `verifychain` RPC (with checklevel=2). Note that starting bitcoind with `-blocksxor=0` fails if a xor key is present already, which is also tested explicitly. Fixes #30599.
DrahtBot commented 2024-08-14 15:34:55 +00:00 (Migrated from github.com)

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.

Type Reviewers
ACK maflcko, ismaelsadeeq, glozow
Concept ACK TheCharlatan
Approach ACK tdb3

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### Code Coverage For detailed information about the code coverage, see the [test coverage report](https://corecheck.dev/bitcoin/bitcoin/pulls/30657). <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/30657#pullrequestreview-2239750096), [ismaelsadeeq](https://github.com/bitcoin/bitcoin/pull/30657#pullrequestreview-2240361497), [glozow](https://github.com/bitcoin/bitcoin/pull/30657#issuecomment-2293114610) | | Concept ACK | [TheCharlatan](https://github.com/bitcoin/bitcoin/pull/30657#issuecomment-2289173555) | | Approach ACK | [tdb3](https://github.com/bitcoin/bitcoin/pull/30657#pullrequestreview-2239353746) | If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
TheCharlatan commented 2024-08-14 15:53:36 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
tdb3 (Migrated from github.com) reviewed 2024-08-15 01:15:49 +00:00
tdb3 (Migrated from github.com) left a comment

Approach ACK.
Nice additions.
Left a comment and a nit.

Approach ACK. Nice additions. Left a comment and a nit.
tdb3 (Migrated from github.com) commented 2024-08-15 01:14:10 +00:00

The help for -blocksxor mentions The created XOR-key will be zeros for an existing blocksdir or when -blocksxor=0 is set.

After the verifychain, could test that a new xor.dat is created (consisting of all zeros) when the node is started with no xor.dat and with -blocksxor=0. Something like:

assert read_xor_key(node=node) == bytes(8)

or maybe lift NUM_XOR_BYTES out of read_xor_key to enable

assert read_xor_key(node=node) == bytes(NUM_XOR_BYTES)

or even add a constant in util.py

NULL_BLK_XOR_KEY = bytes(NUM_XOR_BYTES) # all-0 xor key

to enable

assert read_xor_key(node=node) == NULL_BLK_XOR_KEY
The help for `-blocksxor` mentions `The created XOR-key will be zeros for an existing blocksdir or when `-blocksxor=0` is set`. After the `verifychain`, could test that a new `xor.dat` is created (consisting of all zeros) when the node is started with no `xor.dat` and with `-blocksxor=0`. Something like: ```python assert read_xor_key(node=node) == bytes(8) ``` or maybe lift `NUM_XOR_BYTES` out of `read_xor_key` to enable ```python assert read_xor_key(node=node) == bytes(NUM_XOR_BYTES) ``` or even add a constant in `util.py` ```python NULL_BLK_XOR_KEY = bytes(NUM_XOR_BYTES) # all-0 xor key ``` to enable ```python assert read_xor_key(node=node) == NULL_BLK_XOR_KEY ```
tdb3 (Migrated from github.com) commented 2024-08-15 00:09:03 +00:00

nitty nit: Since this is being moved, could update to use a more descriptive function name (e.g. xor_bytes). Feel free to ignore.

nitty nit: Since this is being moved, could update to use a more descriptive function name (e.g. `xor_bytes`). Feel free to ignore.
maflcko (Migrated from github.com) approved these changes 2024-08-15 05:53:51 +00:00
maflcko (Migrated from github.com) left a comment
ACK faa1b9b0e6de7d213699fbdbc2e25a2a81c35cdc
maflcko (Migrated from github.com) commented 2024-08-15 05:49:13 +00:00

nit: 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?

nit: 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?
glozow (Migrated from github.com) reviewed 2024-08-15 11:48:20 +00:00
glozow (Migrated from github.com) commented 2024-08-15 11:48:19 +00:00

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?

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?
maflcko (Migrated from github.com) reviewed 2024-08-15 12:38:05 +00:00
maflcko (Migrated from github.com) commented 2024-08-15 12:38:05 +00:00

Maybe a leftover previous bitcoind was used? Can you try make clean, just to double check? Otherwise, the combined log could be useful.

Maybe a leftover previous `bitcoind` was used? Can you try `make clean`, just to double check? Otherwise, the combined log could be useful.
ismaelsadeeq (Migrated from github.com) approved these changes 2024-08-15 13:10:28 +00:00
ismaelsadeeq (Migrated from github.com) left a comment

Tested ACK faa1b9b0e6

Tested ACK faa1b9b0e6de7d213699fbdbc2e25a2a81c35cdc
glozow (Migrated from github.com) reviewed 2024-08-15 16:53:39 +00:00
glozow (Migrated from github.com) commented 2024-08-15 16:53:39 +00:00

I added a if (opts.use_xor) assert(xor_key != decltype(xor_key){}); which hit, so not an old bitcoind. Attaching combined log.

 node0 2024-08-15T16:40:41.093882Z [init] [node/blockstorage.cpp:1184] [InitBlocksdirXorKey] Using obfuscation key for blocksdir *.dat files (/tmp/bitcoin_func_test__c38k83u/node0/regtest/blocks): '0000000000000000' 

logs_30657.txt

I added a `if (opts.use_xor) assert(xor_key != decltype(xor_key){});` which hit, so not an old bitcoind. Attaching combined log. ``` node0 2024-08-15T16:40:41.093882Z [init] [node/blockstorage.cpp:1184] [InitBlocksdirXorKey] Using obfuscation key for blocksdir *.dat files (/tmp/bitcoin_func_test__c38k83u/node0/regtest/blocks): '0000000000000000' ``` [logs_30657.txt](https://github.com/user-attachments/files/16627687/logs_30657.txt)
maflcko (Migrated from github.com) reviewed 2024-08-15 17:02:08 +00:00
maflcko (Migrated from github.com) commented 2024-08-15 17:02:08 +00:00

I added a if (opts.use_xor) assert(xor_key != decltype(xor_key){}); which hit, so not an old bitcoind. Attaching combined log.

Can you also print/log/debug the result of fs::is_empty(opts.blocks_dir) and fs::exists(xor_key_path)?

> I added a `if (opts.use_xor) assert(xor_key != decltype(xor_key){});` which hit, so not an old bitcoind. Attaching combined log. Can you also print/log/debug the result of `fs::is_empty(opts.blocks_dir)` and `fs::exists(xor_key_path)`?
glozow (Migrated from github.com) reviewed 2024-08-15 17:22:34 +00:00
glozow (Migrated from github.com) commented 2024-08-15 17:22:34 +00:00

logs_30657_2.txt

Ah interesting, fs::is_empty(opts.blocks_dir) is 0

^so clearly this isn't a problem with the test

[logs_30657_2.txt](https://github.com/user-attachments/files/16627939/logs_30657_2.txt) Ah interesting, `fs::is_empty(opts.blocks_dir)` is 0 ^so clearly this isn't a problem with the test
maflcko (Migrated from github.com) reviewed 2024-08-15 17:32:04 +00:00
maflcko (Migrated from github.com) commented 2024-08-15 17:32:04 +00:00

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?)

mkdir no_ramdisk_temp_prefix
./test/functional/test_runner.py --tmpdirprefix ./no_ramdisk_temp_prefix/ feature_blocksxor
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?) ``` mkdir no_ramdisk_temp_prefix ./test/functional/test_runner.py --tmpdirprefix ./no_ramdisk_temp_prefix/ feature_blocksxor
maflcko (Migrated from github.com) reviewed 2024-08-15 17:35:39 +00:00
maflcko (Migrated from github.com) commented 2024-08-15 17:35:39 +00:00

Also, what is ls --all /tmp/bitcoin_func_test_fj812gkv/node0/regtest/blocks

Also, what is `ls --all /tmp/bitcoin_func_test_fj812gkv/node0/regtest/blocks`
maflcko (Migrated from github.com) reviewed 2024-08-15 17:37:59 +00:00
maflcko (Migrated from github.com) commented 2024-08-15 17:37:59 +00:00
Is it Apple https://en.wikipedia.org/wiki/.DS_Store ?
glozow (Migrated from github.com) reviewed 2024-08-15 17:52:52 +00:00
glozow (Migrated from github.com) commented 2024-08-15 17:52:52 +00:00

It's jammy with clang 17, indeed it works with a non-/tmp folder. Nothing out of place in ls. Hmmm

It's jammy with clang 17, indeed it works with a non-`/tmp` folder. Nothing out of place in `ls`. Hmmm
maflcko (Migrated from github.com) reviewed 2024-08-15 18:21:31 +00:00
maflcko (Migrated from github.com) commented 2024-08-15 18:21:31 +00:00

Jammy 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)
  • Try with CC=gcc CXX=g++ ./configure (using the libstdc++-11)
  • Try with CC=clang-17 CXX='clang++-17 -stdlib=libc++-17' ./configure (using libc++-17)
  • Try turning it off and on again (To kill any processes that may make /tmp/ dirty)?
Jammy 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) * Try with `CC=gcc CXX=g++ ./configure` (using the libstdc++-11) * Try with `CC=clang-17 CXX='clang++-17 -stdlib=libc++-17' ./configure` (using libc++-17) * Try turning it off and on again (To kill any processes that may make `/tmp/` dirty)?
glozow (Migrated from github.com) reviewed 2024-08-16 08:55:20 +00:00
glozow (Migrated from github.com) commented 2024-08-16 08:55:20 +00:00
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  468G  110G  335G  25% /

It worked with gcc. ./configure didn't like libc++-17. After reboot I can't get it to fail anymore (also I don't mean to hold up this PR)

``` Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p2 468G 110G 335G 25% / ``` It worked with gcc. `./configure` didn't like libc++-17. After reboot I can't get it to fail anymore (also I don't mean to hold up this PR)
glozow commented 2024-08-16 08:56:29 +00:00 (Migrated from github.com)
ACK faa1b9b0e6d
maflcko (Migrated from github.com) reviewed 2024-08-16 09:08:24 +00:00
maflcko (Migrated from github.com) commented 2024-08-16 09:08:24 +00:00

After reboot I can't get it to fail anymore (also I don't mean to hold up this PR)

Thanks 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 with ls --all on 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:

  • Start the test, but pause Bitcoin Core once the blocksdir is created (empty)
  • Run Apple Finder on the blocksdir to check if a file will be created
  • Continue the test and see it fail (if a file was created), or pass (otherwise)
> After reboot I can't get it to fail anymore (also I don't mean to hold up this PR) Thanks 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 with `ls --all` on 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: * Start the test, but pause Bitcoin Core once the blocksdir is created (empty) * Run Apple Finder on the blocksdir to check if a file will be created * Continue the test and see it fail (if a file was created), or pass (otherwise)
glozow (Migrated from github.com) reviewed 2024-08-16 14:26:19 +00:00
glozow (Migrated from github.com) commented 2024-08-16 14:26:19 +00:00

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

Starting at macOS 10.12 16A238m, Finder will not display .DS_Store files (even with com.apple.finder AppleShowAllFiles YES set).

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 > Starting at [macOS 10.12](https://en.wikipedia.org/wiki/MacOS_10.12) 16A238m, Finder will not display .DS_Store files (even with com.apple.finder AppleShowAllFiles YES set).
maflcko (Migrated from github.com) reviewed 2024-08-16 14:45:31 +00:00
maflcko (Migrated from github.com) commented 2024-08-16 14:45:31 +00:00

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).

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).
maflcko (Migrated from github.com) reviewed 2024-08-16 14:50:41 +00:00
maflcko (Migrated from github.com) commented 2024-08-16 14:50:41 +00:00

I guess fs::is_empty(opts.blocks_dir) could be replaced by not fs::exists("blk0000.dat")?

I guess `fs::is_empty(opts.blocks_dir)` could be replaced by `not fs::exists("blk0000.dat")`?
glozow (Migrated from github.com) reviewed 2024-08-16 15:23:40 +00:00
glozow (Migrated from github.com) commented 2024-08-16 15:23:40 +00:00

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.

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.
theStack (Migrated from github.com) reviewed 2024-08-20 13:52:55 +00:00
theStack (Migrated from github.com) commented 2024-08-20 13:52:55 +00:00

nit: 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?

No strong reason. Personally I first look into util.py for helpers and tend to forget that there are also some implemented as TestNode methods, but I agree that the latter makes sense. Could be picked up in a follow-up, e.g. #30669.

> nit: 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? No strong reason. Personally I first look into util.py for helpers and tend to forget that there are also some implemented as `TestNode` methods, but I agree that the latter makes sense. Could be picked up in a follow-up, e.g. #30669.
fjahr (Migrated from github.com) reviewed 2024-09-08 11:18:50 +00:00
fjahr (Migrated from github.com) commented 2024-09-08 11:18:50 +00:00

Found this here because I saw #30833 and it got me to look into blocksxor for 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@ef00b8eab4 I 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.

Found this here because I saw #30833 and it got me to look into `blocksxor` for 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: https://github.com/fjahr/bitcoin/commit/ef00b8eab48cf7ebcc8a0539f237175b8f5a0373 I 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.
maflcko (Migrated from github.com) reviewed 2024-09-09 06:34:01 +00:00
maflcko (Migrated from github.com) commented 2024-09-09 06:34:01 +00:00

made the test robust for me: fjahr@ef00b8e

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.

> made the test robust for me: [fjahr@ef00b8e](https://github.com/fjahr/bitcoin/commit/ef00b8eab48cf7ebcc8a0539f237175b8f5a0373) 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.
fjahr (Migrated from github.com) reviewed 2024-09-15 16:20:43 +00:00
fjahr (Migrated from github.com) commented 2024-09-15 16:20:43 +00:00

I guess fs::is_empty(opts.blocks_dir) could be replaced by not fs::exists("blk0000.dat")?

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.

> I guess fs::is_empty(opts.blocks_dir) could be replaced by not fs::exists("blk0000.dat")? 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.
This discussion has been locked. Commenting is limited to contributors.
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!30657
No description provided.