test: [refactor] Simplify submit_block_catch_error
What changed, and why it matters
This is a test-only code cleanup. It changes how a Bitcoin Core functional test catches errors when submitting blocks to a test node that is intentionally being crashed. The test now catches any generic exception instead of a specific list of network/process errors, and relies on a separate helper to confirm the node actually crashed. It does not touch the live Bitcoin network code, consensus rules, or wallet handling.
No security action needed. This is a benign test refactor. Reviewers may optionally verify that wait_for_node_exit() is indeed called on every False return path, which the diff confirms.
Security signals we found
No strong security signals were identified.
Evidence from the diff
Commit fa09de8b refactors submit_block_catch_error in test/functional/feature_dbcrash.py. Previously the helper caught only http.client.CannotSendRequest, http.client.RemoteDisconnected, subprocess.CalledProcessError, and specific OSError errno values (EPIPE, ECONNREFUSED, ECONNRESET), re-raising any other OSError. The refactor replaces that narrow exception list with a bare except Exception, logs the exception, returns False, and lets the caller’s wait_for_node_exit() enforce that bitcoind actually crashed. Imports for errno, http.client, and subprocess are removed. The commit message explicitly states this is a refactor that does not change behavior.
Changed components
test/functional/feature_dbcrash.pyInspect captured patch +4 / −16
diff --git a/test/functional/feature_dbcrash.py b/test/functional/feature_dbcrash.py
index 98aabb8d..b5b2f4e6 100755
--- a/test/functional/feature_dbcrash.py
+++ b/test/functional/feature_dbcrash.py
@@ -25,10 +25,7 @@
- restart until recovery succeeds
- check that utxo matches node3 using gettxoutsetinfo"""
-import errno
-import http.client
import random
-import subprocess
import time
from test_framework.blocktools import COINBASE_MATURITY
@@ -90,7 +87,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
except Exception:
# An exception here should mean the node is about to crash.
# If bitcoind exits, then try again. wait_for_node_exit()
- # should raise an exception if bitcoind doesn't exit.
+ # enforces that bitcoind crashed.
self.wait_for_node_exit(node_index, timeout=10)
self.crashed_on_restart += 1
@@ -105,25 +102,15 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
"""Try submitting a block to the given node.
Catch any exceptions that indicate the node has crashed.
+ The caller will check that a crash happened.
Returns true if the block was submitted successfully; false otherwise."""
try:
self.nodes[node_index].submitblock(block)
return True
- except (http.client.CannotSendRequest, http.client.RemoteDisconnected) as e:
+ except Exception as e:
self.log.debug(f"node {node_index} submitblock raised exception: {e}")
return False
- except subprocess.CalledProcessError as e:
- self.log.debug(f"node {node_index} submitblock raised CalledProcessError: {e}")
- return False
- except OSError as e:
- self.log.debug(f"node {node_index} submitblock raised OSError exception: errno={e.errno}")
- if e.errno in [errno.EPIPE, errno.ECONNREFUSED, errno.ECONNRESET]:
- # The node has likely crashed
- return False
- else:
- # Unexpected exception, raise
- raise
def sync_node3blocks(self, block_hashes):
"""Use submitblock to sync node3's chain with the other nodes
@@ -149,6 +136,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
if not self.submit_block_catch_error(i, block):
# TODO: more carefully check that the crash is due to -dbcrashratio
# (change the exit code perhaps, and check that here?)
+ # wait_for_node_exit() enforces that bitcoind crashed.
self.wait_for_node_exit(i, timeout=30)
self.log.debug(f"Restarting node {i} after block hash {block_hash}")
nodei_utxo_hash = self.restart_node(i, block_hash)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.