Introducing a new way to review your PRs.

Read the announcement

celestiaorg / celestia-core

A fork of CometBFT

View on GitHub

20 documents · Updated Nov 23, 2026

docs / rpc-transports-and-clients

RPC transports and clients

The RPC layer gives applications a way to read node state, submit transactions, inspect network state, and receive events. It offers HTTP JSON-RPC for broad client support, WebSockets for live events, and a separate gRPC API for typed calls and streams. Shared client interfaces and test helpers let applications use the same request model against a remote node, an in-process node, or a controlled test double.

This page is a child of RPC and API.

API surface

The node builds its public RPC surface from named routes. Each route points to a core operation and can be enabled for normal HTTP use, WebSocket use, or both. Unsafe control routes are added only when the node configuration allows them. Routes that can return large or chain-sized results also share a process-wide capacity limit across the HTTP and gRPC layers.

Route model

The route model gives all transports a common operation name and result shape. The main route groups cover node information, chain data, transaction broadcast, ABCI access, evidence, and data-availability proofs. Event subscription routes are reserved for WebSockets. The route map in rpc/…/routes.go is the contract that ties these operations to the JSON-RPC server in rpc/…/rpc_func.go.

References: rpc/…/routes.go• L9-25 rpc/…/routes.go• L43-63 rpc/…/routes.go• L66-72 rpc/…/rpc_func.go• L12-24

Request context

Every RPC operation receives a transport-aware request context. The context can carry the JSON-RPC request, the HTTP request, or the WebSocket connection. This lets an operation use cancellation and remote-address information without changing its public operation name for each transport.

References: rpc/…/types.go• L251-313 rpc/…/http_json_handler.go• L83-90 rpc/…/http_uri_handler.go• L35-40 rpc/…/ws_handler.go• L390-407

JSON-RPC transport

JSON-RPC is the main general-purpose RPC transport. It uses one operation name and one result model across HTTP requests and WebSocket messages, so clients can use HTTP for calls and switch to WebSockets when they need a live event stream.

HTTP request forms

The HTTP server exposes two request forms. URI-style calls place the operation in the URL path and pass values as query or form parameters. JSON-RPC calls use a POST to the root RPC endpoint with a JSON request body. An empty root request returns a human-readable endpoint list.

The JSON-RPC client sends named parameters in a JSON object. It can also send an array of parameters when a caller needs positional arguments. The URI client encodes values for an operation-specific HTTP path. String and byte values follow the RPC formatting rules, including quoted strings and 0x-prefixed bytes.

References: rpc/…/doc.go• L4-20 rpc/…/doc.go• L22-38 rpc/…/http_json_handler.go• L20-38 rpc/…/http_uri_handler.go• L20-77 rpc/…/http_json_client.go• L207-254 rpc/…/http_uri_client.go• L53-85 rpc/…/openapi.yaml• L36-51

JSON-RPC messages

Each request uses JSON-RPC version 2.0 fields for the operation name, parameters, and an optional request ID. A request with an ID produces a response with the same ID. A request without an ID is a notification and produces no response. The server accepts both named and positional parameters. A method may also accept omitted parameters as zero values when its request shape permits that form. The client checks response IDs before it decodes a result.

The server returns either a result or a JSON-RPC error. Parse errors, invalid requests, unknown methods, invalid parameters, and internal failures use distinct error codes. A batch is one HTTP request that contains several calls. The server limits batch size through RPC configuration, and the client keeps the result objects in the same order as the queued calls.

HTTP JSON-RPC clients cap the response body they read. The default limit is sized for large block results, and callers can lower it when their use case needs a smaller bound. The limit applies to single calls and batches, and an oversized response fails before result decoding.

References: rpc/…/types.go• L14-45 rpc/…/types.go• L51-85 rpc/…/types.go• L140-184 rpc/…/types.go• L217-247 rpc/…/http_json_handler.go• L40-127 rpc/…/http_server.go• L286-328 rpc/…/ws_handler.go• L360-443 rpc/…/decode.go• L12-38 rpc/…/http_json_client.go• L201-270 rpc/…/http_json_client.go• L289-332

Heavy request capacity

Heavy requests are calls whose result can be large or whose cost grows with chain data. The server admits them only while a shared process-wide budget has room, and it rejects a request without waiting when that budget is full. The budget covers equivalent URI, JSON-RPC, WebSocket, and gRPC calls so one transport or method cannot bypass protection for another.

For a JSON-RPC batch, repeated calls that use the same heavy-request budget share one slot. The slot stays held until the complete response is written, so a large response cannot release capacity while its output is still in flight. Different heavy budgets can still use their own slots within the same batch.

The transport reports saturation in its own error form. URI calls return HTTP 503, while JSON-RPC and WebSocket calls return a JSON-RPC internal error. gRPC calls return ResourceExhausted. Consumers should treat any of these results as temporary overload and retry with backoff.

References: rpc/…/rpc_func.go• L13-16 rpc/…/rpc_func.go• L57-92 rpc/…/http_json_handler.go• L104-125 rpc/…/http_json_handler_test.go• L282-350 rpc/…/http_uri_handler.go• L54-65 rpc/…/ws_handler.go• L404-442 rpc/…/ws_handler_test.go• L107-165 rpc/…/interceptor.go• L12-57

HTTP response caching

Read-only operations can mark an HTTP response as public and cacheable. The route defines whether an operation is cacheable, and the request values can remove that status when a default value means “latest,” such as height zero. Consumers must not assume that every successful read has the same cache behavior.

References: rpc/…/rpc_func.go• L26-48 rpc/…/rpc_func.go• L107-128 rpc/…/http_json_handler.go• L58-124 rpc/…/routes.go• L23-39 rpc/…/http_server.go• L128-132

WebSocket sessions

The WebSocket endpoint uses the same JSON-RPC message shape as HTTP. A client sends calls over one connection and receives responses and subscription events over that connection. The subscribe, unsubscribe, and unsubscribe_all operations are WebSocket-only.

The server keeps one event subscription set per connection. When a connection closes, its subscriptions are removed. A request with no ID is a notification and receives no response. When a method accepts arguments, omitted parameters use the method's zero values. The connection also uses read and write limits plus ping and pong activity to detect stale sessions. A slow event consumer can miss events because delivery is best effort rather than a durable queue.

WebSocket calls that can produce heavy responses use the shared capacity budget. The server rejects them when the budget is full instead of waiting, and it holds the slot until the response has been serialized and written to the socket. This prevents a client that stops reading from making the server build and queue more heavy responses than the budget allows.

The following flow shows how a WebSocket call and an event subscription share one connection.

sequenceDiagram
    participant C as Client
    participant S as RPC server
    participant E as Event bus
    C->>S: JSON-RPC subscribe request
    S->>E: Register query for connection
    S-->>C: JSON-RPC subscription response
    E-->>S: Matching event
    S-->>C: JSON-RPC event response
    C->>S: WebSocket close
    S->>E: Remove connection subscriptions

References: rpc/…/routes.go• L13-17 rpc/…/doc.go• L40-44 rpc/…/ws_handler.go• L29-45 rpc/…/ws_handler.go• L72-99 rpc/…/ws_handler.go• L220-243 rpc/…/ws_handler.go• L259-305 rpc/…/ws_handler.go• L313-447 rpc/…/ws_handler_test.go• L20-58 rpc/…/ws_handler_test.go• L60-92 rpc/…/ws_handler_test.go• L107-165 node/node.go• L865-883

JSON-RPC clients

The low-level JSON-RPC clients provide transport calls for consumers that need direct control. The HTTP client is safe for concurrent use and supports custom HTTP clients, request IDs, response decoding, request batches, and a maximum response-body size. The URI client is useful when a caller wants the path-based form. The WebSocket client exposes an asynchronous response channel and reconnects with backoff after a connection failure.

The higher-level rpc/client/http client builds on these pieces. It presents typed methods for the node API, uses HTTP JSON-RPC for normal calls, and uses a WebSocket client for event subscriptions. A caller can set the HTTP response-body limit through this client. It must start the high-level client before it uses event methods and stop it during shutdown.

References: rpc/…/http_json_client.go• L121-205 rpc/…/http_json_client.go• L207-332 rpc/…/http_uri_client.go• L18-50 rpc/…/ws_client.go• L30-49 rpc/…/ws_client.go• L183-265 rpc/…/ws_client.go• L298-335 rpc/…/http.go• L22-38 rpc/…/http.go• L110-184 rpc/…/http.go• L761-809

gRPC transport

The gRPC layer provides a typed API for consumers who prefer generated request and response types. It runs on a separate configured listener and exposes a smaller set of services than the full JSON-RPC route surface. The current API is marked deprecated in the code and is intended to be replaced by a new gRPC API after v0.38.

Service groups

The server exposes three service groups. The broadcast service submits a transaction and returns its check and execution results. The block service returns status, commits, validator sets, and block parts. The blobstream service returns data-root inclusion proofs. Generated clients give consumers the matching typed methods.

References: rpc/…/client_server.go• L30-62 rpc/…/types.pb.go• L1257-1316 rpc/…/types.pb.go• L1366-1555 rpc/…/types.pb.go• L1713-1757 rpc/…/api.go• L21-50 rpc/…/api.go• L405-475 rpc/…/api.go• L500-517

Unary and streaming calls

Simple reads and transaction calls return one response. Block queries can return a stream of block parts, with commit and validator data attached to the first part. New-height subscriptions remain open and send height, hash, time, and catch-up status as new blocks arrive.

The server applies the same heavy-request budget used by HTTP RPC to selected gRPC calls. Full block responses, full validator sets, and data-root inclusion proofs are limited, while cheap calls and the long-lived new-height stream are not. A full budget returns a ResourceExhausted gRPC status instead of queueing the call. Different heavy gRPC methods draw from the same budget.

Heavy block streams hold their slot for the full stream. Each receive and send has a stall limit, so a client that does not send its request or stops reading cannot hold the shared slot forever. The stall limit applies to each message rather than to the total stream time. A client that reads normally can receive a long stream even when the total transfer takes longer than one stall interval.

New-height subscriptions have a separate listener cap. When the cap is full, a new stream fails with ResourceExhausted; when a stream ends, its listener is released. The broadcaster sends without waiting on each listener, so a slow consumer can miss a height event without blocking other consumers or the node. Consumers that need a complete range should use block queries to fill any gap rather than treating the stream as durable storage.

The following flow shows the relationship between a typed block query and a live height stream.

sequenceDiagram
    participant C as gRPC client
    participant S as gRPC server
    participant B as Block store
    participant E as Event bus
    C->>S: BlockByHeight request
    S->>B: Read block parts and metadata
    S-->>C: Stream block parts
    C->>S: SubscribeNewHeights request
    E-->>S: New block event
    S-->>C: Height, hash, time, catch-up state

References: rpc/…/interceptor.go• L12-32 rpc/…/interceptor.go• L42-85 rpc/…/interceptor.go• L89-143 rpc/…/api.go• L55-64 rpc/…/api.go• L86-133 rpc/…/api.go• L192-250 rpc/…/api.go• L278-299 rpc/…/api.go• L301-403 rpc/…/api.go• L478-497 rpc/…/api_test.go• L50-259 rpc/…/api_test.go• L277-333 rpc/…/client_server.go• L35-62 rpc/…/interceptor_stream_test.go• L58-123 rpc/…/types.pb.go• L1388-1490 rpc/…/grpc_test.go• L175-205

gRPC addresses and lifecycle

The node starts the gRPC listener only when grpc_laddr is set. The server uses the same RPC environment as the HTTP layer, but it registers typed gRPC services on its own listener. Client helpers accept normal host and port addresses and preserve the dns:// and unix:// schemes that gRPC supports. Other URI schemes are removed before dialing.

The server uses keepalive checks and stops its block event listener and gRPC server during shutdown. Client calls should use a request context and end streaming calls when that context is canceled.

References: node/node.go• L930-956 rpc/…/client_server.go• L23-79 rpc/…/client_server.go• L84-155 rpc/…/api.go• L256-277 rpc/…/api.go• L278-299 rpc/…/api.go• L456-472

OpenAPI exposure

The OpenAPI description documents the HTTP-facing RPC contract for tools and human users. It describes URI over HTTP, JSON-RPC over HTTP, and JSON-RPC over WebSockets. It does not replace the generated gRPC service contract.

API description

rpc/…/openapi.yaml describes the server address, request formats, argument encoding, endpoint groups, response shapes, and common errors. It also records important consumer guidance, such as using WebSocket subscriptions for asynchronous transaction results and avoiding commit-wait calls in production. Heavy HTTP routes document HTTP 503 as the response for a saturated concurrent request budget and advise retry with backoff.

Swagger UI loads this YAML document through rpc/…/index.html. The result is a browsable reference for an HTTP consumer, while the live node still controls access, CORS, limits, and the enabled unsafe routes through RPC configuration.

References: rpc/…/openapi.yaml• L1-34 rpc/…/openapi.yaml• L36-63 rpc/…/openapi.yaml• L174-215 rpc/…/openapi.yaml• L499-578 rpc/…/openapi.yaml• L843-880 rpc/…/index.html• L13-23 node/node.go• L849-900

Client abstractions

The client package separates what a consumer can ask from how the request reaches the node. Code that depends on the rpc/client.Client interface can use a remote HTTP client, a local in-process client, or a test client without changing its API calls.

Shared client contract

The shared client contract groups calls by purpose. It covers ABCI queries and transaction broadcast, chain history and signed data, node status, network state, event subscriptions, mempool state, and evidence submission. Most methods accept a context and return a typed core result, so callers can keep transport concerns outside their application logic.

The default ABCI query uses the latest height and does not request a proof. Callers that need a historical result or proof must pass explicit query options.

References: rpc/…/interface.go• L32-62 rpc/…/interface.go• L64-120 rpc/…/interface.go• L122-171 rpc/…/types.go• L3-11

Client modes

The client modes serve different trust and test needs:

  • HTTP is the normal remote client. It combines typed HTTP calls with WebSocket event support.
  • Local calls the node directly in the same process. It avoids network and serialization cost and is useful for in-process applications and tests.
  • Mock supplies controlled responses or custom method implementations. It is useful when a test must force an error or record a call without starting a node.

These modes share the client interface, but they do not provide the same transport boundary. In particular, local and mock calls do not test network encoding, server limits, or remote connection failure.

References: rpc/…/interface.go• L3-21 rpc/…/http.go• L22-38 rpc/…/http.go• L160-164 rpc/…/local.go• L20-39 rpc/…/local.go• L47-61 rpc/…/client.go• L1-15 rpc/…/client.go• L30-50

Event and wait helpers

Shared helpers turn common consumer waits into small operations. WaitForHeight polls status until a target height is available and lets the caller choose a wait policy. WaitForOneEvent manages one subscription, waits for one matching event, and removes the subscription when it finishes.

The high-level HTTP and local clients retry event subscriptions after a service-side cancellation. Event channels are still best effort, so an application that cannot tolerate a missed event must use a later state query to recover.

References: rpc/…/helpers.go• L12-60 rpc/…/helpers.go• L60-83 rpc/…/http.go• L30-34 rpc/…/http.go• L855-919 rpc/…/local.go• L218-300

Test utilities

The RPC test layer starts real nodes when a test needs to verify a transport and provides controlled clients when it only needs to verify consumer behavior. This split keeps protocol tests realistic without forcing every client test to bind ports or run consensus.

Test node setup

rpc/…/helpers.go creates isolated configuration with free RPC, gRPC, and peer ports. StartTendermint starts a node and waits for both RPC transports to answer before returning. The helper also exposes typed JSON-RPC and gRPC clients, while StopTendermint stops the node and removes its temporary files.

The transport tests use this harness to check transaction broadcast, block and proof reads, streaming block parts, height events, and address parsing. The tests therefore cover the contract between a running node and an API consumer rather than only the internal handler functions.

References: rpc/…/helpers.go• L28-44 rpc/…/helpers.go• L47-73 rpc/…/helpers.go• L87-125 rpc/…/helpers.go• L127-171 rpc/…/helpers.go• L226-241 rpc/…/grpc_test.go• L25-59 rpc/…/grpc_test.go• L67-205

Consumer doubles

The mock clients let a test select a result, return an error, match arguments, or record a call. The local client gives a faster in-process path when the test needs real node behavior but not a network. Generated testify mocks provide a lower-level expectation tool for code that depends on the full client interface.

References: rpc/…/client.go• L30-83 rpc/…/client.go• L20-45 rpc/…/client.go• L724-849 rpc/…/local.go• L20-39

Protocol guarantees

The JSON-RPC tests protect the message contract. They check request IDs, notifications, batch responses, invalid parameters, unknown paths, cache headers, and response-size limits. The client tests protect address parsing, custom transport dialing, and rejection of responses above the configured limit. The gRPC tests protect typed results, streamed block parts, proof selection, event fields, listener-cap rejection and release, graceful listener behavior, and the shared heavy-request budget across distinct heavy methods. The gRPC interceptor stream tests also protect release of a shared slot when a client stalls and completion of a long stream when each message stays within the stall limit. The WebSocket server tests protect upgrade and parameter handling, cancellation of the connection context after disconnect, and the rule that a stalled reader cannot make heavy responses pile up behind a held permit.

References: rpc/…/http_json_handler_test.go• L34-87 rpc/…/http_json_handler_test.go• L90-216 rpc/…/http_json_handler_test.go• L219-277 rpc/…/http_json_handler_test.go• L280-350 rpc/…/rpc_func_test.go• L11-72 rpc/…/http_json_client_test.go• L15-130 rpc/…/ws_handler_test.go• L20-58 rpc/…/ws_handler_test.go• L60-92 rpc/…/ws_handler_test.go• L107-165 rpc/…/interceptor_test.go• L9-80 rpc/…/interceptor_stream_test.go• L58-123 rpc/…/api_test.go• L38-245 rpc/…/api_test.go• L277-333 rpc/…/grpc_test.go• L216-409

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the route names and parameter names aligned across rpc/…/routes.go, the JSON-RPC handlers, the typed client methods, and rpc/…/openapi.yaml.
  • Keep WebSocket-only routes out of URI and JSON-RPC HTTP handling, and keep disconnect cleanup aligned with event-bus subscription ownership.
  • Keep JSON-RPC response IDs, notification rules, batch limits, and client response decoding aligned. A change in one layer can make valid calls look like transport errors.
  • Keep response-body limits aligned between the low-level JSON-RPC client and the high-level HTTP client. Document any change to the default or failure behavior for consumers that receive large results.
  • Keep cache rules aligned with default arguments. A new default value can make a response unsafe to cache even when the route is read-only.
  • Keep the heavy-route list aligned across core route options, HTTP and WebSocket handlers, gRPC method names, and the shared capacity budget. A missed entry can let an expensive call bypass protection.
  • Keep heavy JSON-RPC batch admission and response lifetime aligned with the shared budget. A change can either reject valid calls or release capacity while a large response is still being written.
  • Keep WebSocket heavy permits held through serialization and socket write. Releasing them when a response is only queued can let a stalled reader accumulate expensive responses.
  • Keep WebSocket disconnect cancellation aligned with subscription cleanup. A handler that stops the socket but leaves its context active can leave work or subscriptions behind.
  • Keep the overload error contract aligned: HTTP URI uses 503, JSON-RPC uses an RPC error, and gRPC uses ResourceExhausted. Update consumer guidance when this contract changes.
  • Keep the gRPC service definitions, generated client types, server registration, and test helpers aligned when a service or stream changes.
  • Keep gRPC heavy stream admission, per-message stall handling, and slot release aligned. A change can leak capacity or cancel a healthy stream that is slow in total but active between messages.
  • Keep the gRPC height listener cap, listener cleanup, and non-blocking event delivery aligned. A change can leak stream capacity or let one slow consumer block all height events.
  • Keep gRPC address normalization aligned with supported resolver schemes and custom dial options.
  • Keep the shared rpc/client.Client groups aligned with HTTP, local, mock, and generated mock clients. A new method can break consumers that use an alternate client mode.
  • Keep OpenAPI request examples and response schemas aligned with the live HTTP route contract. OpenAPI does not describe the gRPC surface.

Important failure modes

TriggerConsequenceGuard
A JSON-RPC request uses an unknown method, wrong path, or wrong parameter shapeThe server returns a JSON-RPC error instead of the expected resultUse the route names and parameter forms in the OpenAPI description, and inspect both the RPC error and HTTP response
A notification omits its ID when the caller expects a resultThe server correctly sends no response, so the caller can wait foreverInclude a non-empty request ID for every call that needs a response
An HTTP batch exceeds the configured limitThe whole batch is rejected before normal route handlingKeep batch size within RPC configuration or send separate requests
A JSON-RPC response exceeds the client response-body limitThe client stops before result decoding and returns a size errorSet a limit that fits the expected result and handle the limit error as a failed call
Concurrent heavy requests fill the shared budgetURI calls return 503, JSON-RPC and WebSocket calls return an RPC error, and gRPC calls return ResourceExhaustedLimit client concurrency and retry temporary overload with backoff
A JSON-RPC batch contains heavy calls that need separate budgetsOne call can be rejected while another budget remains available, or a slot can be held longer than expected if response writing changesTreat each heavy budget as a shared cross-transport resource and keep batch admission and response writing rules aligned
A caller treats a successful broadcast_tx_async or broadcast_tx_sync response as proof of block inclusionThe transaction may remain uncommitted or be dropped laterUse event subscription or a later transaction status query when inclusion matters
A WebSocket consumer reads events too slowlyThe server or client can drop events, cancel the subscription, or reconnectRead the event channel promptly and backfill state with normal RPC queries
A WebSocket client is used before Start, or is not stoppedSubscription calls fail or connection resources remain activeStart the client before event calls and stop it during shutdown
A WebSocket reader stops consuming heavy responsesThe server holds the heavy permit until the write finishes and later requests receive overload errorsContinue reading or close the connection, then retry after the server releases capacity
A WebSocket connection closes while a handler still uses its contextWork that depends on the connection can continue with a stale contextStop the connection and use the connection context so cancellation reaches the handler
A gRPC height stream reaches the listener capA new subscription returns ResourceExhausted instead of waitingLimit concurrent subscriptions and retry after an existing stream ends
A gRPC height subscriber is slowIts height events can be dropped while other subscribers continueUse later block queries to backfill missed heights
A gRPC heavy stream stalls on request or response I/OThe stream ends with DeadlineExceeded and its shared slot is releasedSend the request and read each response within the per-message stall limit
A gRPC block stream ends before all parts are readThe consumer has an incomplete block viewRead until the stream ends and use the IsLast marker to identify completion
A client uses Local or a mock to claim that network behavior is validEncoding, address, limit, and connection errors remain untestedUse the real RPC test node for transport contract checks

Key files

FileWhy to read it
rpc/…/routes.goDefines the shared operation names and separates normal, WebSocket, unsafe, and heavy routes.
rpc/…/types.goDefines the request, response, error, and transport context contract.
rpc/…/rpc_func.goShows route options for WebSocket access, caching, and shared heavy-request admission.
rpc/…/http_json_handler.goExplains JSON-RPC request forms, notifications, batches, cache decisions, and overload handling.
rpc/…/http_uri_handler.goExplains URI parameter decoding and the HTTP overload response.
rpc/…/ws_handler.goExplains connection lifetime, context cancellation, parameter handling, event delivery, limits, and WebSocket overload handling.
rpc/…/http_json_client.goDefines direct HTTP JSON-RPC calls, batching, address handling, response-size protection, and result decoding flow.
rpc/…/ws_client.goDefines asynchronous WebSocket calls, response delivery, and reconnect behavior.
rpc/…/interface.goDefines the transport-independent client surface used by applications.
rpc/…/http.goConnects typed client methods to HTTP JSON-RPC and WebSocket events, including the response-body limit.
rpc/…/local.goShows the in-process client mode and local event behavior.
rpc/…/client.goShows the configurable client double for consumer tests.
rpc/…/client_server.goDefines gRPC server startup, client creation, address rules, keepalive, and shutdown.
rpc/…/interceptor.goDefines the shared heavy-request guard for typed unary and streaming calls, including per-message stall limits.
rpc/…/interceptor_stream_test.goShows the transport-level guarantees for stalled and long-running heavy streams.
rpc/…/api.goDefines typed service behavior, block stream semantics, height listener limits, and event delivery.
rpc/…/types.pb.goDefines the generated typed service and client contracts.
rpc/…/openapi.yamlDocuments the HTTP-facing RPC protocols, routes, arguments, responses, and overload status.
rpc/…/helpers.goProvides the real-node harness and transport client setup for integration tests.