Curtailment: Enable end-to-end curtailment confirmation with dev-stack fake miners#812
Conversation
🔐 Codex Security Review
Review SummaryOverall Risk: NONE FindingsNo findings in the scoped diff. NotesReviewed Generated by Codex Security Review | |
There was a problem hiding this comment.
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
statsand align both RPC/HTTP telemetry to report mode-dependentchain_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. |
There was a problem hiding this comment.
💡 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".
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
Curtailedstate 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
statswith the firmware metadata and mining-stat records expected by the Antminer plugin, including dynamicchain_powerat approximately 3,250 W while mining and 30 W while sleeping. HTTP stats report the same power value for consistency.Diagrams
Areas of the code involved
plugin/proto/internal/device/plugin/proto/pkg/proto/curtailedas healthy-inactive, and exposes the curtail-specific stop call.server/fake-proto-rig/server/fake-antminer/statsand reports mode-dependent power through RPC and HTTP.PowerWatts.Key technical decisions & trade-offs
Curtailedprecedence over the pool-derivedNoPoolspresentation so telemetry can expose the temporary low-power state, then return toNoPoolsafter restore.chain_powercontract instead of introducing a fake-only power field or changing the production parser.Testing & validation
golangci-lint, package/unit tests, andgo build ./....golangci-lint.GOWORK=off go test --count=1 .in bothserver/fake-antminerandserver/fake-proto-rig.go test --count=1 ./pkg/antminer/...inplugin/antminer.just test-contractcould not start because Cargo, required by its asicrs prerequisite, is not installed locally.just devcurtailment lifecycle and Docker E2E suites were not run locally.Closes #709