Fix leaderboard min cache corruption under ties in update_top_players (closes #70) - #117
Open
Paranoa-dev wants to merge 1 commit into
Open
Fix leaderboard min cache corruption under ties in update_top_players (closes #70)#117Paranoa-dev wants to merge 1 commit into
Paranoa-dev wants to merge 1 commit into
Conversation
…SPulse-Org#70) The incremental MinPoints/MinSlot maintenance was unsound under ties: it tracked a single (points, slot) pair and could not represent two players sharing the minimum, so the cached MinSlot could point at the wrong entry and equal-scoring players corrupted the cache. The full-path eviction also used a strict greater-than that wrongly rejected players whose score equalled the current minimum. - Add recompute_min which scans the bounded top list and picks the tie-aware minimum (lowest slot index on ties), replacing all three ad-hoc min updates. - Change the full-path eviction condition from > to >= so equal-min players can displace an equal-min entry. - Add a regression test covering equal-min displacement and that below-min scores are still rejected. All existing leaderboard tests pass.
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.
Fix leaderboard min cache corruption under ties in
update_top_playersCloses #70
Summary
The leaderboard maintained
MinPoints/MinSlotincrementally, which is unsound when two players share the minimum score. The single-slot cache could point at the wrong entry, and the full-path eviction used a strict>that wrongly rejected a player whose score equalled the current minimum (so they could never displace an equal-min entry).Changes (
leaderboard/src/lib.rs)recompute_min(env)which scans the bounded (MAX_TOP_PLAYERS) top list and selects the true minimum, using the lowest slot index on ties for deterministic tie-breaking. It replaces all three ad-hoc min-cache updates (existing-user update, append, and full-path eviction).new_points > min_pointstonew_points >= min_pointsso equal-scoring players can displace an equal-min entry instead of being rejected.Test (
leaderboard/src/ttl_tests.rs)test_equal_min_players_do_not_corrupt_min_cache: fills the board, then verifies two equal-min newcomers each displace an equal-min entry (cache value stays correct) and that a strictly-below-min score is still rejected.Verification
cargo test -p leaderboard→ 7 passed (6 existing + 1 new).