Skip to content

chore(faucet): token-bucket rate limiting via reliakit-ratelimit#789

Merged
github-actions[bot] merged 1 commit into
mainfrom
chore/faucet-reliakit-ratelimit
Jun 4, 2026
Merged

chore(faucet): token-bucket rate limiting via reliakit-ratelimit#789
github-actions[bot] merged 1 commit into
mainfrom
chore/faucet-reliakit-ratelimit

Conversation

@satyakwok
Copy link
Copy Markdown
Member

What

Adopt reliakit-ratelimit (one of the reliakit resilience crates) in the
testnet faucet, replacing two hand-rolled limiters.

  • Per-IP: was a sliding-window Vec<Instant> that grew per IP — the doc
    comment 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_drips per window with a burst allowance, O(1) memory per IP.
  • Per-recipient cooldown: was a hand-rolled last-timestamp check. Now a
    1-token bucket refilling every cooldown.
  • Precise Retry-After hints from RateLimiter::retry_after.

Why it's safe

  • Non-consensus: faucet binary only, testnet. No chain code touched.
  • TOCTOU preserved: the per-recipient cooldown previously needed a DashMap
    Entry guard to stop two parallel requests for the same address from both
    passing. The new code keeps that guard — entry(..).or_insert_with(..) holds
    the per-key shard lock across try_acquire_one, so refill+consume is atomic.
  • Rollback = git revert.

Tests

4 unit tests on the bucket mapping (burst-then-block, zero-max clamp,
one-per-cooldown, retry_after remaining). sentrix-faucet green under
RUSTFLAGS="-D warnings".

No workspace version bump (avoids colliding with the concurrent #788 bump);
changelog note under [Unreleased].

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Warning

Review limit reached

@satyakwok, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f6854e16-021a-4af2-998d-02f100dfc4ee

📥 Commits

Reviewing files that changed from the base of the PR and between 08f9738 and e8ebc85.

⛔ Files ignored due to path filters (2)
  • CHANGELOG.md is excluded by !**/CHANGELOG.md
  • Cargo.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (2)
  • bin/sentrix-faucet/Cargo.toml
  • bin/sentrix-faucet/src/main.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/faucet-reliakit-ratelimit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot enabled auto-merge (squash) June 4, 2026 05:21
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

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.
@satyakwok satyakwok force-pushed the chore/faucet-reliakit-ratelimit branch from d7cf2f1 to e8ebc85 Compare June 4, 2026 05:26
@github-actions github-actions Bot merged commit 1712cdd into main Jun 4, 2026
17 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.

1 participant