Skip to content

test: add functional test for outbound connection management - #33954

Open
mzumsande wants to merge 3 commits into
bitcoin:masterfrom
mzumsande:202511_test_outbound_mgmt
Open

mzumsande wants to merge 3 commits into
bitcoin:masterfrom
mzumsande:202511_test_outbound_mgmt

Conversation

@mzumsande

@mzumsande mzumsande commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

For #29415, vasild added the possibility to have outbound connections made "naturally" by the node using addrman entries, by redirecting them via a SOCKS5 proxy to python p2ps or other full nodes, so that the node under test behaves as if it is connected to normal non-local peers from arbitrary networks, while we have full control over the peers.

I think this feature is really cool and want to suggest to integrate it more prominently into the test framework ("auto_outbound_mode") in the first commit because it allows to test the code in which the node decides to make connections - in contrast to the existing add_outbound_p2p_connection where the functional test intiates the connections.

The second commit uses it to add functional test coverage for the following features of outbound connection management:

This should work well with the test from #29415 (which would keep its own destinations_factory but can call _create_auto_outbound_listener to avoid much of code duplication).

Other possible uses for auto_outbound_mode I could think of are more detailed testing of anchors (feature_anchors.py), feeler connections, or any other p2p logic that uses the network of peers.

@DrahtBot DrahtBot added the Tests label Nov 26, 2025
@DrahtBot

DrahtBot commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

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.

Type Reviewers
Concept ACK 0xB10C
Stale ACK vasild, Bortlesboat

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36434 (http: support unix sockets by pinheadmz)
  • #35888 (net: reject oversized outbound messages by l0rinc)

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.

@mzumsande
mzumsande force-pushed the 202511_test_outbound_mgmt branch from 8005a48 to 1158564 Compare November 26, 2025 19:11
@mzumsande
mzumsande marked this pull request as ready for review November 26, 2025 20:14
@vasild

vasild commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Concept ACK, thanks!

@mzumsande
mzumsande marked this pull request as draft November 28, 2025 22:07
@mzumsande

Copy link
Copy Markdown
Contributor Author

there are still some intermittent timeouts, will put in draft until I've fixed them.

@mzumsande
mzumsande force-pushed the 202511_test_outbound_mgmt branch from 1158564 to b961ad4 Compare December 11, 2025 21:00
@mzumsande
mzumsande force-pushed the 202511_test_outbound_mgmt branch 3 times, most recently from 53457d8 to 0cb0857 Compare January 2, 2026 00:17

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 0cb08573f38b7aa8a18147eef1a775b6c24bcb7c

I ran test_runner.py and p2p_outbound_management.py a bunch of times locally and did not observe timeouts.

Comment on lines +92 to +95
self.log.info("Advance time")
self.cur_time += self.MOCKTIME_BUMP
node.setmocktime(self.cur_time)
self.generate(node, 1) # Disable stale-tip extra-outbound connections that could interfer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an unlikely scenario that a stale-tip extra-outbound connection is initiated after advancing the mocktime and before self.generate(node, 1)? And eventually causing the interference that this is trying to disable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think probably not in practice - CheckForStaleTipAndEvictPeers fires every 45 seconds (on a steady clock, not influenced by the mocktime bump). So I think this means it would only fire if 45 real seconds passed since the last mockscheduler call, which seems very unlikely.

@mzumsande
mzumsande force-pushed the 202511_test_outbound_mgmt branch 2 times, most recently from 1562496 to b5e9e38 Compare February 24, 2026 16:17
@mzumsande
mzumsande force-pushed the 202511_test_outbound_mgmt branch from b5e9e38 to c733d11 Compare February 24, 2026 17:25

@mzumsande mzumsande left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @vasild!
Rebased, addressed feedback, and also added a commit that uses the test-framework auto-outbound mode for p2p_private_broadcast.py, removing some duplicate code.

I just had a rare (?) local intermittent failure of p2p_private_broadcast.py that I need to look into, so I will keep it in draft a little bit longer.

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c733d11

I just had a rare (?) local intermittent failure of p2p_private_broadcast.py

Might be related to #34410 or #34646

@Bortlesboat Bortlesboat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c733d11. Ran p2p_outbound_management.py and p2p_private_broadcast.py locally on Ubuntu 24.04, both pass.

@mzumsande
mzumsande force-pushed the 202511_test_outbound_mgmt branch from c733d11 to abf8fc4 Compare August 28, 2026 15:42

@mzumsande mzumsande left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebased after several changes to p2p_private_broadcast.py - not a trivial rebase and not ready for review yet - still need to change some things / address feedback

@0xB10C

0xB10C commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

@mzumsande

mzumsande commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

rebased and overhauled the test, also addressed the outstanding feedback.

The main complication is that different types of extra outbound connections on probabilistic timers all use the one available connection slot, so it is a bit hard to handle all constellations.

The extra block-relay-only connections are now tested in a separate subtest, and we avoid them in the extra outbound test by using an older tip. That also fixed an intermittent failure seen in the previous CI.

one thing I'm not sure about: should the added code in the test framework be put into its own module (test_framework/auto_outbound.py) or should I leave it as is.

mzumsande and others added 3 commits November 25, 2026 11:55
This new option allows tests to make use of automatic outbound connections
(made from addrman) for the nodes listed in auto_outbound_nodes.
A SOCKS5 proxy is used to redirect the connection, by default to a P2PInterface.

For advanced customization, tests can provide auto_outbound_factory() to
override where each outbound connection made by a node should be redirected
to (for example to another node). It is passed the connection type, which is
determined by matching the proxy client's address against the nodes'
getpeerinfo addrbind.

The generic pieces are taken from p2p_private_broadcast.py, which is
converted to use them in the next commit.

Co-authored-by: Vasil Dimov <[email protected]>
Using the test framework avoids some duplicated code.
The test covers
- Extra outbound connections when the tip is stale
- Regularly scheduled extra block-relay-only connections
- Management of full outbound connection slots with respect to network-specific peers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants