5 minor findings · 4 suggestions
Findings
[minor] · bitcoin-mine can shrink and append to the node's debug.log
Running bitcoin-mine against a node's datadir can discard older log history and add startup lines that look like a node restart.
Location: src/bitcoin-mine.cpp:101 (head).
Details and suggested fix
bitcoin-mine starts file logging to the default debug.log in the network datadir before connecting to the node. With no debug categories, shrinkdebugfile defaults to true. If the log exceeds about 11 MB, each run rewrites it with only the last 10 MB; node log lines written between the read and rewrite can also be lost. Each run appends a new-execution separator and startup and configuration lines. If the log cannot be opened, for example because bitcoin-mine runs as a different user, the client exits before connecting. Default to console-only logging, enable file logging only when -debuglogfile is explicitly set, and do not shrink the log.
[minor] · Null IPC connection results make bitcoin-mine abort
Values such as -noipcconnect, -ipcconnect=0, an empty value, or -ipcconnect=auto with no node running can make the client abort instead of reporting a connection error.
Location: src/bitcoin-mine.cpp:119 (head).
Details and suggested fix
connectAddress() returns nullptr for an empty address or "0", and also for "auto" when the socket is missing or refuses the connection. The catch block handles exceptions but not null returns, so these values reach assert(node_init) and abort the client with SIGABRT instead of printing the connection hint. bitcoin-cli handles the same null return explicitly. Check node_init and return EXIT_FAILURE with an error; apply the same check to mining, which can return nullptr if the node is interrupted while waiting for chainstate. No documented bitcoin-mine usage passes these values, so the trigger is explicit user input or shared configuration.
[minor] · Final tip comparison dereferences an empty optional
If bitcoin-mine connects before the node has a tip, it prints that the tip is null but later dereferences the empty optional, causing undefined behavior in the client.
Location: src/bitcoin-mine.cpp:159 (head).
Details and suggested fix
The initial getTip() result may be empty, which the client handles when printing the tip. This can happen on first startup with an empty datadir or with -reindex or -reindex-chainstate: IPC becomes available before the initload thread connects the tip, while makeMining() waits only for chainstate_loaded. createNewBlock() waits for a tip internally, so the client can continue and reach the final comparison with the original optional still empty. That dereference, and the unchecked dereferences of the later getTip() results, cause undefined behavior. The client may print an incorrect result or abort with a hardened standard library. Use the template's hashPrevBlock, or fetch a tip after createNewBlock(), as the baseline, and check each optional before dereferencing it.
[minor] · bitcoin-mine creates files without Bitcoin Core's private umask
bitcoin-mine skips SetupEnvironment() and opens the node's log path before connecting; a newly created log can therefore inherit a permissive umask and be readable by other users if its parent directory is traversable.
Location: src/bitcoin-mine.cpp:59 (head).
Details and suggested fix
Other standalone executables call SetupEnvironment(), which sets umask(0077) on non-Windows systems. bitcoin-mine does not, and opens <datadir>/<net>/debug.log before attempting the IPC connection. If the file does not exist, a direct invocation under a typical 0022 umask creates it with mode 0644, and the node later appends without changing that mode. Existing logs retain their mode; the default datadir is 0700, and the bitcoin wrapper passes its private umask through exec. Exposure therefore requires both a newly created log and a parent directory that other users can traverse. Call SetupEnvironment() at the start of main.
[minor] · StartLogging errors lose their specific message
When StartLogging fails, the user sees only a generic error because bitcoin-mine has no UI handler to print the specific log-file error.
Location: src/bitcoin-mine.cpp:101 (head).
Details and suggested fix
InitError forwards its message to uiInterface.ThreadSafeMessageBox, which does nothing when no handler is connected. bitcoind connects a handler with noui_connect(), but bitcoin-mine neither links noui.cpp nor connects its own handler. As a result, the specific "Could not open debug log file <path>" message is lost, and the user sees only "Error: StartLogging failed." Connect a minimal ThreadSafeMessageBox handler that prints to stderr, or move noui.cpp into the common library.
Optional improvements
[suggestion] · The functional test accepts a failed block submission
bitcoin-mine ignores submitSolution()'s result and exits successfully on failure, while the test accepts that output, so the test can pass without the node accepting a block.
Location: test/functional/feature_mine.py:28 (head).
Details and suggested fix
bitcoin-mine ignores the bool returned by submitSolution() and its reason and debug strings. It also submits unconditionally after the loop, including when -maxtries=0 or when CheckProofOfWork() never passed, and judges success only by whether the tip changed. A block arriving from elsewhere can also change the tip. The functional test accepts either "New block mined" or "Failed to mine a block," so a regression in the merkle root, coinbase, or submission path can leave it green. Submit only after CheckProofOfWork() passes, report reason and debug, and return nonzero when submitSolution() returns false. Require "New block mined" in the test and verify through RPC that the node's height advanced to 1.
[suggestion] · bitcoin-mine submits the template's dummy coinbase
Blocks are valid at this revision, but the reference client uses a dummy coinbase that the Mining interface says consumers must not use.
Location: src/bitcoin-mine.cpp:157 (head).
Details and suggested fix
BlockTemplate::getBlock() is documented to return a dummy coinbase that should not be used and may differ from one built with getCoinbaseTx(). BlockAssembler likewise says mining interface consumers must not use it, but bitcoin-mine submits block.vtx.at(0) directly. At this revision the transaction is complete and produces valid blocks, paying the full reward to the default OP_TRUE anyone-can-spend script. If the node later makes vtx[0] a real placeholder, as the interface permits, bitcoin-mine will stop producing valid blocks, and the current test will not detect the failure. Build the coinbase from getCoinbaseTx() using the script_sig_prefix plus at least one extra byte, the witness, an output for block_reward_remaining followed by required_outputs, and the sequence and lock_time. Then recompute the merkle root before the nonce loop.
[suggestion] · The generated bitcoin-mine man page is not installed
The release man-page script generates bitcoin-mine.1 for an internal test binary and adds bitcoin-mine(1) to every page's SEE ALSO section, although CMake does not install the page.
Location: contrib/devtools/gen-manpages.py:16 (head).
Details and suggested fix
Because bin/bitcoin-mine is in BINARIES, the script generates doc/man/bitcoin-mine.1 whenever the binary exists in the build directory, which is the default on Unix because ENABLE_IPC is on. It also adds bitcoin-mine(1) to every generated page's SEE ALSO section. CMake installs the target as INTERNAL and does not mark it HAS_MANPAGE, so the page is never installed. The other INTERNAL binaries, bitcoin-node and bitcoin-chainstate, are not listed. Remove bin/bitcoin-mine from BINARIES, or, if the binary is meant to be user-facing, mark it HAS_MANPAGE and commit the page.
[suggestion] · The test name conflicts with functional-test naming conventions
The feature_ prefix is intended for non-mining features, and the commit message names a different existing test.
Location: test/functional/feature_mine.py:5 (head).
Details and suggested fix
The functional-test README reserves feature_ for full features outside wallet, mining, and mempool, and tool_ for tests of tools. This test runs bitcoin-mine against an IPC-enabled node, so tool_mine.py or interface_ipc_mine.py would fit better. The commit message says it adds interface_ipc_mining.py, but the file it adds is feature_mine.py; interface_ipc_mining.py is an existing, unrelated pycapnp test. Rename the file, update its test_runner.py entry, and correct the commit message.