Skip to main content

Module server

Module server 

Source
Expand description

API server: JSON-RPC over HTTP and WebSocket on one port, as in Clio.

HTTP: POST / with {"method": ..., "params": [{...}]}, response is {"result": {..., "status": "success"}}. WebSocket: GET / with an upgrade, requests {"command": ..., "id": ..., ...}, response is result plus id, api_version, status, type at the top level. Errors follow Clio: inside result over HTTP, at the top level over WebSocket.

Requests are served on a blocking task pool (fjall and zstd are synchronous), at most MAX_INFLIGHT at a time; proof bundles have their own budget, MAX_PROOFS, and no queue: when it is full they are refused with tooBusy. Requests to a node have their own budget too, MAX_FORWARDS, so that nodes that stopped answering can’t hold the slots that reads need. A request waits at most QUEUE_WAIT for a slot and has REQUEST_LIMIT to finish (limits); past either it ends with tooBusy.

Public listeners (PublicConfig) are a separate door to the same data: their slots are their own, so public load can’t fill those of --api-addr, the limits of guard apply there and only there, and when the other door has fewer than OWN_HEADROOM free slots they step aside with tooBusy. This protects the queue, not the machine: disk and CPU stay shared, which is why the public slots are few.

subscribe and unsubscribe work only over WebSocket; subs keeps the subscriptions. A session interleaves responses to requests with messages from its queue.

Node methods and requests about the current ledger (forward::forwarded) go to xrpld; the response follows Clio: the node’s result as is, with forwarded: true, status, type on top.

Clients are limited per address by guard when it is configured.

HTTP answers say whether they can be cached: an answer about a ledger named by sequence or hash, or about a transaction, never changes once given, and gets Cache-Control: public, max-age=86400, immutable; everything else gets no-store. A cache in front can rely on that. JSON-RPC requests are POSTs, which CDNs don’t cache on their own, so the cache keys on the body.

Structs§

PublicConfig
Listeners for strangers, with their own slots and limits.
ServeConfig
How the server listens beyond its addresses.

Functions§

serve
Listens on every address in addrs for the life of the process, with one set of subscriptions behind them all. An address that can’t be bound is retried on its own: ingestion matters more than the API, and an address still held by the server being replaced is taken over once it is freed.