Skip to content

fix(p2p): initialize peer routing before publishing readiness - #1464

Merged
lklimek merged 1 commit into
v1.8-devfrom
fix/p2p-ready-after-queue
Sep 14, 2026
Merged

lklimek merged 1 commit into
v1.8-devfrom
fix/p2p-ready-after-queue

Conversation

@lklimek

@lklimek lklimek commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

TL;DR: Prevent the first message to a newly connected peer from being dropped after the peer has already been announced as ready.

Issue being fixed or feature implemented

A peer can be announced as ready before its outgoing queue exists. Sending immediately after that notification drops the message as targeting an unconnected peer. This caused tests (02) on PR #1460 to receive 9 of 10 messages and time out in TestRouter_Channel_Enqueue_Timeout.

User story

As a node operator, I want messages sent when a peer becomes ready to reach that peer reliably.

Scenario

A subscriber sends a message immediately after receiving PeerStatusUp. The router must already have the peer's send queue and supported channels registered.

What was done?

Detailed discussion

Initialize the peer queue and channel map before calling PeerManager.Ready. Add a deterministic regression test that pauses queue creation and verifies that no readiness event has been published, then verifies readiness and routing registration once initialization completes.

This PR branches directly from v1.8-dev and is independent of #1460.

How Has This Been Tested?

  • The new TestRouter_ReadyAfterQueue fails on the base with peer advertised readiness before its send queue exists.
  • go test -race -tags deadlock ./internal/p2p -count=1.
  • make lint LINT_BASE=origin/v1.8-dev: 0 issues.
  • gofmt and git diff --check.

Breaking Changes

None. Readiness notifications are delivered after the outgoing route has been initialized.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation (not needed)

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Co-authored by Claudius the Magnificent AI Agent

Create the send queue and register peer channels before PeerStatusUp so
subscribers can send immediately without losing their first message.

Add a deterministic regression test that pauses queue creation and checks
that readiness is published only once the outgoing route exists.

Co-Authored-By: Codex <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 14, 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

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e5620ab0-3db4-408c-bf67-e6b514065e2a

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

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

Comment @coderabbitai help to get the list of available commands.

@lklimek
lklimek marked this pull request as ready for review September 14, 2026 10:43
@lklimek
lklimek requested a review from shumkov as a code owner September 14, 2026 10:43
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

PR Hygiene

State: waiting-self-review · commit a2741b815053a08114a78fbc2d080d705363fd55

  • Author must post /self-reviewed a2741b8 after bot completion

Self-review is an author attestation that you have read the diff:
/self-reviewed — covers everything pushed so far; post it again after a new push.
Post it after this report appears for commit a2741b815053a08114a78fbc2d080d705363fd55, or name the commit explicitly with /self-reviewed a2741b815053a08114a78fbc2d080d705363fd55.

This report does not bypass CI or repository protection rules.

@thepastaclaw

thepastaclaw commented Sep 14, 2026 •

Copy link
Copy Markdown

✅ Final review complete — no blockers (commit a2741b8) · triage: low · Phase 2 only (queue backlog)

@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 2 only (queue backlog)

The change initializes the peer's outgoing queue and channel routing before publishing PeerStatusUp, directly addressing the readiness race described by the PR. The deterministic regression test verifies readiness is withheld while queue creation is blocked and that routing state exists once readiness is announced; no in-scope correctness, security, or concurrency defects were found.

Review provenance

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: low by gpt-6-astra (effort low) — This is a small, well-contained initialization-order fix in the peer router with a deterministic regression test; although it affects message delivery timing, it does not change a critical surface such as consensus, cryptography, storage migrations, or peer-facing deserialization.
  • Phase 1 reviewers: not run (skipped for throughput: 15 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort medium); agent phase2-reviewer, gpt-6-astra — tenderdash-consensus-security (completed, effort medium); agent phase2-reviewer

@lklimek
lklimek merged commit fcb6f4d into v1.8-dev Sep 14, 2026
22 checks passed
@lklimek
lklimek deleted the fix/p2p-ready-after-queue branch September 14, 2026 14:04
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.

2 participants