Skip to content

fix(p2p): stop a congested peer from stalling consensus round-state gossip - #1625

Merged
lklimek merged 5 commits into
devfrom
fix/consensus-round-state-refresh-stall
Nov 17, 2026
Merged

lklimek merged 5 commits into
devfrom
fix/consensus-round-state-refresh-stall

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

A single slow or congested peer could stop a validator from telling its other peers which consensus round it is in. Validators then stopped sending each other proposals and the network got stuck on one height, voting nil round after round. This change makes sure a slow peer only misses its own round-state updates and no longer holds up everyone else's.

User story

As a validator operator, I want my node to keep reaching consensus with healthy peers while one of its peers is slow, to keep the chain producing blocks.

Scenario

Steps to reproduce

  1. Run a network of several validators.
  2. Let one peer's outbound queue fill up, e.g. a slow peer during a burst of consensus traffic. Since fix(consensus): periodically re-announce round state to peers #1598 the nodes announce their round state periodically, which adds to that traffic.
  3. Watch the validators' round progress.

Actual behavior

Round-state announcements to every peer are delayed by several seconds. The proposer believes its peers are still in the old round, so it does not send them the proposal. Validators prevote and precommit nil round after round. In CI, TestReactorValidatorSetChanges fails this way in 4 of 6 runs since #1598, against 0 of about 40 runs before it.

Expected behavior

Round-state announcements keep flowing to healthy peers. The congested peer misses some of its own announcements and catches up through the periodic re-announcement added in #1598.

Detailed discussion

Root cause. The router has one routeChannel goroutine per channel, and it enqueues each outbound envelope into each target peer's queue with a blocking send (internal/p2p/router.go). When one peer's queue is full, that goroutine blocks, and so does every message on that channel to every other peer: head-of-line blocking. A goroutine dump of a stalled TestReactorValidatorSetChanges run shows the consensus state channel (0x20) goroutine blocked on that send on 5 of 7 nodes. Timestamped logs show NewRoundStep arriving about 5s late at the stuck height, against 0.1–0.4s before it.

Fix. A new channel descriptor option, DropOnFullPeerQueue, makes the router use a non-blocking enqueue for that channel. It is enabled only for ConsensusStateChannel. When the peer queue is full, the router:

  • drops the envelope,
  • completes its delivery notification,
  • counts the drop in PeerQueueDroppedMsgs (ch_id label).

The state-channel messages are either advisory or repeated (NewRoundStep through the periodic refresh from #1598, HasVote, VoteSetMaj23/VoteSetBits through the maj23 query loop), so losing one to a congested peer is recoverable. All other channels keep blocking enqueue, because their messages (proposals, block parts, votes, PEX) are not necessarily retried.

Out of scope.

Tests. internal/p2p/router_queue_test.go covers:

  • unicast and broadcast to a full peer queue not blocking other peers (fails on dev);
  • recovery after the queue drains;
  • drop accounting;
  • unchanged backpressure on data and PEX channels.

Results, local, -race -tags deadlock:

Test Result
Router regression tests, on dev 6/6 failing
Router regression tests, with the fix 40/40 passing
Data/PEX backpressure tests 40/40 passing
TestReactorValidatorSetChanges 3/3 passing

TestReactorValidatorSetChanges also passed once on unmodified dev locally, so these local runs do not prove the flake is gone. CI history is the deciding signal.

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

PR Hygiene · 8a9ce97

  • Bots — thepastaclaw ✓
  • Self-review — not asked of a bot author
  • Build green
  • Approvals
    • files with no dedicated owner (internal/p2p/channel_params.go, internal/p2p/conn/connection.go, internal/p2p/router.go and 1 more) — approved by lklimek

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Drop state-channel messages when a peer queue is full, count the drop,
and complete delivery notifications. A slow peer must not hold up the
round-state updates other peers need to send proposals and votes.

State messages are retried or advisory; preserve blocking enqueue for
other channels whose messages may not be retried. Keep periodic round
state refresh intact to recover announcements dropped during congestion.

Cover full-queue unicast and broadcast, recovery after draining, drop
accounting, and unchanged data/PEX backpressure.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Codex (gpt-6-astra) <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

thepastaclaw commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ Final review complete — no blockers (commit 8a9ce97) · triage: normal

Match the debug log the blocking enqueue path emits when the peer queue
is closed.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the hardcoded consensus state channel check in routeChannel with a
DropOnFullPeerQueue channel descriptor option, enabled for the state
channel.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lklimek
lklimek marked this pull request as ready for review November 17, 2026 14:39
@lklimek lklimek added this to the v2.0 milestone Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 17, 2026
@lklimek lklimek added the priority: high High priority — address soon label Nov 17, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

The PR correctly removes head-of-line blocking for the consensus state channel while preserving blocking behavior for other channels, and the available code checks passed. Two non-blocking issues remain: VoteSetBits responses use a retry path but remain exposed to the same channel-level blocking, and the new descriptor comment inaccurately describes closed-queue drops.

🟡 1 suggestion(s) | 💬 1 nitpick(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: VoteSetBits responses remain exposed to channel-level head-of-line blocking
internal/p2p/channel_params.go:167-174

VoteSetBits responses use the same per-channel routeChannel goroutine and blocking peer-queue enqueue as before, so one full peer queue can still delay responses to every other peer on channel 0x23. This sibling path is recoverable because sendVoteSetBits gives up after its short timeout and the requesting peer asks again on a later gossip tick, but that recovery mechanism matches the rationale used for the non-blocking state channel. Enable DropOnFullPeerQueue for VoteSetBitsChannel as well, or create a tracked follow-up issue explaining why its remaining backpressure is intentional.

source: muse-spark-1.3-contributor (phase1-reviewer: general)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a contained but behavior-changing P2P routing and concurrency fix that affects consensus message delivery and backpressure, without directly changing consensus rules or another critical surface listed for the critical tier.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `internal/p2p/channel_params.go`:
- [SUGGESTION] internal/p2p/channel_params.go:167-174: VoteSetBits responses remain exposed to channel-level head-of-line blocking
  VoteSetBits responses use the same per-channel routeChannel goroutine and blocking peer-queue enqueue as before, so one full peer queue can still delay responses to every other peer on channel 0x23. This sibling path is recoverable because sendVoteSetBits gives up after its short timeout and the requesting peer asks again on a later gossip tick, but that recovery mechanism matches the rationale used for the non-blocking state channel. Enable DropOnFullPeerQueue for VoteSetBitsChannel as well, or create a tracked follow-up issue explaining why its remaining backpressure is intentional.

In `internal/p2p/conn/connection.go`:
- [NITPICK] internal/p2p/conn/connection.go:666-670: DropOnFullPeerQueue documentation misstates closed-queue drops
  The comment says dropped messages are counted and not logged, but the DropOnFullPeerQueue branch also handles closed queues at router.go:379-381. Those drops are logged at debug level and are not added to PeerQueueDroppedMsgs, so the documentation does not describe all behavior controlled by this field.

Comment thread internal/p2p/conn/connection.go Resolved
@github-actions github-actions Bot removed the waiting-bots Waiting for the review bots to report on this head label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 17, 2026
@lklimek
lklimek enabled auto-merge (squash) November 17, 2026 15:39
@lklimek

lklimek commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

/skip-bots

@github-actions github-actions Bot added bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Nov 17, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 1 + Phase 2

The current head includes the documentation correction for closed-queue drops, and all completed build, test, vet, lint, vulnerability, and protocol checks pass. No new independent issues were identified beyond the carried-forward VoteSetBits routing concern.

🟡 1 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: VoteSetBits responses remain exposed to channel-level head-of-line blocking
internal/p2p/channel_params.go:167-174

VoteSetBitsChannel still leaves DropOnFullPeerQueue disabled, so routeChannel uses its blocking enqueue path. A peer that stops reading can fill its shared outbound queue; when a VoteSetBits response for that peer reaches the router, the channel goroutine blocks and responses for healthy peers wait behind it. The five-millisecond sendVoteSetBits timeout only bounds the reactor-to-router handoff and cannot unblock a router goroutine already waiting on the peer queue. This remains part of the recoverable maj23 vote catch-up path described by the PR. Enabling the descriptor flag alone is not sufficient: sendVoteSetBits records the answer whenever Channel.Send returns successfully, but a non-blocking router drop can occur after that handoff, falsely suppressing retries. The channel therefore needs either delivery-aware drop handling or another non-blocking strategy that preserves the retry bookkeeping.

source: muse-spark-1.3-contributor (phase1-reviewer: general); gpt-6.1-sol (phase2-reviewer: general, tenderdash-consensus-security)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a contained but behaviorally significant router and concurrency change affecting consensus-state gossip, without modifying consensus rules, cryptography, or peer-facing deserialization.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `internal/p2p/channel_params.go`:
- [SUGGESTION] internal/p2p/channel_params.go:167-174: VoteSetBits responses remain exposed to channel-level head-of-line blocking
  `VoteSetBitsChannel` still leaves `DropOnFullPeerQueue` disabled, so `routeChannel` uses its blocking enqueue path. A peer that stops reading can fill its shared outbound queue; when a VoteSetBits response for that peer reaches the router, the channel goroutine blocks and responses for healthy peers wait behind it. The five-millisecond `sendVoteSetBits` timeout only bounds the reactor-to-router handoff and cannot unblock a router goroutine already waiting on the peer queue. This remains part of the recoverable maj23 vote catch-up path described by the PR. Enabling the descriptor flag alone is not sufficient: `sendVoteSetBits` records the answer whenever `Channel.Send` returns successfully, but a non-blocking router drop can occur after that handoff, falsely suppressing retries. The channel therefore needs either delivery-aware drop handling or another non-blocking strategy that preserves the retry bookkeeping.

@github-actions

Copy link
Copy Markdown

Policy satisfied — this can merge.
Full checklist in the description.

@github-actions github-actions Bot removed the bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. label Nov 17, 2026
@lklimek
lklimek merged commit a7379f0 into dev Nov 17, 2026
29 checks passed
@lklimek
lklimek deleted the fix/consensus-round-state-refresh-stall branch November 17, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: high High priority — address soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants