Skip to content

Curtailment: Enable end-to-end curtailment confirmation with dev-stack fake miners#812

Open
negarn wants to merge 2 commits into
mainfrom
negar/gh-709-curtailment-enable-end-to-end-curtailment-confirmation-with-dev-stack-fake-miners
Open

Curtailment: Enable end-to-end curtailment confirmation with dev-stack fake miners#812
negarn wants to merge 2 commits into
mainfrom
negar/gh-709-curtailment-enable-end-to-end-curtailment-confirmation-with-dev-stack-fake-miners

Conversation

@negarn

@negarn negarn commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Reviewable diff: +165/-56 across 7 files (excludes generated, test, and story files).

Summary

This PR lets the local dev-stack fake Proto and Antminer devices produce the power transitions required for end-to-end curtailment confirmation. Full curtailment now reports minimal draw, while restore returns each device to mining or idle power according to its pre-curtail state, including pool-less and intentionally stopped Proto devices.

How it works

For Proto devices, the plugin snapshots whether the miner was active before full curtailment and marks the stop request as curtailment intent. The fake rig uses that marker to enter a distinct Curtailed state at approximately 30 W; ordinary stop remains an idle state at approximately 200 W. During restore, the plugin starts devices that were mining and sends an ordinary stop to devices that were not, moving them out of curtailment without incorrectly starting hash production.

For Antminers, the existing sleep/wake workflow remains the control path. The fake cgminer server now implements stats with the firmware metadata and mining-stat records expected by the Antminer plugin, including dynamic chain_power at approximately 3,250 W while mining and 30 W while sleeping. HTTP stats report the same power value for consistency.

Diagrams

flowchart TD
  A["Curtailment reconciler dispatches FULL"] --> B["Miner plugin command"]
  B --> C["Proto plugin snapshots mining state"]
  B --> D["Antminer plugin selects sleep mode"]
  C --> E["POST mining/stop with curtailment marker"]
  E --> F["Fake Proto rig reports Curtailed and about 30 W"]
  D --> G["Fake Antminer enters sleep mode"]
  G --> H["cgminer stats reports chain_power about 30 W"]
  F --> I["Persisted telemetry confirms target"]
  H --> I
  I --> J["Restore dispatch"]
  J --> K["Previously mining devices start or wake"]
  J --> L["Previously idle Proto devices receive ordinary stop"]
  K --> M["Mining power returns"]
  L --> N["Idle power returns without hashing"]
Loading
stateDiagram-v2
  [*] --> Mining
  [*] --> Idle
  Mining --> Curtailed: FULL curtail
  Idle --> Curtailed: FULL curtail
  Curtailed --> Mining: restore previous mining state
  Curtailed --> Idle: restore previous non-mining state
Loading

Areas of the code involved

Area / package / file What changed Why it matters for review
plugin/proto/internal/device/ Marks full-curtail stop requests and restores both active and inactive pre-curtail states explicitly. Defines the production command semantics used to return low-power curtailed devices to their prior state.
plugin/proto/pkg/proto/ Adds optional request headers, maps curtailed as healthy-inactive, and exposes the curtail-specific stop call. Carries curtailment intent across the HTTP boundary while preserving normal stop behavior.
server/fake-proto-rig/ Separates mining, idle, and curtailed power; allows curtailment to remain visible on pool-less rigs. Supplies truthful telemetry for both confirmation and restore without starting pool-less devices.
server/fake-antminer/ Implements cgminer stats and reports mode-dependent power through RPC and HTTP. Matches the actual Antminer parser path used to populate PowerWatts.
Focused tests Covers Proto restore intent, request marking, fake Proto power states, and Antminer RPC/HTTP power. Pins the state transitions and parser-facing response shapes used by confirmation.

Key technical decisions & trade-offs

  • Reuse the existing Proto mining-stop endpoint with a backward-compatible request marker instead of adding a simulator-only endpoint; normal manual stop remains distinguishable from full curtailment.
  • Issue an ordinary stop when restoring a previously non-mining Proto device instead of doing nothing; the redundant command is idempotent and moves the fake from curtailed draw back to idle draw.
  • Give Curtailed precedence over the pool-derived NoPools presentation so telemetry can expose the temporary low-power state, then return to NoPools after restore.
  • Match the Antminer plugin's existing second-record chain_power contract instead of introducing a fake-only power field or changing the production parser.
  • Keep virtual-miner handle persistence and load-test behavior out of scope; this change targets the process-backed dev-stack fake miners.

Testing & validation

  • Passed Proto plugin formatting, golangci-lint, package/unit tests, and go build ./....
  • Passed server golangci-lint.
  • Passed GOWORK=off go test --count=1 . in both server/fake-antminer and server/fake-proto-rig.
  • Passed go test --count=1 ./pkg/antminer/... in plugin/antminer.
  • The full Proto plugin test command reached the Docker integration package after all package/unit tests passed, but the local Docker connection closed while creating its container.
  • just test-contract could not start because Cargo, required by its asicrs prerequisite, is not installed locally.
  • The complete just dev curtailment lifecycle and Docker E2E suites were not run locally.

Closes #709

@negarn
negarn requested a review from a team as a code owner July 24, 2026 17:47
Copilot AI review requested due to automatic review settings July 24, 2026 17:47
@github-actions github-actions Bot added the review-policy: needs-review Managed by the Review Policy workflow. label Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated security-focused code review generated by Codex.
It should be used as a supplementary check alongside human review.
False positives are possible - use your judgment.

Scope summary

  • Reviewed pull request diff only (82e63b2908493a8f853d15dd83993ecdefd24742...e65a971abfeb84685971370dc54a5990fb4d2e2d, exact PR three-dot diff)
  • Model: gpt-5.5

💡 Click "edited" above to see previous reviews for this PR.


Review Summary

Overall Risk: NONE

Findings

No findings in the scoped diff.

Notes

Reviewed .git/codex-review.diff only, as requested. The changes are concentrated around Proto full-curtailment restore behavior, fake Proto rig curtailed telemetry, and fake Antminer power reporting for stats/RPC responses. I did not identify a concrete security, correctness, or reliability issue introduced by these hunks.


Generated by Codex Security Review |
Triggered by: @negarn |
Review workflow run

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.

Pull request overview

Enables end-to-end curtailment confirmation in the local dev stack by making the fake Proto rig and fake Antminer expose realistic, mode-dependent power telemetry, and by teaching the Proto plugin to explicitly distinguish “full curtailment stop” from an ordinary stop so restore can return devices to their pre-curtail intent (mining vs non-mining).

Changes:

  • Proto plugin: mark full-curtail stop requests via an HTTP header and restore to either mining or idle (via a deliberate stop) based on the pre-curtail snapshot.
  • Fake Proto rig: introduce distinct mining/idle/curtailed power draw and ensure “Curtailed” remains visible even when pool-less.
  • Fake Antminer: implement cgminer RPC stats and align both RPC/HTTP telemetry to report mode-dependent chain_power.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
server/fake-proto-rig/rest_api_handler.go Detects full-curtail intent via X-Proto-Fleet-Curtailment: full on mining stop and records Curtailed.
server/fake-proto-rig/models.go Adds separate idle/curtail power constants; preserves Curtailed visibility for pool-less devices; models distinct power by state.
server/fake-proto-rig/curtailment_power_test.go Tests power/state transitions across mining/idle/pool-less/curtailed and restore behavior.
server/fake-antminer/rpc_handlers.go Adds cgminer RPC stats handling and generates chain_power consistent with work mode.
server/fake-antminer/models.go Introduces mining vs sleep power constants and an effectivePowerWattsLocked helper; adds StatsResponse type.
server/fake-antminer/http_handlers.go Adds chain_power to HTTP stats output using the same mode-dependent power as RPC.
server/fake-antminer/sleep_mode_test.go Extends tests to assert HTTP and RPC stats report expected chain_power in sleep and normal modes.
plugin/proto/pkg/proto/client.go Adds request-header support in the HTTP client and a CurtailMining call that marks full curtailment; maps curtailed health to healthy-inactive.
plugin/proto/pkg/proto/client_test.go Adds coverage for curtailed mining status mapping.
plugin/proto/internal/device/device.go Uses CurtailMining for full curtail; restores non-mining devices by issuing an ordinary stop to exit curtailed state without starting.
plugin/proto/internal/device/device_test.go Adds/updates tests covering restore intent, pool-less restore, and verifying the curtailment marker header is sent.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0857f897ee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread plugin/proto/pkg/proto/client.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-policy: needs-review Managed by the Review Policy workflow. server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Curtailment: Enable end-to-end curtailment confirmation with dev-stack fake miners

2 participants