chore(faucet): token-bucket rate limiting via reliakit-ratelimit#789
Conversation
|
Warning Review limit reached
More reviews will be available in 46 minutes and 13 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Replace the per-IP sliding-window Vec<Instant> (which grew per IP, and whose own doc comment already called it a "token bucket") and the hand-rolled per-recipient last-timestamp cooldown with reliakit-ratelimit::RateLimiter: - per-IP: max_drips per window with a burst allowance - per-recipient: a 1-token-per-cooldown bucket - O(1) memory per key, precise Retry-After hints The DashMap entry guard still holds the per-key lock across try_acquire_one, so the cooldown TOCTOU fix is preserved. Non-consensus (faucet binary only); no version bump.
d7cf2f1 to
e8ebc85
Compare
What
Adopt
reliakit-ratelimit(one of the reliakit resilience crates) in thetestnet faucet, replacing two hand-rolled limiters.
Vec<Instant>that grew per IP — the doccomment already called it a token bucket, so this aligns the code with its
stated intent. Now
RateLimiter::new(max_drips, 1, window/max_drips):max_dripsper window with a burst allowance, O(1) memory per IP.1-token bucket refilling every cooldown.
Retry-Afterhints fromRateLimiter::retry_after.Why it's safe
Entryguard to stop two parallel requests for the same address from bothpassing. The new code keeps that guard —
entry(..).or_insert_with(..)holdsthe per-key shard lock across
try_acquire_one, so refill+consume is atomic.git revert.Tests
4 unit tests on the bucket mapping (burst-then-block, zero-max clamp,
one-per-cooldown, retry_after remaining).
sentrix-faucetgreen underRUSTFLAGS="-D warnings".No workspace version bump (avoids colliding with the concurrent #788 bump);
changelog note under
[Unreleased].