LighterSDKSession
Documentation for eth_defi.lighter.session.LighterSDKSession Python class.
- class LighterSDKSession
Bases:
objectExponential backoff for all HTTP traffic of the official Lighter SDK.
The SDK sends everything through
ApiClient.rest_client.request()usingaiohttp, soLighterSessioncannot see it. This class replacesrest_clientby composition, which keeps the optional SDK out of eth-defi’s imports. It does not change the SDK’s error handling: the final response is returned unchanged and the SDK raises its usualApiException.Retrying here rather than around a signer method matters. The SDK does not roll its nonce back when a 429 escapes, so a retry above this layer would sign again with a later nonce. Here the same signed body is resent, so the nonce and the transaction hash do not change.
Which requests are retried:
GETandHEAD:LIGHTER_RETRYABLE_READ_STATUSES, and connection, timeout or body-read errors.POSTtoLIGHTER_SEND_TX_PATH:LIGHTER_RATE_LIMIT_STATUSESonly. The resend carries the same nonce, so the sequencer cannot execute it twice. A 5xx or a timeout leaves the outcome unknown and is never retried.Anything else: never.
The SDK holds its per-key nonce lock during a wait. That keeps transactions in nonce order, and clients are built per operation, so nothing else is blocked.
Authenticated Lighter requests can carry a token in the query string, and bodies hold signed transactions, so logs only name the method and URL path.
The native Go signer has its own HTTP client, which this class cannot wrap. It is used when an SDK transaction method receives
api_key_indexwithout anonce, and bySignerClient.check_client(). Do not call them that way: omitapi_key_indexand the Python nonce manager fetches the nonce through this class.See Lighter’s rate limits and the SDK’s REST client.
Attributes summary
The SDK's
RESTClientObject.Delays and deadlines.
Monotonic clock, injectable for deterministic tests.
Async sleep, injectable for deterministic tests.
Methods summary
__init__(rest_client[, policy, clock, sleep])close()Close the wrapped SDK client.
request(method, url[, headers, body, ...])Send one SDK request, matching
RESTClientObject.request().- rest_client: Any
The SDK’s
RESTClientObject.
- policy: eth_defi.lighter.session.LighterSDKRetryPolicy
Delays and deadlines.
- clock: collections.abc.Callable[[], float]
Monotonic clock, injectable for deterministic tests.
- sleep: collections.abc.Callable[[float], collections.abc.Awaitable[None]]
Async sleep, injectable for deterministic tests.
- async close()
Close the wrapped SDK client.
- Return type
None
- async request(method, url, headers=None, body=None, post_params=None, _request_timeout=None)
Send one SDK request, matching
RESTClientObject.request().The body is read here because the SDK reads it only after this returns, which would leave a truncated read outside the retries.
RESTResponsecaches it, so the SDK’s later read returns the same bytes.- Parameters
- Returns
SDK
RESTResponsewith its body read.- Return type
- __init__(rest_client, policy=LighterSDKRetryPolicy(initial_delay=1.0, max_delay=64.0, read_deadline=130.0, transaction_deadline=30.0, request_timeout=30.0), clock=<built-in function monotonic>, sleep=<function sleep>)
- Parameters
rest_client (Any) –
clock (collections.abc.Callable[[], float]) –
sleep (collections.abc.Callable[[float], collections.abc.Awaitable[None]]) –
- Return type
None