You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 78fecde
Browse filesBrowse the repository at this point in the historyBrowse files
fix(routersession,holdoff)!: hold a provider off only while every url that can serve the request is held (MAG-4732, MAG-4733, MAG-4734) (#618)
A 429 is recorded per (provider, url). Selection read it wrong in both
directions. It asked only whether the provider name was held, and the
registry knows only urls that answered 429, so when url A got a 429 and B
never had one the provider read as held and B was skipped too; a name is
unique per chain and api-interface, so a 429 on the jsonrpc entry also held
the same-named REST entry. Inside a provider the url walk never read the
hold-off, so with B's old 429 expired and A held now, the provider read as
free and the walk handed out A because it is listed first.
The rule now: a provider is held only while every url of it that could
serve this request is held. "Could serve" means usable, able to answer a
relay (not a ws url), and serving the request's add-on, extensions and
internal path; a url with no entry is free. Inside the provider, urls that
are not held are handed out before held ones, and when every url is held
one is still used, as before.
- holdoff.ProviderKey(chain, interface, name) scopes the registry key.
Escalation (two held urls) holds that provider entry, not every entry
sharing the name. Decided on MAG-4732: the fleet runs one router process
per chain, so cross-chain escalation never happened in production; the
change is confined to api-interfaces of one chain.
- The re-verifier holds the url that answered 429 (MAG-4733), on the urls
the pass dials (base + path for a generated url, since MAG-4214), each
with its own Retry-After. A held url is not asked and keeps its last
verdict, add-on refusals and warnings included; the provider's other urls
are still checked, on the first pass and on the per-check retry. The pass
is skipped only when every url is held. Results are merged per url and
every 429 is recorded before any answer, so the outcome does not depend on
config order. A websocket url's 429 is held under the url alone.
- The last chance lends a url that can answer before a dead one (MAG-4734):
in rotation, then head-stalled, then switched off, stable within a rank.
- Scoped key at the relay path, recovery probe, probe loop (HoldoffKey),
re-verifier, session manager and the chain tracker's relay read.
- A provider's lost internal paths (UnservedInternalPaths, MAG-4214)
restrict the walk and relayURLs alike.
Unchanged: hold durations, the soonest-to-expire fallback between
providers, the write broadcast ignoring the hold-off (MAG-4388), the chain
tracker / WS / gRPC url-only keys, and the metrics' plain-name provider
label.
Jira ticket: MAG-4732
Also fixes MAG-4733 and MAG-4734.
BREAKING CHANGE: a rate-limit escalation (two urls of one provider held at
once) now holds that provider entry only (its name on one chain and
api-interface), not the same name on every chain and interface. The
`escalated` event of `smartrouter_rate_limit_holdoffs_total` keeps its
plain-name `provider` label, but no longer means every chain stopped.
Public docs: Magma-Devs/docs#86.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/METRICS.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -447,10 +447,11 @@ signal that an upstream is refusing us for load.
447
447
448
448
| Metric | Type | Labels | Description |
449
449
| --- | --- | --- | --- |
450
-
|`smartrouter_rate_limit_holdoffs_total`| Counter |`provider`, `event`| Registry events. `event` is the closed set `recorded` (a 429 held an endpoint off — a new hold-off, or a Retry-After that extended one; a 429 inside a standing hold-off changes nothing and is not counted, so a burst counts once), `escalated` (the hold-off widened to the whole provider name — counted once on the transition, not per refresh), `cleared` (an answer dropped a standing penalty — not counted when there was nothing to clear). |
450
+
|`smartrouter_rate_limit_holdoffs_total`| Counter |`provider`, `event`| Registry events. `event` is the closed set `recorded` (a 429 held an endpoint off — a new hold-off, or a Retry-After that extended one; a 429 inside a standing hold-off changes nothing and is not counted, so a burst counts once), `escalated` (the hold-off widened to the whole provider entry — the provider on one chain and api-interface, not the same name on others (MAG-4732); counted once on the transition, not per refresh), `cleared` (an answer dropped a standing penalty — not counted when there was nothing to clear). |
451
451
|`smartrouter_rate_limit_holdoff_seconds`| Histogram |`provider`| Applied hold-off duration per `recorded` event, in **seconds** (buckets `15, 30, 60, 120, 300, 600, 1800, 3600` — not the shared millisecond latency buckets). Shows upstream `Retry-After` magnitudes against the exponential default. |
452
452
453
-
`provider` is the configured provider name on the relay / probe / re-verify paths. The
453
+
`provider` is the configured provider name on the relay / probe / re-verify paths, summed
454
+
over chains and api-interfaces: the registry holds each entry apart, the label does not. The
454
455
WS and gRPC subscription paths and the per-url chain tracker key the registry by node URL
455
456
(the tracker so that its poll's 429 holds that URL, not the provider, off — MAG-4165); those
456
457
keys are reduced to `scheme://host` before they become a label, so a `sum by (provider)`
@@ -461,7 +462,7 @@ API keys in their path or query and a credential must never reach a Prometheus s
461
462
# upstreams currently tripping their caps
462
463
sum by (provider) (increase(smartrouter_rate_limit_holdoffs_total{event="recorded"}[15m])) > 0
463
464
464
-
# a vendor-wide cap: the hold-off escalated across a provider's URLs
465
+
# a vendor-wide cap: the hold-off escalated across the URLs of one provider entry (chain + api-interface)
Copy file name to clipboardExpand all lines: docs/RATE-LIMIT-HOLDOFF.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,12 @@ another registry, and tests use `NewRegistry` or the jitter-free `NewRegistryWit
9
9
## Semantics
10
10
11
11
-**Tiered keying.** A 429 holds off the endpoint URL that returned it. When 2 distinct
12
-
URLs of one provider name are held off at once, the hold-off escalates to the provider
13
-
name — a vendor cap is account-wide, and per-URL keying alone would let the process
14
-
keep hammering the account through its other chains. The provider-wide hold-off ends
15
-
when its longest-held member does.
12
+
URLs of one provider are held off at once, the hold-off escalates to the provider — a
13
+
vendor cap is account-wide, and per-URL keying alone would let the process keep
14
+
hammering the account through the provider's other URLs. The provider is one configured
15
+
entry: its name on one chain and api-interface (`holdoff.ProviderKey`), so an escalation
16
+
holds that entry and not the same name on other chains or interfaces (MAG-4732). The
17
+
provider-wide hold-off ends when its longest-held member does.
16
18
-**Retry-After is the floor.** When the upstream said how long to wait
17
19
(`common.RetryAfterFrom` on the typed error, or `RelayResult.RetryAfter` for a gRPC
18
20
status, whose refusal completes the relay and so returns no error), the hold-off is at
@@ -84,10 +86,12 @@ another registry, and tests use `NewRegistry` or the jitter-free `NewRegistryWit
84
86
-`URLReadyAt(provider, url)` returns the later of the url-only entry (the chain tracker, WS and gRPC
85
87
subscriptions) and the relay path's (provider, url) entry: when the url is free under every key
86
88
it is recorded by. The chain tracker's poll and the probe loop read it.
87
-
-`ProviderReadyAt(provider)` answers whether the provider is held as a whole and when it
88
-
next has a recorded URL worth trying. The registry only knows URLs that have answered
89
-
429; if a provider has additional never-limited URLs, this query can conservatively
90
-
over-hold until the earliest recorded deadline expires.
89
+
-`ProviderReadyAt(provider, urls)` answers whether the provider is held as a whole and when
90
+
it next has a URL worth trying. `urls` are the provider's urls that could serve the request
91
+
being placed (usable, able to answer a relay, serving its add-on, extensions and internal
92
+
path): the caller knows them, the registry only knows URLs that answered 429. The provider
93
+
is held while it is escalated or while every one of `urls` is held; a url with no
94
+
entry is free (MAG-4732).
91
95
92
96
## Consumer map
93
97
@@ -96,11 +100,11 @@ off" means on its path. This table is the catalog; add a row when wiring a new c
96
100
97
101
| Path | What "held off" means there | Records into the registry | Status |
98
102
| --- | --- | --- | --- |
99
-
| Spec re-verification (`spec_reverifier.go`) | Skip the probe, return the rate-limit error so reconciliation stays inconclusive — membership unchanged, streak untouched — without spending a request | 429 from `Validate`| live |
100
-
| Verification retries (`verification_retry.go`, MAG-3950) | A failing check's next retry is scheduled no earlier than its provider's hold-off ends (`ReadyAt` on the url the provider is keyed by), whatever its backoff says; a provider retried while still in the pairing goes through the spec re-verification row's probe, so a held provider is not probed | through spec re-verification's probe; the retry of a provider out of the pairing records nothing | live |
101
-
| Hot relay path (endpoint selection) | A rate-limited relay releases its session with no QoS sample in either direction, and selection prefers providers that are not held off; when every candidate is held off, the soonest-to-expire one stays in — the customer is never answered with a synthesized 429. A write broadcast is the exception: a stateful request goes to every enabled provider, held off or not — primaries, and backups under `--stateful-to-backup` — because the hold-off chooses which provider a request goes to and a broadcast goes to all of them. A provider still limiting answers the write with a 429, which is not the answer, so the broadcast waits for the others; one that has recovered lands it (MAG-4388). A write that reaches a single provider keeps the hold-off: a sticky write, the fleet claim a write proposes for a new sticky session, and every write under the cost strategy, which does not broadcast | 429 relay results, both shapes (typed HTTP error, 2xx-body/gRPC classification) | live |
103
+
| Spec re-verification (`spec_reverifier.go`) | The urls are the ones the router dials, so on a chain with internal paths a bare url is one url per path (`base + path`, the key the relay path records a 429 under), each held, skipped and cleared on its own (MAG-4214). A held url is not asked: the pass reads it as only rate-limited, so it keeps its last verdict — its url refusal and the refusals of its add-ons, since none of its checks ran — and the provider's other urls are still checked — a url refused for a capability problem comes back while a sibling is busy (MAG-4733). Only when every url is held is the probe skipped, returning the rate-limit error so reconciliation stays inconclusive — membership unchanged, streak untouched — without spending a request | 429 from `Validate`, under the url that answered it (MAG-4733): a relay url under the provider entry's key, a websocket url under the url alone (the WS path's key), so a socket's 429 never counts toward the entry's escalation. Results are merged per url (one url configured twice is one url) and every 429 is recorded before any answer, so the outcome does not depend on config order and an answer never clears a 429 the same pass met on the same url. Each url that answered clears its own entry; a url the pass did not send a request to (held off, or a retry kept its verdicts without dialing it) changes nothing, and a pass that never ran (a config error) clears nothing | live |
104
+
| Verification retries (`verification_retry.go`, MAG-3950) | A failing check's next retry is scheduled no earlier than the first of its provider's dialed urls comes out of its hold-off, whatever its backoff says: the pass asks only the urls that are not held, so one free url is enough (MAG-4733); a provider retried while still in the pairing goes through the spec re-verification row's probe, so a held provider is not probed | through spec re-verification's probe; the retry of a provider out of the pairing records nothing | live |
105
+
| Hot relay path (endpoint selection) | A rate-limited relay releases its session with no QoS sample in either direction, and selection prefers providers that are not held off — a provider is held only while every url of it that could serve the request is held — and inside a provider it hands out a url that is not held before one that is (MAG-4732), except in the last chance, which first ranks a url by its state — in rotation, then head-stalled, then switched off — and keeps this order only within a rank (MAG-4734); when every candidate is held off, the soonest-to-expire one stays in — the customer is never answered with a synthesized 429. A write broadcast is the exception: a stateful request goes to every enabled provider, held off or not — primaries, and backups under `--stateful-to-backup` — because the hold-off chooses which provider a request goes to and a broadcast goes to all of them. A provider still limiting answers the write with a 429, which is not the answer, so the broadcast waits for the others; one that has recovered lands it (MAG-4388). A write that reaches a single provider keeps the hold-off: a sticky write, the fleet claim a write proposes for a new sticky session, and every write under the cost strategy, which does not broadcast | 429 relay results, both shapes (typed HTTP error, 2xx-body/gRPC classification) | live |
102
106
| Recovery probe (`recovery_probe.go`) | Skip the replay while held off (verdict stays inconclusive), instead of burning replay-attempt budget on a vendor that said stop | 429 probe responses (Retry-After floor honoured) | live |
103
-
| Chain tracker / endpoint poller (`chaintracker/chain_tracker.go`, `endpointstate/endpoint_monitor.go`) | Records its own 429s under the url alone — the key the WS and gRPC subscription paths use — never under the relay path's (provider, url) key: relay selection holds a provider off while every url the registry knows for it is held, so a tracker entry there would pull the provider's healthy legs out of selection whenever its one polled leg is limited, and a backup-tier leg with no relay traffic would never be cleared. Reads both keys: the first fetch waits out an existing hold-off before each attempt, and a rate-limited attempt ends the init burst instead of retrying into the limit — the applied hold-off rides the start error as its Retry-After, and the monitor's start retry waits it out with the tracker in `retrying_start` naming the 429, never `starting` with no error; the dedicated poll waits out the applied hold-off (Retry-After when sent, else the strike schedule) and whatever the registry holds for the url — a relay's, a probe's or a subscription's hold-off, or the provider escalation. Its timer wakes at the normal cadence and reads the registry on every wake: while the url is held off nothing is sent, not even the poll scheduled before the hold-off began, and the next wake looks again (MAG-4387). It used to fold the hold-off into one timer when the timer was armed, so a poll already scheduled went out into the limit and a hold-off lifted early was slept out in full — after a burst of 429s that froze the url's tip for up to 35 minutes while relays on the url were answered. The idle wake burst does not poll a url that is held off: `WakePoll` sends nothing and returns `chaintracker.ErrorPollNowHeldOff` (also the typed 429, remaining wait as Retry-After), and the burst counts the url as not polled. An explicit `/debug/poll-now` still polls, as an explicit `lava-select-provider` outranks a relay hold-off. Because each wake reads the registry, an answer recorded for the url by anyone — a relay included — resumes the poll within one interval. A held wake runs at the base cadence, not the failure backoff: a refused poll counts as a failed one, and the backoff it built up would otherwise delay the resume by up to a minute. Clears its url-only entry only after its own 429 was answered; a fetch that got no answer (timeout, refused or reset connection) clears nothing | The typed 429 from the head or block-hash fetch — an HTTP 429, a refused ws handshake, or a JSON-RPC error body with code 429 / "too many requests", which `chainlib.RateLimitedReplyError` types for the body form on both fetchers — `chainlib.ChainFetcher` and the per-endpoint `endpointstate.EndpointPoller` behind every per-url tracker, including its `CustomMessage` behind the SVM (Solana / KOII) latest-slot poll via `chainlib.RateLimitedErrorBody` (MAG-4165) | live |
107
+
| Chain tracker / endpoint poller (`chaintracker/chain_tracker.go`, `endpointstate/endpoint_monitor.go`) | Records its own 429s under the url alone — the key the WS and gRPC subscription paths use — never under the relay path's (provider, url) key: relay selection holds a provider off while every url of it that could serve the request is held, so a tracker entry there would hold a relay url off whenever its tracker is limited, and a backup-tier leg with no relay traffic would never be cleared. Reads both keys: the first fetch waits out an existing hold-off before each attempt, and a rate-limited attempt ends the init burst instead of retrying into the limit — the applied hold-off rides the start error as its Retry-After, and the monitor's start retry waits it out with the tracker in `retrying_start` naming the 429, never `starting` with no error; the dedicated poll waits out the applied hold-off (Retry-After when sent, else the strike schedule) and whatever the registry holds for the url — a relay's, a probe's or a subscription's hold-off, or the provider escalation. Its timer wakes at the normal cadence and reads the registry on every wake: while the url is held off nothing is sent, not even the poll scheduled before the hold-off began, and the next wake looks again (MAG-4387). It used to fold the hold-off into one timer when the timer was armed, so a poll already scheduled went out into the limit and a hold-off lifted early was slept out in full — after a burst of 429s that froze the url's tip for up to 35 minutes while relays on the url were answered. The idle wake burst does not poll a url that is held off: `WakePoll` sends nothing and returns `chaintracker.ErrorPollNowHeldOff` (also the typed 429, remaining wait as Retry-After), and the burst counts the url as not polled. An explicit `/debug/poll-now` still polls, as an explicit `lava-select-provider` outranks a relay hold-off. Because each wake reads the registry, an answer recorded for the url by anyone — a relay included — resumes the poll within one interval. A held wake runs at the base cadence, not the failure backoff: a refused poll counts as a failed one, and the backoff it built up would otherwise delay the resume by up to a minute. Clears its url-only entry only after its own 429 was answered; a fetch that got no answer (timeout, refused or reset connection) clears nothing | The typed 429 from the head or block-hash fetch — an HTTP 429, a refused ws handshake, or a JSON-RPC error body with code 429 / "too many requests", which `chainlib.RateLimitedReplyError` types for the body form on both fetchers — `chainlib.ChainFetcher` and the per-endpoint `endpointstate.EndpointPoller` behind every per-url tracker, including its `CustomMessage` behind the SVM (Solana / KOII) latest-slot poll via `chainlib.RateLimitedErrorBody` (MAG-4165) | live |
104
108
| Probe loop (`runProbeCycleCore` in `rpcsmartrouter_server.go`) | Busy, not dead: an endpoint whose observation went stale while its url is held off under either key (`URLReadyAt`) is left out of its provider's QoS sample — neither healthy nor counted — and a provider whose every endpoint is in that state sends no sample that cycle. A stale url used to be scored availability 0 every cycle for the length of the hold-off, routing reads away from a healthy vendor that only asked us to slow down (MAG-4387). A fresh observation is judged as usual, held off or not, and the proactive re-enable pass is unaffected | Nothing — read only | live |
105
109
| WS subscriptions (`direct_ws_subscription_manager.go`) | A rate-limited connect/subscribe is held off instead of scored (no availability sample), selection skips held endpoints while something ready remains, and the pool's reconnect ladder is floored by the dial's Retry-After. Keyed per WS URL — no provider name exists on this path, so vendor-tier escalation does not apply | 429 handshakes and subscribe failures | live |
106
110
| WS / gRPC transports | Recognition first: a 429 on the WS upgrade or a corroborated gRPC rate limit produces the typed sentinel these consumers key on | handshake / metadata 429s | live |
@@ -111,7 +115,7 @@ off" means on its path. This table is the catalog; add a row when wiring a new c
111
115
The registry emits its own events, so every consumer is covered without wiring
112
116
(labels, buckets, and PromQL recipes in [METRICS.md](METRICS.md#rate-limit-hold-off)):
113
117
114
-
-`smartrouter_rate_limit_holdoffs_total{provider, event}` — `recorded` (a 429 held an
118
+
-`smartrouter_rate_limit_holdoffs_total{provider, event}`(`provider` is the plain name, summed over chains and interfaces) — `recorded` (a 429 held an
115
119
endpoint off), `escalated` (counted on the transition to a provider-wide hold-off),
116
120
`cleared` (an answer dropped a standing penalty).
117
121
-`smartrouter_rate_limit_holdoff_seconds{provider}` — histogram of applied hold-offs,
0 commit comments