Skip to content

fix(p2p): bound the simple priority queue, honor channel priorities and count drops - #1627

Merged
lklimek merged 20 commits into
devfrom
fix/p2p-simple-queue-limits
Dec 1, 2026
Merged

lklimek merged 20 commits into
devfrom
fix/p2p-simple-queue-limits

Conversation

@Claudius-Maginificent

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

Copy link
Copy Markdown
Collaborator

TL;DR

The default incoming P2P queue could build a backlog of about 16.7 million consensus votes. At that size, sorting on each additional vote stalled the node. This change caps the incoming backlog, uses channel priorities to choose which queued messages to keep, and counts messages evicted from the default queue.

User story

As a validator operator, I want my node's message queues to stay bounded, to favour consensus traffic under load, and to report what they drop, so that a burst of traffic cannot stall consensus unnoticed.

Scenario

Steps to reproduce

  1. Run a node with the default p2p.queue-type = "simple-priority".
  2. Send it a sustained burst of consensus votes faster than it processes them, or let a peer's outbound queue back up with mixed traffic.

Actual behavior

  • The vote channel's inbound heap grows to about 16.7 million envelopes (4096²) before overflow. Once it is full, each new envelope sorts the heap, so senders stall for seconds.
  • All channels share priority 0, so when a peer queue overflows, consensus messages are dropped as readily as PEX or mempool ones.
  • Simple-priority heap evictions are absent from the P2P drop counter.

Expected behavior

  • The inbound heap holds up to 16× the channel's receive buffer capacity. For the vote channel, that is 65,536 heap entries plus 8,192 input and 2,048 output buffer slots. The outbound heap holds up to 1,024 entries per peer, with separate input and output buffers.
  • Within the heap, higher-priority entries are dequeued first and kept ahead of lower-priority entries on overflow. Entries already in the output buffer are delivered in FIFO order.
  • With Prometheus enabled and the default namespace, each simple-priority heap eviction increments tendermint_p2p_router_channel_queue_dropped_msgs{ch_id}. Inbound admission timeouts are only logged (p2p: simple priority queue starves votes behind block parts, has no byte budget, and mixes drop directions #1669).

Detailed discussion

Stack (bottom → top; a manual stack, since native stacked PRs are not enabled for this repository): #1600 → #1627 → #1515 → #1639 → #1641 → #1642. This PR is 2 of 6, base fix/consensus-serve-polka-block; depends on #1600; merge them first (bottom-up). Each PR carries only its own changes. The dependency on #1600 is ordering only; this change does not rely on it.

Limit. newSimplePriorityQueue used maxSize = size * size, a "generous" bound picked upstream (tendermint#8929) when channel buffers were 128 deep. With our vote channel's RecvBufferCapacity of 4096 it reaches 16.7M. Inbound heaps now use size * simpleQueueCapacityMultiplier (16). Outbound peer heaps keep size * size (queueBufferDefault = 32, heap 1,024). Input and output buffers are additional to both heap limits.

Priorities. simpleQueue.chDescs was never set, so every envelope got priority 0. The queue now resolves priority at enqueue time through Router.channelPriority, which reads r.chDescs under channelMtx.RLock(). That includes channels opened after the queue was created.

Drop counter. Simple-priority heap evictions increment PeerQueueDroppedMsgs with the same ch_id label format that pqScheduler uses, and their delivery notification still completes.

Peer queue capacity. The per-peer heap stays at 1024. Gossip marks proposals, votes and block parts as sent when they are enqueued, so an envelope trimmed from a peer queue is not re-sent; a smaller heap could drop a signed proposal under a temporary send backlog. Trimmed slots are cleared, so evicted envelopes are not kept in memory.

No polling. The run loop no longer wakes on a 10 ms ticker. The send case is enabled only while the heap is non-empty (a nil channel otherwise), so the loop sleeps when idle and forwards an envelope as soon as the consumer has room.

Out of scope.

  • Trimming still sorts the heap on overflow, under the separate heap limits of 16× the channel buffer size inbound and 1,024 entries per outbound peer.
  • The shared Less is not transitive, so a trim can leave the heap order inconsistent (pre-existing).
  • The shared Less orders newest-first within a priority.
  • Possible starvation of low priorities under sustained load.
  • A FIFO-per-channel redesign, or switching the default to priority.

Related.

Testing. The queue regression tests cover heap bounds, priority ordering, eviction accounting with NotifyDelivery, and late channel registration. The occupancy tests account for each offer through delivery or eviction within the test deadline. The ./internal/p2p package passes with -race -tags deadlock. Formatting and golangci-lint checks pass.

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

PR Hygiene · c4ba755

  • Bots — thepastaclaw ✓
  • Self-review — not asked of a bot author
  • Build green
  • Approvals
    • files with no dedicated owner (internal/p2p/delivery_notification_test.go, internal/p2p/load_router_queue_test.go, internal/p2p/router.go and 4 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.

lklimek and others added 7 commits November 9, 2026 13:26
…t in its round

A validator that saw a polka for a block it never received precommits nil
and, once its peers move to a later round, can no longer obtain the block:
block parts are served only from the proposal part set, which entering a
new round clears, while the valid and locked part sets that still hold the
block are never gossiped. Even when the block does arrive, one completed in
the prevote or precommit step is not processed, so an application that
verifies vote extensions against its last processed proposal, like Drive,
rejects every precommit for the block. Rejected precommits are not stored
and do not count towards the +2/3 of any kind that start the precommit
wait, so the validator stays in its round for good and a network without
spare voting power stalls with it.

Serve a validator peer at this height, in an earlier round, the complete
valid or locked part set whose header it is collecting, from the gossip
snapshot. Process the round's polka block when it completes too late for
the round to vote on it, so that the precommits for it verify; the node
casts no vote again, and a failure is not retried.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A polka block the application rejects is processed once and not retried
on the precommits for it or on its parts arriving again; a block completing
in the prevote wait is processed there and not again in the precommit step;
one completing in the propose step with its proposal takes the usual path
and is processed once; a block completing without being the round's polka
block is not processed; an incomplete held part set is not served.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A block completing while the round's polka is for another block is not
processed; a nil polka alone let the identity check go unexercised. The
rejected-block test no longer redelivers parts the part set already holds,
which completes nothing.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… set is incomplete

heldBlockPartsFor skipped the held-block fallback whenever the round's
ProposalBlockParts carried the peer's part set header, even when that set
was incomplete and had nothing left to send. A complete current set still
suppresses the fallback, which would send nothing new anyway.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ommit step

A block that completed in the precommit step before its polka was never
processed: ProposalCompletedAction found no polka, and the prevote that
formed it later only updated the valid block, as the node had already
precommitted. The application then rejected every precommit for the block
and the node never started its precommit wait.

blockExecutor.processPolkaBlock now owns the condition (current-round
non-nil polka, matching proposal block, not yet processed) and is called
both on block completion and when the current round's polka forms in the
Precommit or PrecommitWait step. The polka path runs once per round, as
the valid round is set there, so a failed ProcessProposal is not retried.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s nil for it

When the polka formed in the prevote steps and enterPrecommit precommitted
nil because the round's proposal was missing or its timestamp differed from
the block's, the held polka block was never processed: the valid round was
already set and the block had completed earlier. The application then
rejected every precommit for it and the node never started its precommit
wait. Both nil branches now call processPolkaBlock before signing; it is a
no-op unless the held block is the unprocessed polka block, and
enterPrecommit runs once per round.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h nil precommit

With no proposal held, a polka block can only be held unprocessed after
ProposalCompletedAction already tried and failed to process it, so the call in
that branch was a silent retry that contradicted the no-retry contract and was
not covered by any test. The timestamp-mismatch branch alone closes the stall.

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

Co-Authored-By: Claude Opus 5.5 <[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 c4ba755) · triage: normal

@lklimek lklimek added the priority: low Low priority — nice to have label Nov 17, 2026
@lklimek lklimek added this to the v2.1 milestone Nov 17, 2026
lklimek and others added 8 commits November 17, 2026 14:17
Use a 16x multiplier so the per-peer outbound queue keeps 512 envelopes,
enough for a full block's parts plus a vote burst, while channel queues
stay far below the previous size-squared bound.

Replace the 10ms ticker and signal channel with a send case that is
enabled only while the heap is non-empty, so the run loop sleeps when
idle and forwards envelopes as soon as the consumer has room.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PartSet.IsComplete read count without the part set mutex that AddPart
writes it under. Consensus gossip checks the completeness of the
proposal part set the consensus state is filling, so the read raced
with AddPart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A block that completed before its polka must be processed when the
polka forms after +2/3 precommits started the precommit wait, so that
the precommits for it verify. The valid-block middleware test passes a
real block executor rather than nil to the polka processing it calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
processPolkaBlock also runs before the node votes, and on the nil
precommit over a mismatched proposal timestamp, so its doc and log
messages no longer say the block arrived too late to vote on. The debug
log drops the step, which on the timestamp path is the step before
precommit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The node's own step never becomes RoundStepPrecommitWait: entering the
precommit wait only sets TriggeredTimeoutPrecommit and leaves the step
at RoundStepPrecommit, which the polka-block hook already checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o a block

Drive verifies a vote extension against the block it accepted in the
precommit's round or, failing that, the same block accepted in another
round of the height; the polka-block recovery matters when it accepted
the block in neither. Other applications may require the same round.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hout a proposal

A node whose signed proposal was dropped (its BlockID did not describe the
completed block) keeps the block but precommits nil without a proposal.
When +2/3 prevoted that block, the application never processed it in the
round, so peer precommits carrying extensions for it failed verification
and the precommit wait never started. Process the held polka block before
the nil precommit, as the timestamp-mismatch branch already does.

The test application's comment now describes the strict same-round
contract it enforces, which Drive relaxes to the same block accepted in
another round of the height.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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

New on this head: The latest commit only replaces TestSimpleQueue's hard-coded delivery bound with the queue's calculated heap and buffer capacities, allowing the valid maximum of 21 envelopes. All p2p test groups, lint, vet, build, and application checks pass; tests (00) still reports an unrelated timeout in unchanged internal/consensus code, while the remaining review checks are either successful or pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

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

  • Triage: normal by gpt-6.2-sol (effort low) — This is a substantial but contained change to P2P queue bounds, prioritization, eviction, metrics, and concurrency behavior; it affects resource-exhaustion handling but does not itself modify consensus rules, cryptography, funds, storage migrations, 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.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-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. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

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

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Ready for review — files with no dedicated owner: lklimek or shumkov.
Full checklist in the description.

@github-actions github-actions Bot added the ready-for-human PR Hygiene: bots done, author self-reviewed, awaiting human review label Nov 29, 2026
@github-actions
github-actions Bot requested review from lklimek and shumkov November 29, 2026 21:12
Comment thread internal/p2p/rqueue.go Resolved
@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed ready-for-human PR Hygiene: bots done, author self-reviewed, awaiting human review labels Dec 1, 2026
Set the simple priority queue heap limit to 32 times the configured
buffer size in both directions. Drop the direction flag from queue
construction and pin the shipped inbound and per-peer outbound limits.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions
github-actions Bot removed the request for review from shumkov December 1, 2026 13:59
@github-actions

github-actions Bot commented Dec 1, 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 waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Dec 1, 2026
@lklimek
lklimek enabled stacked auto-merge (squash) December 1, 2026 14:24

@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

New on this head: This head uses one 32× heap multiplier for both directions, doubling inbound limits from the previous reviewed head while preserving the 1,024-entry outbound peer heap. The build, lint, unit, and end-to-end checks passed; PastaClaw review and PR Hygiene are pending.

🟡 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.

Review provenance

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

  • Triage: normal by gpt-6.2-sol (effort low) — This is a substantial but contained P2P queueing and metrics change involving bounded resource usage, prioritization, eviction semantics, and concurrency, but it does not directly alter consensus rules, cryptography, funds movement, peer-facing deserialization, or storage migrations.
  • 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.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-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/rqueue.go`:
- [SUGGESTION] internal/p2p/rqueue.go:13-14: The PR description understates the inbound heap limits by half
  Impact: Operators estimating how much vote traffic can queue before heap eviction are told the heap holds 65,536 envelopes when it actually holds 131,072.
  The vote heap can hold 65,536 more envelopes than the PR description says. `OpenChannel` passes the vote channel's 4,096-entry receive buffer size to the shared queue factory, which now applies the 32× multiplier; `TestSimpleQueueHeapLimit` pins the resulting 131,072 entries. Update Expected Behavior, Limit, and Out of Scope to describe the shared 32× formula. The vote queue's 8,192 input slots and 2,048 output slots, and the 1,024-entry outbound peer heap, are unchanged.

Comment thread internal/p2p/rqueue.go Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Ready for review — resolve every review thread lklimek left open (their approval counts).
Full checklist in the description.

@github-actions github-actions Bot added ready-for-human PR Hygiene: bots done, author self-reviewed, awaiting human review and removed waiting-bots Waiting for the review bots to report on this head labels Dec 1, 2026
@github-actions
github-actions Bot requested a review from lklimek December 1, 2026 14:45
@github-actions
github-actions Bot requested review from lklimek and removed request for lklimek December 1, 2026 18:32
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

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

@github-actions github-actions Bot removed the ready-for-human PR Hygiene: bots done, author self-reviewed, awaiting human review label Dec 1, 2026
@lklimek
lklimek merged commit a73d7fd into dev Dec 1, 2026
27 checks passed
@lklimek
lklimek deleted the fix/p2p-simple-queue-limits branch December 1, 2026 19:24
lklimek added a commit that referenced this pull request Dec 3, 2026
…es (#1515)

* fix(consensus): deliver and process a polka block for a validator left in its round

A validator that saw a polka for a block it never received precommits nil
and, once its peers move to a later round, can no longer obtain the block:
block parts are served only from the proposal part set, which entering a
new round clears, while the valid and locked part sets that still hold the
block are never gossiped. Even when the block does arrive, one completed in
the prevote or precommit step is not processed, so an application that
verifies vote extensions against its last processed proposal, like Drive,
rejects every precommit for the block. Rejected precommits are not stored
and do not count towards the +2/3 of any kind that start the precommit
wait, so the validator stays in its round for good and a network without
spare voting power stalls with it.

Serve a validator peer at this height, in an earlier round, the complete
valid or locked part set whose header it is collecting, from the gossip
snapshot. Process the round's polka block when it completes too late for
the round to vote on it, so that the precommits for it verify; the node
casts no vote again, and a failure is not retried.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* test(consensus): cover the edges of polka block delivery and processing

A polka block the application rejects is processed once and not retried
on the precommits for it or on its parts arriving again; a block completing
in the prevote wait is processed there and not again in the precommit step;
one completing in the propose step with its proposal takes the usual path
and is processed once; a block completing without being the round's polka
block is not processed; an incomplete held part set is not served.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* test(consensus): guard the polka block identity check on completion

A block completing while the round's polka is for another block is not
processed; a nil polka alone let the identity check go unexercised. The
rejected-block test no longer redelivers parts the part set already holds,
which completes nothing.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(consensus): serve a held polka block when the current same-header set is incomplete

heldBlockPartsFor skipped the held-block fallback whenever the round's
ProposalBlockParts carried the peer's part set header, even when that set
was incomplete and had nothing left to send. A complete current set still
suppresses the fallback, which would send nothing new anyway.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(consensus): process a held block when its polka forms in the precommit step

A block that completed in the precommit step before its polka was never
processed: ProposalCompletedAction found no polka, and the prevote that
formed it later only updated the valid block, as the node had already
precommitted. The application then rejected every precommit for the block
and the node never started its precommit wait.

blockExecutor.processPolkaBlock now owns the condition (current-round
non-nil polka, matching proposal block, not yet processed) and is called
both on block completion and when the current round's polka forms in the
Precommit or PrecommitWait step. The polka path runs once per round, as
the valid round is set there, so a failed ProcessProposal is not retried.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(consensus): process the polka block when enterPrecommit precommits nil for it

When the polka formed in the prevote steps and enterPrecommit precommitted
nil because the round's proposal was missing or its timestamp differed from
the block's, the held polka block was never processed: the valid round was
already set and the block had completed earlier. The application then
rejected every precommit for it and the node never started its precommit
wait. Both nil branches now call processPolkaBlock before signing; it is a
no-op unless the held block is the unprocessed polka block, and
enterPrecommit runs once per round.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(consensus): process the polka block only on the timestamp-mismatch nil precommit

With no proposal held, a polka block can only be held unprocessed after
ProposalCompletedAction already tried and failed to process it, so the call in
that branch was a silent retry that contradicted the no-retry contract and was
not covered by any test. The timestamp-mismatch branch alone closes the stall.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(p2p): raise simple queue headroom to 16x and drop the polling ticker

Use a 16x multiplier so the per-peer outbound queue keeps 512 envelopes,
enough for a full block's parts plus a vote burst, while channel queues
stay far below the previous size-squared bound.

Replace the 10ms ticker and signal channel with a send case that is
enabled only while the heap is non-empty, so the run loop sleeps when
idle and forwards envelopes as soon as the consumer has room.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(types): read part set completeness under its mutex

PartSet.IsComplete read count without the part set mutex that AddPart
writes it under. Consensus gossip checks the completeness of the
proposal part set the consensus state is filling, so the read raced
with AddPart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(consensus): cover a polka forming in the precommit wait

A block that completed before its polka must be processed when the
polka forms after +2/3 precommits started the precommit wait, so that
the precommits for it verify. The valid-block middleware test passes a
real block executor rather than nil to the polka processing it calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(consensus): describe when the polka block is processed accurately

processPolkaBlock also runs before the node votes, and on the nil
precommit over a mismatched proposal timestamp, so its doc and log
messages no longer say the block arrived too late to vote on. The debug
log drops the step, which on the timestamp path is the step before
precommit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(consensus): drop the unreachable precommit-wait step check

The node's own step never becomes RoundStepPrecommitWait: entering the
precommit wait only sets TriggeredTimeoutPrecommit and leaves the step
at RoundStepPrecommit, which the polka-block hook already checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(consensus): describe how Drive matches a precommit's extension to a block

Drive verifies a vote extension against the block it accepted in the
precommit's round or, failing that, the same block accepted in another
round of the height; the polka-block recovery matters when it accepted
the block in neither. Other applications may require the same round.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(privval): keep a connection rejected during shutdown unpublished

Clear rejected connections before mirroring them and report ErrEndpointClosed from waiting acquisition. Stop ensureConnection from waiting again after shutdown rejects a hand-off. Cover availability, waiting, ensuring, and direct assignment in the regression test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(consensus): process a held polka block when precommitting nil without a proposal

A node whose signed proposal was dropped (its BlockID did not describe the
completed block) keeps the block but precommits nil without a proposal.
When +2/3 prevoted that block, the application never processed it in the
round, so peer precommits carrying extensions for it failed verification
and the precommit wait never started. Process the held polka block before
the nil precommit, as the timestamp-mismatch branch already does.

The test application's comment now describes the strict same-round
contract it enforces, which Drive relaxes to the same block accepted in
another round of the height.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(p2p): bound simple priority queue and honor channel priorities

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

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

* fix(privval): interrupt the signer server connection before closing it on stop

SignerServer.OnStop closed the endpoint while an idle ReadMessage held its connection lock, so stopping waited for the read deadline, and a dial racing the stop published an unclosed connection. Interrupt the connection first, as the listener endpoint does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(privval): end WaitConnection when the endpoint stops

A caller blocked in WaitConnection with its own context kept the listener's instance lock until maxWait, so OnStop waited too. Return ErrEndpointClosed once the endpoint stops, closing a connection handed over meanwhile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(light): unsubscribe when a websocket subscription is rejected during shutdown

SubscribeWS subscribed upstream, then returned an error without unsubscribing when the client or the websocket session was already stopping; the unread upstream subscription could stall delivery to other subscribers of a caller-owned client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(p2p): drop a redundant context check in recvRoutine

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(service)!: join remaining service workers before shutdown completes

Squashed net change of fix/base-service-stop up to 90226b4, restacked
linearly on fix/p2p-simple-queue-limits (#1627). The original commits
(including the dev merges) remain reachable from 90226b4.

Conflict resolved in internal/p2p/rqueue.go: keeps #1627's queue loop
(nil-channel send, no polling ticker, priority function, metrics) and this
change's closed() contract (closeCh is closed only after run returns).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(rpc): reference the orphaned-subscription follow-up without a TODO

STYLE_GUIDE.md asks to track work in an issue or PR, not a TODO comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(p2p): adapt simple queue tests to the running-router requirement

On top of #1627, OpenChannel requires a running router and the simple
queue constructor takes metrics and a priority function. Start the router
in the simple queue regression helper and pass the new constructor
arguments in the delivery-callback test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(node): wait for the Core RPC dispatcher to exit in the release check

WaitForShutdown returns when the dispatcher goroutine calls Done, which can
precede the goroutine's exit, so counting goroutines right after the node
stops could still see it (seen on CI in the failed-start case). Poll briefly
instead of asserting once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(upgrading): move the service lifecycle notes under Unreleased

Merging dev renamed the Unreleased section to v2.0.0, which left this PR's
additions under an already released version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(p2p): preserve outbound queue capacity and release evicted envelopes

Apply the reduced simple queue heap limit to inbound channel queues.
Preserve the existing capacity of outbound peer queues and clear
discarded heap slots after accounting and delivery notification.

Cover both queue limits, mixed-priority overflow in both arrival
orders, and complete draining of the small queue under backpressure.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(p2p): account for every simple queue offer

Count dequeued envelopes and eviction notifications in both occupancy
tests. Fail at the test deadline if any offer remains unaccounted for.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(p2p): correct the simple queue delivery bound

Account for the rounded input buffer when checking how many envelopes
can survive an undrained burst.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(p2p): use a single simple queue heap multiplier

Set the simple priority queue heap limit to 32 times the configured
buffer size in both directions. Drop the direction flag from queue
construction and pin the shipped inbound and per-peer outbound limits.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(p2p): keep #1515 running-router simple queue regression over dev

The merge resolved internal/p2p/rqueue.go and rqueue_regression_test.go to
dev's #1627 version, but #1515's surviving fix(service)! change makes
Router.OpenChannel require a running router. Dev's regression test does not
start the router, so it fails with "router is not running". Restore #1515's
versions of both files, which start the router and carry the matching simple
queue close semantics.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: Codex (gpt-6-astra) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: low Low priority — nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants