Repository navigation
Cut hashrate-weighted staleness in PRISM tip-refresh fanout - #98
Conversation
The tip-refresh wave admitted job-less clients first and the rest in arbitrary set order. A job-less client burns zero hashrate while it waits, but a stale client burns its full rate on old-tip work, so serving newcomers first anti-optimized hashrate-weighted staleness across the multi-second wave. Admit clients in descending per-client hashrate order instead, using the vardiff difficulty estimate (share_difficulty fallback) as the proxy: vardiff targets a uniform share interval, so sustained difficulty is proportional to hashrate. Proxies are snapshotted under the coordinator lock in the same pass as the expected-active-jobs snapshot to avoid torn reads. Job-less clients keep their initial-delivery queue priority; the separate initial-job executor is untouched. Co-Authored-By: Claude Fable 5 <[email protected]>
Both retarget send sites passed clean_jobs=True, so every same-tip difficulty change discarded the miner's in-flight work even though per-job stamped share targets already validate old-job shares at the difficulty they were mined against. Flush only on a step-down (clean_jobs = next < current): firmware that applies mining.set_difficulty retroactively would otherwise submit sub-target shares against the old job. Step-ups now send a non-clean job, keeping the old job registered and submittable at its own stamped difficulty. Idle retargets only fire on zero-share windows and thus always step down, so their flush behavior is unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
ensure_reorg_reconciled_for_tip on the poll path was the only serial pre-build stage with no phase metric, leaving ops blind to whether it holds material wall time in the refresh critical path. Time the call and report it as phase="reorg_reconcile" in the existing qbit_prism_tip_refresh_bundle_phase_seconds histogram. The observation lands in a finally block so blocked or failed reconciles are visible too, not just successful ones. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8c14f8f. Configure here.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c14f8f8af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A job-less client burns zero hashrate while it waits regardless of its configured difficulty, so a high static-difficulty newcomer must not outrank stale active miners in fanout admission. Rank stale-job clients by descending hashrate proxy and admit job-less clients after them; their initial-delivery queue priority is unchanged. Reported by Cursor Bugbot on PR #98. Co-Authored-By: Claude Fable 5 <[email protected]>
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This branch already carries the #99 content (based on prism-cache-persist at b289550, the exact head that squash-merged) plus the earlier #98 merge, so the 'ours' tree is the correct union by construction; the merge only records ancestry and collapses the PR diff to this branch's own changes. Co-Authored-By: Claude Fable 5 <[email protected]>

Summary
Three independent PRISM coordinator changes, one commit each, aimed at cutting hashrate-weighted staleness after chain-tip changes across the ~350-client mainnet fleet, plus visibility into the one unmeasured serial stage of the refresh path.
1. Hashrate-ordered fanout admission
The tip-refresh wave admitted clients without an active job first and the rest in arbitrary set order. A job-less client burns zero hashrate while it waits for work, but a stale-job client burns its full rate on old-tip work, so newcomer-first admission anti-optimized hashrate-weighted staleness over the multi-second wave.
Admission now sorts stale-job clients by a descending per-client hashrate proxy (vardiff_difficulty_estimate, falling back to share_difficulty before an estimate exists) and admits job-less clients after them: a job-less client burns no hashrate while it waits, regardless of its configured difficulty. Vardiff drives every client toward the same share interval, so sustained difficulty is proportional to hashrate. Proxies are snapshotted under the coordinator lock in the same pass that snapshots expected active jobs, avoiding torn reads. Job-less clients keep their initial-delivery executor queue priority, and the separate initial-job executor path is untouched.
2. No-flush vardiff step-up retargets
Both retarget send sites passed clean_jobs=True, flushing the miner's in-flight work on every same-tip difficulty change. Per-job stamped share targets already validate old-job shares at the difficulty they were mined against, and non-clean sends keep old jobs registered — eviction happens only under the clean_jobs branches.
clean_jobs is now next_difficulty < current_difficulty: step-ups keep the old job submittable at its own stamped difficulty; step-downs still flush to protect firmware that applies mining.set_difficulty retroactively, which would otherwise submit sub-target shares against the old job. Idle retargets fire only on zero-share windows and therefore always step down, so their flush behavior is unchanged.
3. reorg_reconcile phase metric
ensure_reorg_reconciled_for_tip on the poll path was the only serial pre-build stage with no phase metric. It is now timed and reported as phase="reorg_reconcile" in qbit_prism_tip_refresh_bundle_phase_seconds. The observation lands in a finally block so blocked or failed reconciles show up too, not just successful ones.
Tests
Validation
Security and operational impact
No schema, dependency, configuration, authentication, or external API changes. Fanout ordering changes only intra-wave admission order; total work delivered is unchanged. Step-up retargets now leave the previous job submittable until the existing per-client retention cap or the next clean send prunes it; share validation against retained jobs is unchanged and already difficulty-stamped per job. The new histogram label adds a fixed set of series to an existing metric.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes tip-refresh delivery order and vardiff retarget flushing behavior on live stratum paths; share validation logic is unchanged but miners may retain more concurrent jobs until caps or clean sends.
Overview
Reduces hashrate-weighted staleness after tip changes on large fleets by changing how tip-refresh fanout admits clients, how vardiff retargets flush work, and what the refresh path measures.
Tip-refresh fanout no longer admits job-less clients before everyone else. Clients are sorted by stale-job presence and descending hashrate proxy (
vardiff_difficulty_estimate, elseshare_difficulty), snapshotted under the coordinator lock with job snapshots. Job-less miners still get initial-delivery queue priority when admitted, but fast stale clients are served first in the wave.Vardiff same-tip retargets set
clean_jobsonly on step-down (next_difficulty < current_difficulty). Step-ups send a non-clean job so in-flight work on the old stamped target stays valid; step-downs still flush for firmware that applies difficulty retroactively.Poll path times
ensure_reorg_reconciled_for_tipand recordsphase="reorg_reconcile"inqbit_prism_tip_refresh_bundle_phase_seconds(including failures viafinally).Reviewed by Cursor Bugbot for commit e452ca0. Bugbot is set up for automated code reviews on this repo. Configure here.