feat(cloud): push per-miner state alongside snapshots#11
Merged
Conversation
The desktop already aggregates ASIC, mobile, and PoPMiner state every 60s to build the farm-rollup snapshot, but only the rollup was being pushed to the cloud. The miner_states table on the portal stayed empty, so the web Dashboard's "Total Miners" tile rendered 0 even when miners were online. Wire push_miners (already present in client.rs) into the sync loop: - Add CloudState.latest_miners staging slot, mirroring latest_snapshot. - Build the /ingest/miners payload at the end of build_and_persist_snapshot in poller.rs from the same ASIC + mobile + PoPMiner data the rollup uses. Map each source to the asic/mobile/popminer enum the server expects. - Push latest_miners in sync.rs right after the snapshot push; on transient failure, enqueue with kind "miners". Extend the queue drain branch and the SQLite CHECK constraint (with a one-shot migration for existing installs) to handle the new kind. Phase 2 vertical-slice only — alert sync, command exec, etc. remain TODO.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wire the existing
client::push_minersinto the cloud sync loop so the portal'sminer_statestable gets populated. Until now, the desktop pushed farm-rollup snapshots but never pushed per-miner state, so the web Dashboard's "Total Miners" tile always read 0 even when miners were online.This is a Phase 2 vertical-slice: capture local miner data → stage on
CloudState→ push from sync loop → queue/drain on transient failure. Full Phase 2 scope (alert sync, command exec, etc.) is still pending — intentionally not in this PR.What changed
src-tauri/src/cloud/mod.rs— Addedlatest_miners: Mutex<Option<serde_json::Value>>toCloudState, initialized toNone. Direct mirror of the existinglatest_snapshotfield.src-tauri/src/poller.rs—build_and_persist_snapshotnow also calls a newstage_miners_for_cloud(...)after persisting the rollup. That helper takes the same ASIC + mobile + PoPMiner inputs the rollup already uses, maps each into{ minerType, minerId, label, coin, online, hashrate, state }, and writes the result toCloudState.latest_miners. The poller'ssnapshot_loopnow takesPopMinerDevicesState(previously discarded as_popminer_state).src-tauri/src/cloud/sync.rs— Added a second push step right after the snapshot push:take()fromlatest_miners, callpush_miners, on transient failure enqueue with kind"miners", on 401/403 setAuthRequired. Extended the queue drain match to handle"miners"items.src-tauri/src/cloud/queue.rs— Relaxed theCHECKconstraint to include'miners', plus a one-shot migration for existing installs (SQLite can't ALTER a CHECK, so we rebuild the table when the existing definition is missing'miners').Local capture path
The local data source was already there:
poller::build_and_persist_snapshotcollectsasic(Vec<MinerInfo>) fromcache.asic_miners,mobile_minersfrommobile_state.miners, and nowpopminer_devicesfrompopminer_state.saved. No new polling logic; we just serialize what the rollup already iterates over into the/ingest/minersshape.Minor type mapping
minerType: "asic",minerId: ip, label from saved miner or hostname, coin from saved miner.minerType: "mobile",minerId: device_id, hashrate stays in H/s (no conversion).minerType: "popminer",minerId: mac, coin omitted (no per-device coin on the ESP32 side yet).The full miner record (model, firmware, temps, etc.) goes into the optional
statefield for portal display.Build verification
cd src-tauri && cargo checkpasses cleanly (no new warnings; pre-existing dead-code warnings unchanged).Test plan
pnpm tauri devor release build), log in, add at least one ASIC/mobile/PoPMiner miner.Cloud: miners staged for sync (N entries)followed byCloud sync: miner state pushed successfullyon the next 60s cycle.cloud-api.proofofprints.combriefly and confirm aminersrow appears in the local queue (cloud_queue.db); restore connectivity and confirm the queue drains.