Repository navigation
fix: shares keyset-pagination cursor can silently skip shares at page boundary - #15
Merged
Merged
Conversation
… boundary PPLNSPaymentScheme, PPLNSBFPaymentScheme and PROPPaymentScheme all page through the shares table via ReadSharesBeforeAsync, resuming each page from the previous page's last row's `created` timestamp with a plain `created < before` filter. Shares are inserted in batches, and `created` timestamp resolution is not fine enough to guarantee every share has a distinct value under load. If the page boundary falls in the middle of a run of shares sharing the exact same `created` timestamp, the shares from that run that didn't make it into the earlier page are permanently excluded from both pages: the next page's `<` filter drops everything at that timestamp, not just the rows already seen. This silently under-credits affected miners' PPLNS/PPLNSBF/PROP reward share, and the equivalent discarded-share accounting/cleanup paths undercount too. Fix: add a `shares.id` BIGSERIAL column (migration add_share_id_column.sql) and use it as a strictly-increasing tiebreaker alongside `created` for both ordering and the page cursor. ReadSharesBeforeAsync now orders by (created DESC, id DESC) and, once a prior page has been read, filters by `created < @before OR (created = @before AND id < @beforeId)`, giving a stable keyset cursor that can't lose rows at a shared timestamp. The first page per run (inclusive=true) is unaffected, since it has no prior cursor to resume from. Added a supporting index (poolid, created DESC, id DESC) and registered the migration with SchemaDriftTests.Every_fork_added_column_has_a_migration_script. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
sharesviaReadSharesBeforeAsync, resuming each page from the previous page's last row'screatedtimestamp with a plaincreated < beforefilter.createdtimestamp resolution isn't fine enough to guarantee uniqueness under load. If a run of shares sharing the exact samecreatedtimestamp straddles a page boundary, the ones that didn't fit in the earlier page are permanently dropped by the next page's<filter — silently under-crediting affected miners' reward share, and undercounting the equivalent discarded-share accounting/cleanup paths.shares.id(BIGSERIAL) as a strictly-increasing tiebreaker.ReadSharesBeforeAsyncnow orders by(created DESC, id DESC)and, for resumed pages, filters bycreated < @before OR (created = @before AND id < @beforeId)— a stable keyset cursor that can't lose rows at a shared timestamp. The first page of each run (inclusive=true) is unaffected since there's no prior cursor.(poolid, created DESC, id DESC), a migration (add_share_id_column.sql), and registered it withSchemaDriftTests.Every_fork_added_column_has_a_migration_script.Test plan
dotnet build— 0 errors (WSL, Release)SchemaDriftTestsrun to confirm the new migration is recognizedadd_share_id_column.sqlagainst a production database before deploying this build (payout schemes will throw ifshares.iddoesn't exist)🤖 Generated with Claude Code