Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitcoind: support v28.0's new default "blk*.dat" xor'ing #130

Open
wants to merge 2 commits into
base: new-index
Choose a base branch
from

Conversation

phlip9
Copy link

@phlip9 phlip9 commented Nov 15, 2024

bitcoind v28.0 added a new "feature" that, by default, xors all "blk*.dat" files on-disk with a random 8-byte key, saved to "xor.dat" on-disk. See: bitcoin/bitcoin#28052.

This diff adds support by first (1) reading the "xor.dat" key and then (2) xor'ing all "blk*.dat" files with it as we read them. If there is no "xor.dat" (old bitcoind version or disabled with the "-blocksxor=0" flag), then we don't do any xor'ing.

Compiling with latest stable also revealed that the "oldcpu" feature doesn't exist anymore, so I also removed those dead #[cfg(feature = "oldcpu")] blocks.

You can easily test against v28.0 if you have nix installed:

$ nix build -L github:NixOS/nixpkgs/nixos-unstable#bitcoind
$ readlink result
/nix/store/33cbyzrgi9f2s7v4rakn5yfsscqxr59x-bitcoind-28.0

$ BITCOIND_SKIP_DOWNLOAD=1 \
    BITCOIND_EXE=/nix/store/33cbyzrgi9f2s7v4rakn5yfsscqxr59x-bitcoind-28.0/bin/bitcoind \
    cargo test -- --nocapture

Running test_electrum without this patch:

$ BITCOIND_SKIP_DOWNLOAD=1 \
    BITCOIND_EXE=/nix/store/33cbyzrgi9f2s7v4rakn5yfsscqxr59x-bitcoind-28.0/bin/bitcoind \
    cargo test --test electrum -- --nocapture

   Compiling electrs v0.4.1 (/home/phlip9/dev/blockstream-electrs)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 13.77s
     Running tests/electrum.rs (target/debug/deps/electrum-0f37414ffe1e8f36)

running 1 test
thread 'blkfiles_fetcher' panicked at src/new_index/fetch.rs:146:17:
failed to index 102 blocks from blk*.dat files
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'test_electrum' panicked at src/new_index/fetch.rs:66:28:
fetcher thread panicked: Any { .. }
test test_electrum ... FAILED

failures:

failures:
    test_electrum

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 5.36s

error: test failed, to rerun pass `--test electrum`

@phlip9
Copy link
Author

phlip9 commented Nov 15, 2024

cc @shesek @RCasatta

Copy link
Collaborator

@RCasatta RCasatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c7f7595 code review and testing with bitcoin 27.1.0 and 28.0, 28.0 fails without this as expected

Great to see nix commands to test, very handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants