Skip to content

feat: expose cumulative round work (total_work) per participant - #486

Closed
mrv777 wants to merge 2 commits into
parasitepool:masterfrom
mrv777:feat/round-total-work
Closed

feat: expose cumulative round work (total_work) per participant#486
mrv777 wants to merge 2 commits into
parasitepool:masterfrom
mrv777:feat/round-total-work

Conversation

@mrv777

@mrv777 mrv777 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a total_work field to the round-participation endpoints: the counted cumulative accepted work (sum of share difficulty, SUM(diff)) each user contributed in a round, alongside the existing top_diff (which is MAX(sdiff), i.e. best share).

This is the real, counted work — the same quantity the PPLNS payout path already sums. Exposing it means consumers (parastats) no longer have to estimate work by integrating hashrate samples over time. Summed across the current round it is also the pool-wide work since the last block.

What changed

  • RoundParticipant gains total_work, populated from COALESCE(SUM(diff), 0) with the same reject_reason IS NULL accepted-share filter used for top_diff.
  • Updated all four code paths in database.rs: the current-round materialized view query, the history-table read, the live fallback query, and the history snapshot insert.
  • bin/postgres-init:
    • round_participation_history gets a total_work column.
    • round_participation_current matview now selects SUM(diff).
    • Covering index idx_remote_shares_round_participation widened to INCLUDE (sdiff, diff) so SUM(diff) stays an index-only scan.
  • All schema changes are idempotent migrations so existing deployments upgrade in place:
    • history table: ADD COLUMN if missing, then TRUNCATE once so previously-snapshotted rounds lazily recompute with work from remote_shares on next read.
    • matview: dropped & recreated only if it predates the column.
    • index: dropped & recreated only if it doesn't already cover diff.

Notes

  • SUM(diff) is robust to the compress_shares compaction (which already stores SUM(diff) per worker+blockheight), so historical rounds compute correctly.
  • diff (credited difficulty) is the right column for "work" — it matches the PPLNS SUM(diff) and is in difficulty-1-share-equivalent units.

Testing

  • cargo build --tests and cargo fmt --check pass.
  • Extended the round-participation integration tests (tests/server_with_db.rs) to assert total_work for historical and current rounds; test schema in tests/test_psql.rs updated to match. (DB integration tests are cfg(linux), so they run in CI.)

Add a total_work field (SUM of accepted share difficulty) to the round
participation endpoints alongside the existing top_diff (MAX). This is the
real, counted work each user contributed in a round — and summed across the
current round, the pool-wide work since the last block — so consumers no
longer have to estimate it by integrating hashrate samples over time.

- RoundParticipant gains total_work, populated from COALESCE(SUM(diff), 0)
- Extend the current-round matview, history table, live query and snapshot
- Widen the covering index INCLUDE to (sdiff, diff) for index-only SUM(diff)
- Idempotent migrations in postgres-init for existing deployments
- Tests assert total_work for historical and current rounds
The height-3 share belongs to the previous round (block 5 was found), so
foo's current-round work is 2000 (height-7 share only), consistent with the
existing blocks_participated == 1 and top_diff == 2000 assertions.
@parabitdev

Copy link
Copy Markdown
Contributor

I attempted to avoid that history total_work coloumn, but in the end it proved vital. Thank you for your work on this.

@parabitdev parabitdev closed this Jul 1, 2026
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.

2 participants