Repository navigation
fix: bound inbound p2p work handled per network pass - #7784
Open
brice-stacks wants to merge 14 commits into
Open
brice-stacks wants to merge 14 commits into
brice-stacks wants to merge 14 commits into
Conversation
New `[connection_options]` settings bound how much inbound p2p work a node does in one network pass: `max_inbound_messages_per_pass` (default `64`) caps the messages handled from any one peer, and `max_inbound_processing_ms` (default `500`) caps the time spent handling inbound messages before the node moves on to inventory sync, block downloads and StackerDB sync. Work that doesn't fit is carried over to the next pass, which starts immediately unless the node is still processing previously downloaded blocks. While a peer's leftover messages are queued, the node stops reading from that peer's socket, so a burst of messages can't overflow the inbox and drop the connection.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Buffered replies can be lost on socket closure, and the processing-time budget is not enforced within a peer’s message batch.
2 open issues
What changed in this PR
This PR adds configurable inbound P2P work limits to help the network thread reach inventory sync, block downloads, and StackerDB sync promptly.
Changes:
- Adds per-peer message and per-pass processing-time settings.
- Carries deferred conversations into later passes and pauses socket reads while inboxes have a backlog.
- Updates both node loops to resume pending work promptly and adds message-cap and backpressure tests.
| File | Description |
|---|---|
stackslib/src/net/tests/neighbors.rs |
Adds deferred-processing and socket-backpressure tests. |
stackslib/src/net/p2p.rs |
Tracks pending conversations and schedules bounded processing. |
stackslib/src/net/connection.rs |
Defines inbound limits and their defaults. |
stackslib/src/net/chat.rs |
Caps messages processed per conversation and adds coverage. |
stackslib/src/config/mod.rs |
Exposes and documents the configuration settings. |
stacks-node/src/neon_node.rs |
Shortens polling delay when inbound work remains. |
stacks-node/src/nakamoto_node/peer.rs |
Applies pending-work polling to the Nakamoto node. |
changelog.d/p2p-bound-inbound-work.added |
Describes the settings and intended behavior. |
Review effort: Balanced
This addresses two PR comments. First, the processing time is checked within one conversation and can be interrupted. Second, when a peer's socket fails, drain all of the messages in its inbox before exiting so they are not lost.
brice-stacks
marked this pull request as ready for review
October 23, 2026 20:29
The new type, `InboundBudget` incapsulates both bounds.
aaronb-stacks
approved these changes
Nov 6, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

New
[connection_options]settings bound how much inbound p2p work a node does in one network pass:max_inbound_messages_per_pass(default64) caps the messages handled from any one peer, andmax_inbound_processing_ms(default500) caps the time spent handling inbound messages before the node moves on to inventory sync, block downloads and StackerDB sync.Work that doesn't fit is carried over to the next pass, which starts immediately unless the node is still processing previously downloaded blocks.
While a peer's leftover messages are queued, the node stops reading from that peer's socket, so a burst of messages can't overflow the inbox and drop the connection.