torcontrol: Improve connection logging

bitcoin/bitcoin: PR #36759

2 suggestions

Optional improvements

Link

[suggestion] · Configured Tor failure reasons use debug logging despite the commit message

Commit bd9945c promises manual logging for explicitly configured Tor control, but manual_connection=false hides the socket failure reason unless network debug logging is enabled.

Location: src/torcontrol.cpp:109 at bd9945c1a565 (commit) (commit).

Details and suggested fix

In the final commit, bd9945c1a5656c7e39bad008951e6780e6654bd1, the message says configured Tor control is treated as manual, but ConnectDirectly receives /*manual_connection=*/false unconditionally. Consequently, LogConnectFailure uses LogDebug(BCLog::NET) even for configured nodes, rather than the info-level refusal reason emitted at base. The first Tor warning reports only the address. The new test's assertion for connect() to ... failed does not verify info-level visibility because the framework starts the node with -debug. Making socket failure reasons debug-only for all nodes may be intentional and avoids repeated info messages. If so, update the commit message to state that policy instead of promising manual logging for configured nodes.


Link

[suggestion] · The failure test misses both noise-reduction behaviors

The new functional test would still pass if retries warned repeatedly or unconfigured connection failures warned, leaving both noise-reduction behaviors unprotected.

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

Details and suggested fix

test_connect_failure_warning supplies both -torcontrol and -listenonion=1, and assert_debug_log checks only that the expected substrings appear. It neither counts warnings nor waits for another failed attempt, so replacing LogWarnThenDebug with LogWarning would leave these assertions passing. The unconfigured branch is also untested. The framework writes listenonion=0 into the node configuration, which still makes IsArgSet("-listenonion") true, so omitting command-line flags alone would not reach that branch. Extend the configured case through at least two completed failed attempts and assert exactly one warning followed by debug-level failures. Also exercise Connect(addr, /*tor_control_configured=*/false) against a closed port in a unit test and assert that it emits no warning.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Ralph's inferences

The generic logging policy favors a warning for an actionable systematic problem, followed by debug-only logging when the same problem is likely to recur frequently. This balances operator visibility against repetitive logging and storage consumption.

The pinned developer guidance describes precisely this purpose for LogWarnThenDebug. It also reserves warnings for problems administrators should address. These premises support warning once for an explicitly configured but unavailable Tor controller, although they do not independently settle whether recovery should reset suppression.

The helper selected at the PR head implements one warning per call site for the process lifetime, not one warning per outage. Successful connections do not reset its suppression state.

LogWarnThenDebug stores a static atomic boolean at its expansion site. The explicitly configured Tor-control failure branch uses that helper, and reconnect attempts return to the same Connect call. Consequently, after that site has warned once, a failed reconnect during a later outage is debug-only. This establishes the selected mechanism's semantics, not a historically documented Tor-specific policy.

The pinned base and head differ in both visibility and repetition: the base warns on every direct connection failure, while the head warns once at the failure call site only when Tor control was explicitly configured.

The base uses an unconditional LogWarning when ConnectDirectly fails. The head uses LogWarnThenDebug for explicitly configured Tor control and LogDebug otherwise. Repeated base warnings therefore establish prior behavior, but do not by themselves prove that a fresh warning for every later outage was an intentional historical requirement.