Skip to content

fix(statesync): correlate consensus parameter replies with pending requests - #1491

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

lklimek merged 3 commits into
v1.8-devfrom
fix/issue-1476

Conversation

@lklimek

@lklimek lklimek commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: P2P state sync now ignores unrelated parameter replies immediately and accepts replies only for an outstanding request to that peer and connection.

User story

As a node operator, I want faulty peers to be unable to satisfy another peer's request or stall state-sync message handling.

Scenario

A node requests parameters from a witness while another peer sends unrelated replies. Previously those replies could win the request race or delay message handling by one second. Matching replies now complete requests, and unrelated replies are discarded immediately.

Issue being fixed or feature implemented

Fixes #1476.

What was done?

  • Track outstanding requests by peer, height, and existing local connection generation before sending.
  • Buffer one reply per request, suppress duplicates, and invalidate requests on disconnect or cancellation, including blocked sends.
  • Preserve parallel witness selection/retries and existing trusted hash, semantic, and voting-power threshold validation.

How Has This Been Tested?

The three original regressions failed against the base before implementation. Added coverage for wrong peer/height, old or missing generation, disconnect/reconnect, duplicates, late canceled replies, multiple witnesses, and canceled/blocked sends.

  • Full internal/statesync package tests and race tests passed during implementation (-tags=deadlock -p 1).
  • Final source passed go test -race -p 1 -tags=deadlock ./internal/statesync -run '^TestParams|^TestVerifyConsensusParams|^TestReactor_(Sync|StateProviderP2P)$' -count=1 -timeout=120s -v.
  • Configured golangci-lint v2.13.2 passed on staged changes against the PR base: zero issues.
  • goimports and diff whitespace checks passed. Three self-review passes ended with zero unresolved findings.

Tests used existing BLS native libraries and a writable shared Go cache.

Breaking Changes

None. No wire/protobuf, public API, configuration, or stored-data changes. The existing protocol has no request nonce: retries to the same peer/height/connection remain equivalent semantic requests, subject to unchanged trusted validation. Replies from earlier connection generations cannot satisfy new requests.

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

No user-facing configuration or interface documentation changes are 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

PR Hygiene · 3279ffe

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

…quests

Bind witness replies to outstanding peer, height and connection generation
requests. Discard unrelated replies without blocking the reactor and cancel
pending sends on disconnect. Preserve witness races and trusted validation.

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

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@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: d6f2ef4e-8d14-4648-a12b-b0d393e8aade

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 3279ffe) · 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

Directly constructed exported providers can lack tracker wiring, causing requests to retry until cancellation.

Review effort: Lite
Findings: None

What changed in this PR

This PR correlates P2P state-sync consensus-parameter replies with the requesting peer, height, and connection generation.

Changes:

  • Tracks pending requests and rejects mismatched or stale replies.
  • Handles disconnects, cancellation, duplicates, and blocked sends.
  • Adds extensive request-correlation and lifecycle tests.
File Reviewed changes
internal/​statesync/​stateprovider.go Uses correlated requests and manages cancellation.
internal/​statesync/​reactor.go Routes responses and peer lifecycle updates.
internal/​statesync/​params.go Implements request correlation and duplicate suppression.
internal/​statesync/​params_response_test.go Tests matching, generations, retries, duplicates, and cancellation.

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

@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
- Log received and discarded consensus params replies at debug level;
  paramsRequests.respond now reports whether a reply was delivered.
- Advance the retry backoff only after a sent request times out, so a
  disconnect or a not-connected pass no longer delays re-contacting a
  witness after reconnect; single cleanup path per worker iteration.
- Pass the paramsRequests registry into newP2PStateProvider explicitly,
  drop the type-assertion wiring in setStateProvider and remove the unused
  exported NewP2PStateProvider wrapper, which could never receive peer
  updates.
- Document the paramsRequests concurrency contract and make remove
  return early on a nil request.
- Add tests for the no-stall path with a provider installed, timeout and
  retry cleanup, reconnect generations, and blocked-send cancellation.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@lklimek
lklimek enabled auto-merge (squash) September 21, 2026 14:14
@lklimek

lklimek commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@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 replaces the shared racy params channel with a per-request registry keyed on peer, height, and connection generation, discarding unmatched replies without blocking the receive path. Verification against the exact head confirms the correlation, lifecycle, and downstream validation logic are sound with no in-scope defects.

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) — State-sync p2p request/reply correlation with disconnect and duplicate handling is ordinary concurrent logic plus tests, not a consensus, crypto, funds, deserialization, or migration change.
  • 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 80% left, weekly 96% 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

@github-actions

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Sep 21, 2026
@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-self-review Waiting for the author to post /self-reviewed label Sep 22, 2026
@lklimek
lklimek merged commit 92b5315 into v1.8-dev Sep 22, 2026
21 checks passed
@lklimek
lklimek deleted the fix/issue-1476 branch September 22, 2026 06:24
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.

statesync: correlate ParamsResponse with the requested peer and height

3 participants