aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-08-26 14:30:07 -0400
committerAva Chow <github@achow101.com>2024-08-26 14:30:07 -0400
commitd50f0ce248a32a373fb22ade33e565d234ddc335 (patch)
tree1f5934c935da07bccd7af1939933d653f5aeb167
parent6d546336e800f7b8990fececab6bc08413f28690 (diff)
parente1d5dd732d5dc641faf1dde316275c84b6bb224b (diff)
Merge bitcoin/bitcoin#30669: test: XORed blocks test follow up
e1d5dd732d5dc641faf1dde316275c84b6bb224b test: check xor.dat recreated when missing (tdb3) d1610962bf1ff14df45c57cc1d2e075f71fcd19a test: add null block xor key (tdb3) 1ad999b9da39b60e16c51f9813f4fd39b7bdc2b9 refactor: lift NUM_XOR_BYTES (tdb3) d8399584dd59b3954a0bea393b2de350a732055e refactor: move read_xor_key() to TestNode (tdb3) d43948c3ef610c383176bf9b389697973bd0ad64 refactor: use unlink rather than os.remove (tdb3) c8176f758b5991c3797c32ee519d32c14b444991 test: add blocks_key_path (tdb3) Pull request description: Builds on PR #30657. Refactors `read_xor_key()` from `util.py` to `test_node.py` (comment https://github.com/bitcoin/bitcoin/pull/30657#discussion_r1723358327) Adds a check that `xor.dat` is created when missing (comment https://github.com/bitcoin/bitcoin/pull/30657#discussion_r1717724161) Help states: ``` -blocksxor Whether an XOR-key applies to blocksdir *.dat files. The created XOR-key will be zeros for an existing blocksdir or when `-blocksxor=0` is set, and random for a freshly initialized blocksdir. (default: 1) ``` ACKs for top commit: maflcko: ACK e1d5dd732d5dc641faf1dde316275c84b6bb224b achow101: ACK e1d5dd732d5dc641faf1dde316275c84b6bb224b theStack: re-ACK e1d5dd732d5dc641faf1dde316275c84b6bb224b brunoerg: reACK e1d5dd732d5dc641faf1dde316275c84b6bb224b Tree-SHA512: 325912ef646ec88e0a58e1ece263a2b04cbc06497e8fe5fcd603e509e80c6bcf84b09dd52dfac60e23013f07fc2b2f6db851ed0598649c3593f452c4a1424bd9
-rwxr-xr-xtest/functional/feature_blocksxor.py13
-rwxr-xr-xtest/functional/feature_reindex.py3
-rwxr-xr-xtest/functional/test_framework/test_node.py13
-rw-r--r--test/functional/test_framework/util.py6
4 files changed, 22 insertions, 13 deletions
diff --git a/test/functional/feature_blocksxor.py b/test/functional/feature_blocksxor.py
index 88e0244cd4..7698a66ec4 100755
--- a/test/functional/feature_blocksxor.py
+++ b/test/functional/feature_blocksxor.py
@@ -3,14 +3,15 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test support for XORed block data and undo files (`-blocksxor` option)."""
-import os
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.test_node import ErrorMatch
+from test_framework.test_node import (
+ ErrorMatch,
+ NULL_BLK_XOR_KEY,
+)
from test_framework.util import (
assert_equal,
assert_greater_than,
- read_xor_key,
util_xor,
)
from test_framework.wallet import MiniWallet
@@ -40,7 +41,7 @@ class BlocksXORTest(BitcoinTestFramework):
self.log.info("Shut down node and un-XOR block/undo files manually")
self.stop_node(0)
- xor_key = read_xor_key(node=node)
+ xor_key = node.read_xor_key()
for data_file in sorted(block_files + undo_files):
self.log.debug(f"Rewriting file {data_file}...")
with open(data_file, 'rb+') as f:
@@ -54,11 +55,13 @@ class BlocksXORTest(BitcoinTestFramework):
match=ErrorMatch.PARTIAL_REGEX)
self.log.info("Delete XOR key, restart node with '-blocksxor=0', check blk*.dat/rev*.dat file integrity")
- os.remove(node.blocks_path / 'xor.dat')
+ node.blocks_key_path.unlink()
self.start_node(0, extra_args=['-blocksxor=0'])
# checklevel=2 -> verify block validity + undo data
# nblocks=0 -> verify all blocks
node.verifychain(checklevel=2, nblocks=0)
+ self.log.info("Check that blocks XOR key is recreated")
+ assert_equal(node.read_xor_key(), NULL_BLK_XOR_KEY)
if __name__ == '__main__':
diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py
index 2961a2d356..1ebfe82da5 100755
--- a/test/functional/feature_reindex.py
+++ b/test/functional/feature_reindex.py
@@ -14,7 +14,6 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.messages import MAGIC_BYTES
from test_framework.util import (
assert_equal,
- read_xor_key,
util_xor,
)
@@ -43,7 +42,7 @@ class ReindexTest(BitcoinTestFramework):
# we're generating them rather than getting them from peers), so to
# test out-of-order handling, swap blocks 1 and 2 on disk.
blk0 = self.nodes[0].blocks_path / "blk00000.dat"
- xor_dat = read_xor_key(node=self.nodes[0])
+ xor_dat = self.nodes[0].read_xor_key()
with open(blk0, 'r+b') as bf:
# Read at least the first few blocks (including genesis)
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index b73566b0e9..60ca9269a5 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -43,6 +43,11 @@ from .util import (
)
BITCOIND_PROC_WAIT_TIMEOUT = 60
+# The size of the blocks xor key
+# from InitBlocksdirXorKey::xor_key.size()
+NUM_XOR_BYTES = 8
+# The null blocks key (all 0s)
+NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
class FailedToStartError(Exception):
@@ -466,6 +471,14 @@ class TestNode():
return self.chain_path / "blocks"
@property
+ def blocks_key_path(self) -> Path:
+ return self.blocks_path / "xor.dat"
+
+ def read_xor_key(self) -> bytes:
+ with open(self.blocks_key_path, "rb") as xor_f:
+ return xor_f.read(NUM_XOR_BYTES)
+
+ @property
def wallets_path(self) -> Path:
return self.chain_path / "wallets"
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index c3bc861cf6..00fe5b08e4 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -515,12 +515,6 @@ def check_node_connections(*, node, num_in, num_out):
assert_equal(info["connections_out"], num_out)
-def read_xor_key(*, node):
- with open(node.blocks_path / "xor.dat", "rb") as xor_f:
- NUM_XOR_BYTES = 8 # From InitBlocksdirXorKey::xor_key.size()
- return xor_f.read(NUM_XOR_BYTES)
-
-
# Transaction/Block functions
#############################