Skip to content

Isolate PRISM share hot-path locking - #83

Merged
kiwidream merged 3 commits into
1.x.xfrom
isolate-prism-share-locks
Jul 21, 2026
Merged

kiwidream merged 3 commits into
1.x.xfrom
isolate-prism-share-locks

Conversation

@kiwidream

@kiwidream kiwidream commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • isolate recent-share deduplication, share counters, and per-client Vardiff state from the coordinator control-plane lock
  • keep block-candidate retries watchdog-visible with sliced heartbeat waits and explicit attempt tracking
  • expose bounded lock-contention, pending-candidate age, first-attempt age, and retry-state metrics
  • add deterministic concurrency, socket-stall, watchdog, and 600-client stress coverage

Testing

  • Docker Python 3.12: python -m unittest tests.test_prism_hot_path tests.test_prism_share_ledger tests.test_prism_coordinator_vardiff (413 tests)
  • python3 -m unittest tests.test_prism_coordinator_job_cache tests.test_prism_initial_job_delivery tests.test_prism_tip_refresh_validation tests.test_prism_coordinator_shutdown (186 tests)
  • Docker Python 3.12 compile/lint: python -m compileall -q docker lab tests examples scripts
  • git diff --check

Note

High Risk
Changes lock ordering and share/block submission concurrency in the mining coordinator; regressions could affect tip publication, duplicate detection, or block-candidate durability, though coverage targets those paths explicitly.

Overview
Reduces coordinator lock convoys on the Stratum share path by moving recent-share dedup, global share counters/rejections, and per-connection Vardiff state onto dedicated locks, with a fixed rule that vardiff_lock is taken before self.lock on job delivery and idle retarget paths.

Normal mining.submit now does one control-plane snapshot (pool_closed, job context, published tip) instead of multiple coordinator acquisitions; duplicate-share tracking and accounting no longer run under the global lock.

The coordinator lock becomes _ObservedRLock with Prometheus contention/wait metrics. Block-candidate retries use sliced heartbeat waits during backoff (so intentional sleeps refresh the submitter watchdog but stuck RPC/SQL does not), mark_block_candidate_attempted at processing entry (ledger/outbox), and new gauges for pending candidate age and retry backoff state.

Reviewed by Cursor Bugbot for commit 406e9e9. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread lab/prism/prism_coordinator.py Resolved
@kiwidream
kiwidream merged commit b002caa into 1.x.x Jul 21, 2026
9 checks passed

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 406e9e9. Configure here.

key = (label, reason)
self.worker_rejection_counts[key] = (
int(self.worker_rejection_counts.get(key, 0)) + 1
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Share metrics lock-order deadlock

High Severity

record_rejection takes _share_accounting_lock then worker_metrics_lock, while note_worker_accepted_share takes worker_metrics_lock then _share_accounting_lock for stale-grace credits. Concurrent reject and grace-accept paths can deadlock and stall share handling.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 406e9e9. Configure here.

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.

1 participant