Welcome! This exercise is about restarting nodes with startup arguments and checking logs.
This exercise teaches you how to check node logs. While running, Bitcoin Core prints various logs, and checking them helps confirm whether the code path you expect is actually being executed.
The test framework node class TestNode provides the function assert_debug_log(expected_msgs=[], unexpected_msgs=[]), which checks whether certain strings are present or absent in node logs.
We usually pair assert_debug_log(...) with a Python with block. The with block means "apply this helper only to the indented code block."
So with assert_debug_log(...), the flow is:
- Start watching logs.
- Run the action inside the block.
- When the block ends, verify that expected messages were seen.
You will see this with + assert_debug_log pattern often in functional tests:
# Make sure that 'Hello world' is in the debug log
with self.nodes[0].assert_debug_log(["Hello world"]):
# action that should produce the log message
# ...
# Make sure that 'I like donuts' is not in the debug log
with self.nodes[0].assert_debug_log([], unexpected_msgs=["I like donuts"]):
# action that shouldn't produce the log message
# ...In this exercise, you will restart the node with specific startup flags and check whether specific log messages are emitted.
You will use prune mode, which means the node will not keep the entire blockchain on disk, only the last N MiB (configured by the user).
When prune mode is enabled, the Bitcoin Core node will log:
Prune configured to target <N> MiB on disk for block and undo files.
You can also check whether prune mode is enabled through getblockchaininfo(), where info["pruned"] is set to True.
To restart a node, use self.restart_node. The method takes the index of the node to restart and a list of extra args to pass on restart. For example, to restart node 0 (self.nodes[0]) with the startup argument -txindex:
self.restart_node(0, extra_args=["-txindex"])
Create a functional test that:
- Uses one node.
- Restarts with default args.
- Asserts that debug logs do not show prune mode configuration.
- Asserts that pruning is not enabled through RPC.
- Restarts with pruning enabled (for example,
-prune=550). - Asserts debug logs show prune mode configuration.
- Asserts pruning is enabled through RPC.
Suggested filename in b4os-bitcoin/:
test/functional/feature_prune_debug_log.py
Do not forget to add the test to test/functional/test_runner.py.
Small hint
Set `self.num_nodes = 1`.Small hint
Use restart_node with extra_args=[""]. This restarts the node without any additional configuration.
Small hint
You will need to wrap the restart call with with assert_debug_log():.
Small hint
Make sure the node did not print pruning logs on restart.Big hint
with self.nodes[0].assert_debug_log([], unexpected_msgs=['Prune configured to target']):
Small hint
Call `getblockchaininfo` and assert `pruned` is `False`.Same hints as steps 2, 3, and 4 :)
Continue with 03-easy-miniwallet-support.md.