Skip to content

SSE transport for MEV-Share event streaming #33

@koko1123

Description

@koko1123

Motivation

MEV-Share's event stream uses Server-Sent Events (SSE), not WebSocket. eth.zig currently has ws_transport.zig and http_transport.zig but no SSE transport. This blocks a full MEV-Share client.

SSE is also used by other Ethereum tooling (some RPC providers, block explorers), so this is a generally useful transport.

Specification

New file: src/sse_transport.zig

pub const SseTransport = struct {
    /// Open a persistent HTTP connection and parse the SSE event stream.
    /// Calls `callback` for each complete event.
    pub fn subscribe(
        allocator: std.mem.Allocator,
        url: []const u8,
        headers: []const std.http.Header,
        callback: *const fn (event: SseEvent) void,
    ) !void

    pub const SseEvent = struct {
        id: ?[]const u8,
        event: ?[]const u8,  // event type ("tx", "bundle", etc.)
        data: []const u8,    // JSON payload
    };
};

Wire format

SSE is a text protocol over a persistent HTTP/1.1 connection:

data: {"hash":"0xabc...","logs":[...]}\n
\n
id: 42\n
event: bundle\n
data: {"hash":"0xdef..."}\n
\n

Parser needs to handle:

  • Multi-line data: fields (concatenate with \n)
  • id: and event: fields
  • Blank line as event delimiter
  • Reconnect on connection drop (respect retry: field)
  • Last-Event-ID header on reconnect

MEV-Share event stream URL

https://mev-share.flashbots.net/api/v1/events (mainnet)

Auth header: X-Flashbots-Signature: 0x<address>:0x<sig> (same scheme as flashbots.zig).

Relationship

This is a prerequisite for mev_share.zig client (event streaming) — see companion issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions