Repository navigation
fix(statesync): correlate consensus parameter replies with pending requests - #1491
Conversation
…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>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository: dashpay/tenderdash/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
|
There was a problem hiding this comment.
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.
- 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]>
|
/self-reviewed |
thepastaclaw
left a comment
There was a problem hiding this comment.
⚠️ DEGRADED — Final validation — Phase 1 + Phase 2
⚠️ DEGRADED review. The primary review models were unavailable (gpt-6-astraunavailable: 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 athigheffort. 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-astraunavailable: 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-insgpt-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 athigh - Triage:
normalbymuse-spark-1.3-contributor(standing in forgpt-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); agentphase1-reviewer,glm-5.3-flash— tenderdash-consensus-security (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 80% left, weekly 96% left; passed overgemini-3.8-flash-high(lane failed) - Fresh verifier:
muse-spark-1.3-contributor(standing in forgpt-6-astra) — final-verifier; agentastra-verifier - Phase 2 reviewers:
muse-spark-1.3-contributor(standing in forgpt-6-astra) — general (completed, effort high); agentphase2-reviewer,muse-spark-1.3-contributor(standing in forgpt-6-astra) — tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
|
Bots are done — your move: post |
|
/self-reviewed |
|
Policy satisfied — this can merge. |
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?
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.
internal/statesyncpackage tests and race tests passed during implementation (-tags=deadlock -p 1).go test -race -p 1 -tags=deadlock ./internal/statesync -run '^TestParams|^TestVerifyConsensusParams|^TestReactor_(Sync|StateProviderP2P)$' -count=1 -timeout=120s -v.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:
No user-facing configuration or interface documentation changes are needed.
For repository code-owners and collaborators only
🤖 Co-authored by Claudius the Magnificent AI Agent
PR Hygiene ·
3279ffeWhen every box is checked the
PR Hygienecheck passes and this can merge.