Repository navigation
fix(statesync): bound retained snapshot discovery resources - #1492
Conversation
Preserve legal 4 MB advertisements while enforcing owned payload budgets, bounded accounting and request allowances. Keep active payload charged through fetcher cleanup and rotate finite discovery sweeps under pressure. Co-Authored-By: GPT-6 Astra <[email protected]> <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Clarify association release and separate global charges when the active snapshot has been removed and another owned copy is admitted. Co-Authored-By: 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 |
|
|
Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Blacklisted peers can still consume discovery batch slots, and the generated configuration template documents stale retry semantics.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Bounds retained snapshot memory, associations, bookkeeping, and discovery response work while preserving legal snapshot message sizes.
Changes:
- Added bounded snapshot pool accounting, ownership, eviction, and active-snapshot pinning.
- Added directed, allowance-limited discovery batches and fetcher cleanup synchronization.
- Documented resource limits and updated discovery configuration comments.
| File | Description |
|---|---|
internal/statesync/snapshots.go |
Pool limits and discovery accounting |
internal/statesync/syncer.go |
Bounded requests and lifecycle cleanup |
internal/statesync/reactor.go |
Response allowance enforcement |
internal/statesync/dispatcher.go |
Safe peer-list copying |
internal/statesync/snapshot_limits_test.go |
Pool limit regressions |
internal/statesync/snapshot_discovery_test.go |
Discovery and lifetime regressions |
internal/statesync/snapshot_unsolicited_test.go |
Unsolicited response regression |
docs/nodes/state-sync.md |
Resource and discovery documentation |
config/config.go |
Retry and sweep semantics documentation |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
An advertisement with an empty hash was admitted at no byte cost, ranked first by height, and made newChunkQueue fail, which shut the node down. Reject it in the pool before hashing. Also log (at debug) advertisements dropped by the discovery allowance and peers skipped by a full batch, unify the pooled-key lookup, and tidy the new tests. Co-Authored-By: Claude Sonnet 5 <[email protected]>
The config template and docs still described retries as a retry count after it became the number of completed discovery sweeps. Document the per-batch cost and that restoration starts from the first batch's best snapshot. Co-Authored-By: Claude Sonnet 5 <[email protected]>
DiscoveryBatch reserved batch slots for rejected peers whose replies are always discarded, wasting slots and discovery intervals. Skip them and fill the batch from the remaining frozen-sweep peers. Co-Authored-By: Claude Sonnet 5 <[email protected]>
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 #1492 bounds snapshot-discovery retention and discovery work as described; both Codex claims were verified against head bcc3051 and do not hold. Retained-bytes accounting stays balanced across detach, re-admission, and release, and the 16-slot request budget is the intentional bound. No in-scope defects remain.
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) — Large intricate state-sync retention/discovery change touches snapshots.go/reactor but preserves wire format and changes no consensus, funds, crypto, deserialization, or migration surface. - 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 85% left, weekly 93% 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 |
|
/self-reviewed |
|
Policy satisfied — this can merge. |


TL;DR: Bound snapshot discovery memory and work while preserving existing legal 4 MB snapshot messages.
User story
As a node operator, I want peers advertising snapshots to use bounded resources while still giving other peers a chance to help my node synchronize.
Scenario
Peers can currently send large snapshot advertisements that remain in memory, with no global limit or requirement for an outstanding request. The node should limit what it retains, ignore excess replies, and make bounded discovery attempts without discarding the snapshot it is restoring.
Detailed discussion
Issue being fixed or feature implemented
Fixes #1475 using the approved local retention and retry policy. No smaller application metadata limit is introduced.
What was done?
How Has This Been Tested?
-p 1 -tags=deadlock: passed.-race -p 1 -tags=deadlock -count=3: passed. Covers near-4 MB serialized messages, shared accounting/removal, active pins, global/per-peer pressure, bounded bookkeeping, duplicate/late/failed replies, peer churn, andretries=1completing a deferred-peer sweep and terminating without responses.-race -count=10: passed.Tests use bounded component fixtures; no full-network OOM or process-RSS benchmark was run. An independent pre-existing snapshot-key field-boundary ambiguity was observed and preserved for follow-up; snapshot identity is unchanged in this PR.
Breaking Changes
No wire, application-format, individual-message-size or persisted-format change. The approved local overload/discovery behavior intentionally changes: old rejection history can expire, unselected candidates can be evicted under pressure, and
retriescounts completed bounded discovery sweeps. A sweep can take up toceil(min(peers, 1024) / 16)discovery intervals, with at least one interval. Existing legal messages remain valid, but overload can defer admission or reduce available suppliers. The 64 MiB bound covers retained pool payload, not total process RSS, transport/in-flight messages, chunks or application memory. Fair admission is not a guarantee against arbitrary Sybil dominance.Checklist:
For repository code-owners and collaborators only
🤖 Co-authored by Claudius the Magnificent AI Agent
PR Hygiene ·
bcc3051When every box is checked the
PR Hygienecheck passes and this can merge.