Skip to content

fix(p2p): reconnect persistent peers at outgoing capacity - #1490

Merged
lklimek merged 6 commits into
v1.8-devfrom
fix/issue-1039
Sep 22, 2026
Merged

lklimek merged 6 commits into
v1.8-devfrom
fix/issue-1039

Conversation

@lklimek

@lklimek lklimek commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Persistent peers can reconnect when ordinary peers have filled the outgoing connection limit.

User story

As a node operator, I want my configured persistent peers to reconnect reliably while connection usage stays bounded.

Scenario

A persistent peer disconnects and an ordinary peer takes its slot. The node should retry the persistent peer and replace the ordinary connection after a successful probe, rather than remain connected only to the ordinary peer.

Detailed discussion

Issue being fixed or feature implemented

Fixes #1039. With total and outgoing connections both limited to one, an ordinary replacement connection could permanently prevent a disconnected persistent peer from reconnecting. Retry jitter could also leave the dialer asleep after the only scheduled wakeup.

What was done?

  • Allow reserved peers to probe within the existing upgrade allowance at outgoing capacity, replacing a lower-scored outgoing peer only after a successful connection.
  • Count pending dials toward the outgoing limit, retain ordinary-peer limits, and recheck live capacity/victims when a probe succeeds.
  • Give the blocking dialer one cancellation-aware retry timer and wake it when pending dials complete or fail. This replaces detached cooldown/retry timers and keeps jitter calculation under the manager lock.
  • Document the outgoing upgrade semantics.

How Has This Been Tested?

Go 1.27.1, CGO enabled with the existing native BLS build:

  • Confirmed failing regressions for saturated persistent reconnect, retry jitter and completion wakeups before their respective fixes.
  • All PeerManager tests passed with the race detector and deadlock tag.
  • Full P2P package, including router integration: go test -race -p 1 -tags=deadlock ./internal/p2p -count=1 -timeout=180s -v passed.
  • Added coverage for failed probes, cooldowns, outgoing-only saturation, pending dials, reserved peers, disabled upgrades/retries, duplicate reservations, concurrent probes, disappearing victims, cancellation and new-peer wakeups during retry.
  • Repository-configured golangci-lint v2.13.2 against the base revision for ./internal/p2p/...: zero issues; goimports/gofmt and diff checks passed.
  • Four self-review passes; final pass has no unresolved in-scope findings.

Breaking Changes

None. No public signature, wire, configuration-format/default or persistence changes. Ordinary outgoing limits remain enforced; reserved-peer probing uses the existing bounded upgrade allowance. The separate early-startup unknown-channel mechanism was already addressed by #1460.

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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Co-authored by Claudius the Magnificent AI Agent

PR Hygiene · f6a74c3

  • Bots — thepastaclaw ✓
  • Self-review — posted; again after any push
  • Within your 5 open PRs
  • Build green
  • Approvals — you own every area touched; none needed

When every box is checked the PR Hygiene check passes and this can merge.

Use bounded outgoing upgrades for reserved peers and keep delayed retries
scheduled while existing connections fill normal capacity.

Co-Authored-By: GPT-6 Astra <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 21, 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: Repository: dashpay/tenderdash/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e76804f5-777f-4b99-996b-fbce4c2dcd09

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.

@thepastaclaw

thepastaclaw commented Sep 21, 2026 •

Copy link
Copy Markdown

⚠️ DEGRADED — Final review complete — no blockers (commit f6a74c3) · triage: normal · stand-in models (primary models out of quota)

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 review overview

🔵 Needs a closer look

Revalidate reserved upgrade probes when the initially selected victim disconnects.

Review effort: Lite
Findings: None

What changed in this PR

Fixes persistent-peer reconnection when outgoing capacity is saturated.

Changes:

  • Adds bounded reserved-peer upgrade probes.
  • Tracks pending dials and revalidates capacity.
  • Improves retry timers, wakeups, and regression coverage.
File Description
internal/​p2p/​peermanager.go Implements outgoing upgrades and retry scheduling; one moderate issue remains regarding probe revalidation.
internal/​p2p/​peermanager_retry_test.go Tests retry timing, cancellation, and wakeups.
internal/​p2p/​peermanager_reconnect_test.go Tests persistent reconnection and upgrade behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

lklimek and others added 2 commits September 21, 2026 13:10
Document tryDialNext's return contract and findUpgradeCandidate's direction
parameter, share upgradeDirection between tryDialNext and Dialed, and align
the max-outgoing-connections config docs and the DoS spec with the reserved-peer
probing behavior.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@lklimek
lklimek marked this pull request as ready for review September 21, 2026 13:11
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 21, 2026
Cover outgoing-capacity rejection paths and protected upgrades while making retry wake and jitter tests bounded and deterministic.

@lklimek lklimek left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/self-reviewed

@github-actions

Copy link
Copy Markdown

@thepastaclaw review

No review for f6a74c38 yet, so PR Hygiene is asking once. If nothing arrives, the requirement is dropped for this commit and the pull request is labelled bot-review-skipped.

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

⚠️ DEGRADED — Final validation — Phase 1 + Phase 2

⚠️ DEGRADED review. The primary review models were unavailable (gpt-6-astra unavailable: All credentials for model gpt-6-astra are cooling down (last error: usage_limit_reached: The usage limit has been reache), so this review ran on stand-in models: gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor. Both review phases and the independent verifiers still ran, but on weaker models, with Phase 1 capped at high effort. Treat the verdict as provisional; a full-strength re-review will run on the next push once the primary models are back.

PR correctly fixes #1039 via bounded reserved-peer probing and the single-timer dialer rework. The only in-scope defect is the new operator-facing comment claiming max-outgoing-connections=0 means unlimited, which is unreachable from config because node setup maps 0 to MaxConnections/2.

🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: tenderdash-consensus-security); reviewer 3: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: phase2-reviewer, role: general); reviewer 4: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: astra-verifier, role: final-verifier)

  • Degraded mode: gpt-6-astra unavailable: All credentials for model gpt-6-astra are cooling down (last error: usage_limit_reached: The usage limit has been reache (detected by probe, since 2026-09-20T20:45:34Z); stand-ins gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor; Phase 1 effort capped at high
  • Triage: normal by muse-spark-1.3-contributor (standing in for gpt-6-astra) (effort low) — PeerManager dial/retry logic change with bounded upgrade probing is an ordinary logic fix, not consensus, crypto, deserialization, or migration code.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — tenderdash-consensus-security (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 91% left; passed over gemini-3.8-flash-high (lane failed)
  • Fresh verifier: muse-spark-1.3-contributor (standing in for gpt-6-astra) — final-verifier; agent astra-verifier
  • Phase 2 reviewers: muse-spark-1.3-contributor (standing in for gpt-6-astra) — general (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6-astra) — 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 each finding against the current code and only fix it if needed.

In `config/config.go`:
- [SUGGESTION] config/config.go:762-763: New config comment misstates the meaning of MaxOutgoingConnections = 0
  This PR added '0 means all connections can be outgoing' to the operator-facing P2PConfig comment (and the same wording to the generated template in config/toml.go). That is true only at the internal PeerManagerOptions layer (internal/p2p/peermanager.go:150-156). At the config layer, node/setup.go:240-246 maps MaxOutgoingConnections == 0 to maxConns/2 before constructing PeerManagerOptions, so an operator setting max-outgoing-connections = 0 gets 32 outgoing slots with the default 64 max connections, not unlimited. Fix the comment in both places to describe the actual fallback.
Out-of-scope follow-up suggestions (2)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • PeerManager.HasDialedMaxPeers is dead code with stale semantics — Out of scope — pre-existing dead code with no callers; this PR does not touch it and its counting semantics do not affect the new dial path. Routine cleanup, not required for this PR's goal.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.
  • PeerManagerOptions.Validate can underflow uint16 when MaxConnectedUpgrade exceeds MaxConnected — Out of scope — pre-existing Validate arithmetic not changed by this PR; production configuration (MaxConnectedUpgrade=4, MaxOutgoingConnections validated separately) cannot trigger it. Speculative hardening for a separate issue.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.

Comment thread config/config.go Resolved
@lklimek
lklimek enabled auto-merge (squash) September 22, 2026 06:21
@lklimek

lklimek commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@github-actions

Copy link
Copy Markdown

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

@github-actions github-actions Bot removed the waiting-bots Waiting for the review bots to report on this head label Sep 22, 2026
@lklimek
lklimek merged commit a6c410c into v1.8-dev Sep 22, 2026
25 checks passed
@lklimek
lklimek deleted the fix/issue-1039 branch September 22, 2026 06:28
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.

Persistent peers setting does not work

3 participants