feat: expose cumulative round work (total_work) per participant - #486
Closed
mrv777 wants to merge 2 commits into
Closed
feat: expose cumulative round work (total_work) per participant#486mrv777 wants to merge 2 commits into
mrv777 wants to merge 2 commits into
Conversation
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.
4 tasks
Contributor
|
I attempted to avoid that history |
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
Adds a
total_workfield to the round-participation endpoints: the counted cumulative accepted work (sum of share difficulty,SUM(diff)) each user contributed in a round, alongside the existingtop_diff(which isMAX(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
RoundParticipantgainstotal_work, populated fromCOALESCE(SUM(diff), 0)with the samereject_reason IS NULLaccepted-share filter used fortop_diff.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_historygets atotal_workcolumn.round_participation_currentmatview now selectsSUM(diff).idx_remote_shares_round_participationwidened toINCLUDE (sdiff, diff)soSUM(diff)stays an index-only scan.ADD COLUMNif missing, thenTRUNCATEonce so previously-snapshotted rounds lazily recompute with work fromremote_shareson next read.diff.Notes
SUM(diff)is robust to thecompress_sharescompaction (which already storesSUM(diff)per worker+blockheight), so historical rounds compute correctly.diff(credited difficulty) is the right column for "work" — it matches the PPLNSSUM(diff)and is in difficulty-1-share-equivalent units.Testing
cargo build --testsandcargo fmt --checkpass.tests/server_with_db.rs) to asserttotal_workfor historical and current rounds; test schema intests/test_psql.rsupdated to match. (DB integration tests arecfg(linux), so they run in CI.)