Expand description
Rate-limit keys, quotas, and limiters for the Lighter adapter.
Lighter meters requests against both the caller IP and the account L1 address.
REST reads draw on a per-client read quota. Transactions (sendTx /
sendTxBatch) are metered in one venue bucket per account regardless of
transport; single orders go over the WebSocket and batches over HTTP, so both
share one LighterTxRateLimiter to keep their combined rate under the single
venue transaction limit.
§WebSocket client messages
Non-transaction WS frames (subscribe, unsubscribe, resubscribe) face two independent per-IP caps: 200 messages per minute and 50 unacknowledged (inflight) messages. The adapter honours each with a separate mechanism:
- Rate: one
ws_message_rate_limiterper venue URL, shared by the data and execution clients so their combined send rate counts against a single bucket. It paces at the documented 200/min with a matching 50-message burst. - Inflight: a rate limiter cannot bound inflight, because the unacknowledged
count tracks venue acknowledgement latency (multi-second and fat-tailed),
not emission rate. The feed handler instead gates subscribe dispatch on a
closed-loop count of unacknowledged subscribes
(
crate::common::consts::SUBSCRIBE_INFLIGHT_MAX), releasing a slot on each ack. Without it, a subscribe storm at startup or reconnect drives inflight past 50 and the venue returns30009/30010.
sendTx is metered in the transaction bucket, not the WS message bucket.
Constants§
- LIGHTER_
REST_ BUCKET - Rate-limit bucket key shared by all REST read endpoints.
- LIGHTER_
TX_ BUCKET - Rate-limit bucket key for the venue transaction bucket.
- LIGHTER_
WS_ MESSAGE_ BUCKET - Rate-limit bucket key for non-transaction WebSocket client messages.
- LIGHTER_
WS_ MESSAGE_ BURST - Rate-limiter burst, at Lighter’s documented 50-message inflight cap. The
closed-loop subscribe gate (
crate::common::consts::SUBSCRIBE_INFLIGHT_MAX) is the real inflight bound; this burst only shapes send rate. - LIGHTER_
WS_ MESSAGE_ RATE_ PER_ MIN - Lighter’s documented WebSocket message rate: 200 per IP per minute.
Statics§
- LIGHTER_
REST_ QUOTA - Conservative Lighter REST rate limit for standard accounts.
- LIGHTER_
WS_ MESSAGE_ QUOTA - Lighter WebSocket client-message quota, excluding
sendTx/sendTxBatch. - LIGHTER_
WS_ MESSAGE_ RATE_ LIMIT_ KEY - Pre-interned rate-limit key for non-transaction WebSocket client messages.
Functions§
- await_
tx_ quota - Awaits transaction-bucket capacity before a
sendTxon either transport. - build_
tx_ rate_ limiter - Builds the shared transaction limiter from a
sendtx_quota_per_minoverride, keyed onLIGHTER_TX_BUCKET. Unset or zero falls back to the standard 60 req/min. - resolve_
quota - Resolves a per-minute override to a quota, falling back to the conservative standard-account quota when unset or zero.
- ws_
message_ rate_ limiter - Returns the shared WS message limiter for
url, creating it on first access. Subsequent calls with the sameurlreturn the sameArc.
Type Aliases§
- Lighter
TxRate Limiter - Per-account transaction rate limiter, shared across the HTTP and WebSocket
sendTxpaths so their combined rate honours the single venue bucket. - Lighter
WsMessage Rate Limiter - Shared WebSocket message limiter, keyed by venue WS URL. Both data and execution clients (and the backend balance poller) draw from one bucket per URL so their combined send rate honours the venue’s per-IP cap.