-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Motivation
Production bots (liquidation keepers, arbitrage searchers, MEV-Share listeners) run 24/7. The current ws_transport.zig has no reconnection logic — a dropped connection kills the bot. This is a blocker for using eth.zig in any production searcher.
Required behaviour
- Auto-reconnect on disconnect: Exponential backoff with configurable max delay (e.g. 100ms → 200ms → 400ms → ... → 30s)
- Re-subscribe on reconnect: Subscriptions registered via
subscription.zigshould be automatically re-established after reconnect - Missed event detection: After reconnect, caller can optionally request events since last-seen block to avoid gaps
- Connection health monitoring: Optional heartbeat (ping/pong) to detect silently dead connections before the OS timeout
API surface
pub const ReconnectOpts = struct {
/// Initial backoff delay in milliseconds. Default: 100
initial_backoff_ms: u64 = 100,
/// Maximum backoff delay in milliseconds. Default: 30_000
max_backoff_ms: u64 = 30_000,
/// Maximum reconnect attempts (0 = unlimited). Default: 0
max_attempts: u32 = 0,
/// Send WebSocket ping every N ms to detect dead connections. 0 = disabled.
ping_interval_ms: u64 = 0,
/// Callback invoked on each reconnect attempt.
on_reconnect: ?*const fn (attempt: u32) void = null,
};Why this matters for the MEV use case
A liquidation keeper that monitors positions near threshold needs continuous WebSocket connectivity. Missing a single block where a position crosses the liquidation line means losing the fee to a competing bot. Reconnect logic is table stakes, not a nice-to-have.
Implementation notes
- Reconnect logic can live in
ws_transport.zigas aReconnectingWsTransportwrapper, keeping the base transport simple - The reconnect loop should run on the same thread (no OS thread spawning required — caller controls the event loop)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request