-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#27850: test: Add unit & functional test coverag…
…e for blockstore de8f912 test: cover read-only blockstore (Matthew Zipkin) 5c2185b ci: enable chattr +i capability inside containers (Matthew Zipkin) e573f24 unit test: add coverage for BlockManager (Matthew Zipkin) Pull request description: This PR adds unit and functional tests to cover the behavior described in #2039. In particular, that bitcoind will crash on startup if a reindex is requested but the `blk` files are read-only. Eventually this behavior can be updated with bitcoin/bitcoin#27039. This PR just commits the test coverage from #27039 as suggested in bitcoin/bitcoin#27039 (comment) ACKs for top commit: jonatack: ACK de8f912 modulo suggestions in bitcoin/bitcoin#27850 (comment), tested on macOS, but not on Linux for the Linux-related change in the last push achow101: ACK de8f912 MarcoFalke: lgtm ACK de8f912 📶 Tree-SHA512: b9bd684035dcea11c901b649fc39f397a2155a9a8459f3348e67947e387e45312fddeccb52981aef486f8a31deebb5356a7901c1bb94b78f82c24192a369af73
- Loading branch information
Showing
6 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2023-present The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
"""Test running bitcoind with -reindex from a read-only blockstore | ||
- Start a node, generate blocks, then restart with -reindex after setting blk files to read-only | ||
""" | ||
|
||
import platform | ||
import stat | ||
import subprocess | ||
from test_framework.test_framework import BitcoinTestFramework | ||
|
||
|
||
class BlockstoreReindexTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 1 | ||
self.extra_args = [["-fastprune"]] | ||
|
||
def reindex_readonly(self): | ||
self.log.debug("Generate block big enough to start second block file") | ||
fastprune_blockfile_size = 0x10000 | ||
opreturn = "6a" | ||
nulldata = fastprune_blockfile_size * "ff" | ||
self.generateblock(self.nodes[0], output=f"raw({opreturn}{nulldata})", transactions=[]) | ||
self.stop_node(0) | ||
|
||
assert (self.nodes[0].chain_path / "blocks" / "blk00000.dat").exists() | ||
assert (self.nodes[0].chain_path / "blocks" / "blk00001.dat").exists() | ||
|
||
self.log.debug("Make the first block file read-only") | ||
filename = self.nodes[0].chain_path / "blocks" / "blk00000.dat" | ||
filename.chmod(stat.S_IREAD) | ||
|
||
used_chattr = False | ||
if platform.system() == "Linux": | ||
try: | ||
subprocess.run(['chattr', '+i', filename], capture_output=True, check=True) | ||
used_chattr = True | ||
self.log.info("Made file immutable with chattr") | ||
except subprocess.CalledProcessError as e: | ||
self.log.warning(str(e)) | ||
if e.stdout: | ||
self.log.warning(f"stdout: {e.stdout}") | ||
if e.stderr: | ||
self.log.warning(f"stderr: {e.stderr}") | ||
|
||
self.log.debug("Attempt to restart and reindex the node with the unwritable block file") | ||
with self.nodes[0].assert_debug_log(expected_msgs=['FlushStateToDisk', 'failed to open file'], unexpected_msgs=[]): | ||
self.nodes[0].assert_start_raises_init_error(extra_args=['-reindex', '-fastprune'], | ||
expected_msg="Error: A fatal internal error occurred, see debug.log for details") | ||
|
||
if used_chattr: | ||
subprocess.check_call(['chattr', '-i', filename]) | ||
|
||
filename.chmod(0o777) | ||
|
||
def run_test(self): | ||
self.reindex_readonly() | ||
|
||
|
||
if __name__ == '__main__': | ||
BlockstoreReindexTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters