torcontrol: Improve connection logging

bitcoin/bitcoin: PR #36759

3 suggestions

Optional improvements

Link

[suggestion] · The description promises an initial info notice that is not emitted

The third description bullet promises an info notice for the first unconfigured Tor connection failure, but the implementation and header specify debug-only reporting.

Location: src/torcontrol.cpp:114 (head).

Details and suggested fix

With onion listening enabled and none of -listenonion, -torcontrol, or -torpassword set, an ordinary connection refusal produces only TOR and NET debug messages, including on the first attempt. ThreadControl() no longer adds a warning, and the new service-loss info message requires a previously created onion service. The header and second commit description indicate that this is intentional. Remove the third bullet from the PR description to match that behavior; retaining the promised notice would instead require a one-time info log and coverage.


Link

[suggestion] · Tor connection-error reasons now require NET debug logging

For ordinary connect errors, explicitly configured Tor now warns without the socket error reason, and the documented -debug=tor option cannot reveal it.

Location: src/torcontrol.cpp:109 (head).

Details and suggested fix

Passing manual_connection=false moves netbase's ordinary connect-error details, such as Connection refused, from info level to BCLog::NET debug. The replacement Tor warning contains only the endpoint, so diagnosing the failure requires enabling the broader -debug=net category. Wait failures and timeouts were already NET-debug-only; the diagnostic loss concerns the ordinary connect-error paths. Return the error text to TorControlConnection and include it in the existing Tor failure message. That preserves the reason in the first configured warning and subsequent TOR debug messages without restoring per-retry info lines.


Link

[suggestion] · The default Tor failure-logging branch lacks coverage

The new functional test only covers configured Tor, so changing the unconfigured failure back to LogWarning would leave its assertions passing.

Location: test/functional/feature_torcontrol.py:297 (head).

Details and suggested fix

test_connect_failure_warning sets both -torcontrol and -listenonion=1, so it never exercises tor_control_configured=false. Simply omitting those arguments is insufficient: the framework writes listenonion=0 into bitcoin.conf, which IsArgSet counts as configured. Add a deterministic unit test using BasicTestingSetup: save and restore CreateSock, override it to return null, and call Connect("127.0.0.1:9051", false) twice. Require the TOR debug message on both calls and reject its warning form.

The existing functional assertions also allow netbase's info-level connect() ... failed line. Reject that line there to guard against restoring manual_connection=true; the null-socket unit test returns before reaching the logging controlled by that flag.


Coverage details