Skip to content

Fix leaderboard min cache corruption under ties in update_top_players (closes #70) - #117

Open
Paranoa-dev wants to merge 1 commit into
SPulse-Org:mainfrom
Paranoa-dev:fix/issue-70
Open

Fix leaderboard min cache corruption under ties in update_top_players (closes #70)#117
Paranoa-dev wants to merge 1 commit into
SPulse-Org:mainfrom
Paranoa-dev:fix/issue-70

Conversation

@Paranoa-dev

Copy link
Copy Markdown

Fix leaderboard min cache corruption under ties in update_top_players

Closes #70

Summary

The leaderboard maintained MinPoints/MinSlot incrementally, 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)

  • Added 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).
  • Changed the full-path eviction condition from new_points > min_points to new_points >= min_points so equal-scoring players can displace an equal-min entry instead of being rejected.

Test (leaderboard/src/ttl_tests.rs)

  • Added 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).

…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.
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.

[MEDIUM] upsert_top append path uses < instead of <= for min tracking — equal-points players corrupt the min cache

1 participant