Skip to content

Use per-user cached windows for O(1) rate-limit cooldown reads#115

Merged
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
LaGodxy:fix/issue-65-bitshift-rate-limits
Jul 21, 2026
Merged

Use per-user cached windows for O(1) rate-limit cooldown reads#115
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
LaGodxy:fix/issue-65-bitshift-rate-limits

Conversation

@LaGodxy

@LaGodxy LaGodxy commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Implemented per-user cached window boundaries for O(1) cooldown reads in the rate limiter, as requested in the issue.

Changes

  • rate_limit.rs: Changed hourly_cached and daily_cached cache keys from bare symbol to (user, symbol) tuple, making cached window boundaries per-user instead of global
  • Updated all 6 call sites: check_swap_limit, record_swap, check_lp_limit, record_lp_op, get_swap_status, get_lp_status
  • Existing bit-shift optimization in fast_window preserved
  • cleanup_rate_limits already O(1), no changes needed
  • Verified formatting
  • No unrelated changes introduced

Closes #65

Make hourly_cached and daily_cached use per-user storage keys so each
user's cached window boundary is independent. This eliminates cross-user
cache invalidation and makes cooldown_ms reads O(1) per user.

- Changed cache key from bare symbol to (user, symbol) tuple
- Updated all 6 call sites (check/record/status for swap and LP)
- Existing bit-shift optimization in fast_window preserved
- cleanup_rate_limits already O(1), no changes needed

Closes OpenPeerX#65

@ameeribro4-sudo ameeribro4-sudo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ameeribro4-sudo
ameeribro4-sudo merged commit 2a88302 into OpenPeerX:main Jul 21, 2026
3 checks passed
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.

[PeerX Backlog # 65] Use bit shifts for power-of-two rate-limit windows

2 participants