Skip to content

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Aug 22, 2025

This PR introduces supports per-endpoint rate limiting using a token bucket based on golang.org/x/time/rate.
Each endpoint configuration applies to each L402 individually.

I tested locally with different loop clients, as well as added unit and integration tests.

Example configuration for one endpoint:

    ratelimits:
      - pathregex: '^/looprpc.StaticAddressServer/ServerWithdrawDeposits.*$'
        requests: 2
        per: 1m
        burst: 5
  • With 2 requests per minute, a new token arrives every 30 seconds. Burst 5 means the bucket can hold up to 5 tokens and starts full after being idle.
  • If you make 2 requests within 10 seconds, you’ve only used 2 of the 5 tokens, leaving 3 tokens. So your next request (and up to 3 more) can go through immediately.
  • Once you’ve consumed all 5 tokens, you must wait for refills: one token every 30 seconds (so the next allowed request would be 30s after the last one that emptied the bucket, then another 30s for the next, etc.).
  • If you stop sending requests, the bucket refills at the same rate up to the burst capacity (max 5 tokens).

@hieblmi hieblmi requested review from starius, bhandras, sputn1ck and Roasbeef and removed request for bhandras and sputn1ck August 22, 2025 15:26
@hieblmi hieblmi self-assigned this Aug 26, 2025
@hieblmi hieblmi added the enhancement New feature or request label Aug 26, 2025
@hieblmi hieblmi requested a review from bhandras August 26, 2025 13:29
This commit introduces basic configurable rate
limits per pathregex.
This commit introduces per-L402 rate limits.
Consumption of a service by one L402 doesn't
eat into a rate bucked of another L402.
@lightninglabs-deploy
Copy link
Collaborator

@starius: review reminder
@Roasbeef: review reminder
@bhandras: review reminder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants