Skip to main content

Module nonce

Module nonce 

Source
Expand description

Per-(account_index, api_key_index) sequential nonce manager.

Mirrors the optimistic strategy lighter-python’s OptimisticNonceManager uses: each call to NonceManager::next_nonce hands out the next monotonic integer for the requested key without waiting for the venue to confirm the prior one. The caller bounds the number of unconfirmed allocations through the NonceManager::skip_window argument; once the window is exhausted, NonceManager::next_nonce errors so the caller can drain or refresh before issuing further transactions.

The window is the L2’s tolerance for out-of-order submission: the sequencer accepts a tx whose nonce is up to skip_window ahead of the last applied nonce, which is what makes the optimistic allocation correct in the first place. Lower the window if the venue rejects rates of out-of-order accepts; raise it when burst-trading multiple keys.

The module is lock-free per key: a [DashMap] keys an Arc holding two AtomicI64s (last_issued and baseline). NonceManager::next_nonce is a CAS loop bounded by skip_window; NonceManager::ack_success monotonically advances the baseline when the venue confirms a tx; NonceManager::ack_failure_if_latest rolls back the most recent allocation when the failed nonce is still the latest issuance.

Structs§

NonceManager
Thread-safe sequential nonce allocator keyed by (account_index, api_key_index).

Enums§

NonceError
Errors raised by NonceManager.

Constants§

DEFAULT_SKIP_WINDOW
Default skip-window used when the caller does not specify one.