WIP: RFC: netbase: Remove manual_connection and return the failure reason to callers #36970

Draft
fjahr wants to merge 3 commits from 2026-11-i2p-proxy-log-nomanual into master AGit
fjahr commented 2026-11-24 19:47:56 +00:00 (Migrated from github.com)

Based on #36969, only the last commit is new. Draft to see if this direction is wanted. This also came out of discussions in #36759:

The manual_connection flag of ConnectDirectly() only picks the log level of a failed connect(). Callers that are not manual peers, like Tor control, pass true just to get the failure logged, and the caller that knows how much a failure matters never sees the reason.

This removes the flag. ConnectDirectly() returns the failure reason and each caller decides how to log it. The log output stays the same, except that manual peers and Tor control now log every failure reason at info level, including timeouts, which were debug only.

Based on #36969, only the last commit is new. Draft to see if this direction is wanted. This also came out of discussions in #36759: The `manual_connection` flag of `ConnectDirectly()` only picks the log level of a failed `connect()`. Callers that are not manual peers, like Tor control, pass `true` just to get the failure logged, and the caller that knows how much a failure matters never sees the reason. This removes the flag. `ConnectDirectly()` returns the failure reason and each caller decides how to log it. The log output stays the same, except that manual peers and Tor control now log every failure reason at info level, including timeouts, which were debug only.
DrahtBot commented 2026-11-24 19:48:06 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36904 (log: Remove trailing and embedded newlines from log messages by maflcko)
  • #36880 (init: Fix surprising behaviors of negated options by fjahr)
  • #36759 (torcontrol: Improve connection logging by ViniciusCestarii)
  • #36257 (qa: assert_equal -> assert_true/assert_false by hodlinator)
  • #35027 (net: add -outboundbind option for outgoing source address by 8144225309)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36970 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36970.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36970#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36904](https://github.com/bitcoin/bitcoin/pull/36904) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36904.svg"></sub> (log: Remove trailing and embedded newlines from log messages by maflcko) * [#36880](https://github.com/bitcoin/bitcoin/pull/36880) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36880.svg"></sub> (init: Fix surprising behaviors of negated options by fjahr) * [#36759](https://github.com/bitcoin/bitcoin/pull/36759) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36759.svg"></sub> (torcontrol: Improve connection logging by ViniciusCestarii) * [#36257](https://github.com/bitcoin/bitcoin/pull/36257) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equal -> assert_true/assert_false by hodlinator) * [#35027](https://github.com/bitcoin/bitcoin/pull/35027) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35027.svg"></sub> (net: add -outboundbind option for outgoing source address by 8144225309) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
DrahtBot commented 2026-11-24 20:58:44 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/45474031569/job/138729326085
LLM reason (✨ experimental): CI failed because IWYU added a missing #include <util/expected.h> to src/net.cpp, leaving an uncommitted diff that the check rejects.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/45474031569/job/138729326085</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU added a missing `#include <util/expected.h>` to `src/net.cpp`, leaving an uncommitted diff that the check rejects.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
First-time contributor

🟠 Minor · Proxy warnings omit the connection failure reason

The prerequisite logging change makes refused proxy connections and missing Unix socket paths produce endpoint-only warnings; their causes require -debug=net, not -debug=proxy or -debug=i2p.

Location: src/netbase.cpp:668 (head).

🔵 Suggestion · One proxy's failure suppresses connection warnings for other endpoints

With separately configured proxies, the first endpoint's failure consumes the warning for every endpoint, so a later refusal from another proxy receives only the categorized debug diagnostic.

Location: src/netbase.cpp:799 (head).

🔵 Suggestion · The I2P test does not reliably check repeated Couldn't listen warnings

The second assertion requires a repeated Hello failure but not a repeated Listen failure, so it catches an unconditional Listen warning only if a background retry happens during the addnode interval.

Location: test/functional/p2p_i2p_ports.py:41 (head).

🔵 Suggestion · The returned getsockopt() failure reason omits the OS error

On the rare getsockopt(SO_ERROR) failure path, the new returned reason omits the OS error even though the existing warn-then-debug diagnostic retains it.

Location: src/netbase.cpp:614 (head).

Review coverage was incomplete.


Reviewed: a2e24607f8bb · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:806938d40e279b6d701b2e78128bb1a09b55193a0b697245a1dce6241d3081c1:3607c760b63c01fb7f1f349adfc3fd0614b148a7df02e42f2f0edc2d448925a1 --> <!-- ralph-base:5ba05739881855cba25c3c05d6f82a61b8a0665f --> <!-- ralph-head:a2e24607f8bb24360922a2a43696a6f948e14681 --> <!-- ralph-case:ac2e152c501000684bb326b6418b5a4f62e9497604f7f70f69cc121bc1f510a4 --> **🟠 Minor · Proxy warnings omit the connection failure reason** The prerequisite logging change makes refused proxy connections and missing Unix socket paths produce endpoint-only warnings; their causes require `-debug=net`, not `-debug=proxy` or `-debug=i2p`. Location: [`src/netbase.cpp:668`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/a2e24607f8bb24360922a2a43696a6f948e14681/src/netbase.cpp#L668>) (head). **🔵 Suggestion · One proxy's failure suppresses connection warnings for other endpoints** With separately configured proxies, the first endpoint's failure consumes the warning for every endpoint, so a later refusal from another proxy receives only the categorized debug diagnostic. Location: [`src/netbase.cpp:799`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/a2e24607f8bb24360922a2a43696a6f948e14681/src/netbase.cpp#L799>) (head). **🔵 Suggestion · The I2P test does not reliably check repeated `Couldn't listen` warnings** The second assertion requires a repeated `Hello` failure but not a repeated `Listen` failure, so it catches an unconditional `Listen` warning only if a background retry happens during the `addnode` interval. Location: [`test/functional/p2p_i2p_ports.py:41`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/a2e24607f8bb24360922a2a43696a6f948e14681/test/functional/p2p_i2p_ports.py#L41>) (head). **🔵 Suggestion · The returned `getsockopt()` failure reason omits the OS error** On the rare `getsockopt(SO_ERROR)` failure path, the new returned reason omits the OS error even though the existing warn-then-debug diagnostic retains it. Location: [`src/netbase.cpp:614`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/a2e24607f8bb24360922a2a43696a6f948e14681/src/netbase.cpp#L614>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`a2e24607f8bb`](<https://git.fish.foo/bitcoin/bitcoin/commit/a2e24607f8bb24360922a2a43696a6f948e14681>) · [Review report](<https://review.fish.foo/report/36970-a2e24607f8bb24360922a2a43696a6f948e14681-3122-2.html>) · [Previous reports](<https://review.fish.foo/traces/36970/>) [permalink](<https://review.fish.foo/report/36970-a2e24607f8bb24360922a2a43696a6f948e14681-3122-2.html>)
DrahtBot commented 2026-12-02 15:50:57 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36970
No description provided.