Skip to content

fix: bound inbound p2p work handled per network pass - #7784

Open
brice-stacks wants to merge 14 commits into
stacks-network:mainfrom
brice-stacks:fix/p2p-bound-inbound-work
Open

brice-stacks wants to merge 14 commits into
stacks-network:mainfrom
brice-stacks:fix/p2p-bound-inbound-work

Conversation

@brice-stacks

Copy link
Copy Markdown
Contributor

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.

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.

Copilot AI 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.

🟡 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

Comment thread stackslib/src/net/chat.rs Resolved
Comment thread stackslib/src/net/p2p.rs Resolved
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
brice-stacks requested a balanced review from Copilot October 23, 2026 19:48

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@brice-stacks
brice-stacks marked this pull request as ready for review October 23, 2026 20:29
Comment thread stackslib/src/net/p2p.rs Resolved
Comment thread stackslib/src/config/mod.rs Resolved
Comment thread stackslib/src/net/p2p.rs Resolved
Comment thread stackslib/src/net/p2p.rs Resolved
Comment thread stackslib/src/net/p2p.rs Resolved
Comment thread stackslib/src/net/p2p.rs Resolved
Comment thread stackslib/src/net/p2p.rs Resolved

@federico-stacks federico-stacks 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.

LGTM!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants