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-and-api

RPC and API services

RPC and API services provide the public boundary of a CometBFT node. They let operators, applications, and tools read node and chain state, submit transactions, inspect consensus and network state, and follow chain events through supported network or in-process clients.

Service boundary

The RPC service turns a running node into a set of query and command capabilities. The node supplies one shared service context with access to application queries, the block and state stores, the mempool, consensus state, peer state, indexes, and the event bus. Each transport then exposes the capabilities that it supports.

This diagram shows how node state becomes API results for remote and local callers.

flowchart LR
    N[Running node] --> E[RPC service context]
    E --> C[Node and network information]
    E --> B[Blockchain and consensus data]
    E --> T[Transaction and application operations]
    E --> V[Events and proof data]
    C --> X[Supported transports]
    B --> X
    T --> X
    V --> X
    X --> R[Remote clients]
    X --> L[In-process clients]

RPC service context

The RPC service context is the shared view of node resources used by the API surface. It keeps transport code separate from the node services that own chain state, so JSON-RPC, WebSocket, gRPC, and local callers can use the same high-level behavior. The context also owns one shared limit for costly responses across all transports. The deterministic RPC test environment assembles the same kinds of resources so handler and transport checks can exercise committed blocks, indexes, the mempool, evidence, and events together.

References: node/node.go• L805-838 rpc/…/env.go• L35-120 rpc/…/routes.go• L11-16 rpc/…/fuzz_env_test.go• L48-140

Response load control

Response load control protects the node when many callers request large results at the same time. Routes that can build a full block, a large search result, proof data, or the genesis document use one process-wide budget. The default budget is 20 concurrent heavy responses. A request that finds the budget full is rejected at once, while light requests remain available.

The full and chunked genesis routes are part of this shared heavy-response group. The same budget covers the matching gRPC methods, including full block streams, unpaged validator sets, and data-root proofs. A disabled limit allows unlimited heavy responses, so operators must size that setting against available memory rather than treat it as a byte limit. The budget is shared and memoized across calls, and a released slot admits one more heavy request. Subscription streams and light methods do not consume it.

Block search has an additional page-size guard. Before it loads block contents, it sums the stored sizes of the retained blocks on the requested page. A page above 64 MiB is rejected, while one block remains reachable even when that block alone exceeds the limit. Pruned heights do not count toward this block-content budget because their blocks cannot be returned.

References: rpc/…/env.go• L27-29 rpc/…/env.go• L98-120 rpc/…/blocks.go• L214-308 rpc/…/env_test.go• L13-48 rpc/…/routes.go• L12-16 rpc/…/routes_test.go• L15-32 rpc/…/blocks_test.go• L428-500 rpc/…/rpc_func.go• L57-93 rpc/…/rpc_func_test.go• L11-71 rpc/…/http_json_handler.go• L108-142 rpc/…/http_json_handler_test.go• L282-350 rpc/…/ws_handler.go• L380-411 rpc/…/interceptor.go• L11-93 rpc/…/interceptor_test.go• L16-80 config/config.go• L411-429

Capability groups

The API groups related node actions around the questions a caller needs to answer. Read operations describe the chain and node, while write operations pass application work or evidence into the node.

Node and network information

Node and network information describes whether the node is healthy, which peers it sees, how far it has synced, and what consensus state it reports. Status data includes node identity, the latest and earliest retained block, application and block hashes, validator information, and the catch-up state.

References: rpc/…/routes.go• L19-41 rpc/…/status.go• L13-74 rpc/…/consensus.go• L53-117

Blockchain and consensus data

Blockchain and consensus data lets callers inspect blocks, headers, commits, block results, validator sets, consensus parameters, genesis data, and signed block material. Height and hash queries support both current chain inspection and verification of historical data that the node still retains. The blockchain range view returns at most 20 block metadata entries and adjusts its bounds to the current and retained heights. Block search returns matching retained blocks in pages and rejects a page whose combined stored block size exceeds 64 MiB, except that a single block remains reachable on its own.

The API also creates data commitments and inclusion proofs over an ordered range of retained block data roots. These requests use an end-exclusive range of no more than 10,000 blocks, and a client can verify that one block belongs to the committed range. Share proof requests also reject an invalid range before trying to load block data. Handler and gRPC fuzz coverage exercises these bounds across height, hash, multipart block, validator-set, commit, and proof requests.

References: rpc/…/routes.go• L23-39 rpc/…/blocks.go• L25-95 rpc/…/blocks.go• L129-211 rpc/…/blocks.go• L214-308 rpc/…/blocks.go• L311-337 rpc/…/blocks.go• L340-356 rpc/…/blocks.go• L442-472 rpc/…/blocks.go• L493-587 rpc/…/blocks_test.go• L39-138 rpc/…/blocks_test.go• L163-293 rpc/…/blocks_test.go• L428-500 rpc/…/blocks_test.go• L502-510 rpc/…/handlers_fuzz_test.go• L129-179 rpc/…/grpc_fuzz_test.go• L79-135 rpc/…/consensus.go• L11-50 rpc/…/openapi.yaml• L396-858

Transaction and application operations

Transaction and application operations connect clients to the ABCI application and the mempool. A caller can query application state, check a transaction, broadcast it with different waiting levels, inspect pending work, submit evidence, and ask for a transaction status.

ABCI application queries provide a general path for application state and may request a proof. The API reserves the application paths used for transaction and share inclusion proofs for dedicated proof routes. This prevents a caller from supplying arbitrary block data to those proof queries. Evidence submission accepts a misbehavior report only after basic validation and then passes it to the evidence pool. Transaction status distinguishes a committed transaction from one that is pending, evicted, rejected, or unknown. Batch status results preserve input order and accept no more than 20 hashes. The older single and search transaction lookup routes are deprecated, so new clients should use the current status and search capabilities where available.

References: rpc/…/routes.go• L43-65 rpc/…/abci.go• L15-67 rpc/…/abci_test.go• L17-64 rpc/…/tx.go• L33-120 rpc/…/tx.go• L282-359 rpc/…/tx.go• L362-375 rpc/…/evidence.go• L12-33 rpc/…/handlers_fuzz_test.go• L52-127 rpc/…/grpc_fuzz_test.go• L72-78 rpc/…/interface.go• L46-62 rpc/…/openapi.yaml• L1059-1302

Events and proof data

Events and proof data support reactive clients and verification workflows. WebSocket clients can subscribe to node events, while block and transaction APIs can return material used to check inclusion or data-root claims.

Subscription requests are limited by configured client counts, per-client subscription counts, and query length. Event delivery is not a replacement for chain queries. A client that must not miss a height or event should use the event as a prompt and query the chain to fill any gap.

References: rpc/…/routes.go• L14-18 rpc/…/events.go• L21-105 rpc/…/handlers_fuzz_test.go• L85-94 rpc/…/jsonrpc_fuzz_test.go• L137-153 rpc/…/blocks.go• L340-356 rpc/…/blocks.go• L493-587 rpc/…/interface.go• L144-159

Transport boundary

The service supports simple HTTP endpoint calls, JSON-RPC over HTTP, JSON-RPC over WebSocket, and a typed gRPC subset. The transports share the RPC capability model but differ in message shape and in their support for streaming or subscriptions.

TransportMain useInteraction shape
URI over HTTPSimple scripts and inspectionOne endpoint per RPC method with query parameters
JSON-RPC over HTTPGeneral remote callsSingle requests or bounded batches with structured results and errors
JSON-RPC over WebSocketEvent-driven clientsRequests and asynchronous subscription results on /websocket
gRPCTyped block, status, broadcast, and proof accessProtocol-defined requests with unary and server-streaming calls

HTTP and JSON-RPC transport

The HTTP service maps the shared route set to both URI paths and the JSON-RPC root endpoint. JSON-RPC supports named or positional parameters, structured errors, notifications, and bounded request batches. WebSocket subscriptions use the same method set where a method is marked for event use, but they are available only on the WebSocket endpoint. Invalid JSON-RPC input returns a structured protocol error, while notifications do not produce a response.

The RPC listener can serve plain or TLS-protected HTTP. Its node configuration also controls request size, batch size, connection limits, CORS, and the listen address. When the shared heavy-response budget is full, URI requests return HTTP 503. JSON-RPC callers receive a JSON-RPC error. A JSON-RPC batch that contains heavy calls uses one shared heavy-response slot, and that slot stays reserved until the complete response is written. The public OpenAPI description records the URI, JSON-RPC, and WebSocket forms and documents 503 responses for heavy routes such as block, block_by_hash, block_results, genesis, and genesis_chunked.

Remote JSON-RPC clients also cap the response body before decoding it. The default cap is 512 MiB and callers can lower or raise it for their workload. The client accepts network endpoints and Unix socket endpoints, so the same API contract can serve local tools as well as remote applications.

References: rpc/…/routes.go• L9-63 rpc/…/rpc_func.go• L12-24 rpc/…/http_json_handler.go• L17-143 rpc/…/http_uri_handler.go• L16-77 rpc/…/jsonrpc_fuzz_test.go• L42-247 rpc/…/http_json_handler_test.go• L34-350 rpc/…/http_json_client.go• L32-117 rpc/…/http_json_client.go• L201-270 rpc/…/http_json_client_test.go• L40-130 rpc/…/openapi.yaml• L8-21 rpc/…/openapi.yaml• L499-777

WebSocket event transport

The WebSocket transport keeps a connection open for request responses and event results. A client sends a subscription query, receives matching events asynchronously, and removes the subscription when it no longer needs it.

The server treats slow event consumers as a service concern. It uses a bounded write path and can cancel a subscription when writes time out. Heavy request slots stay held while a response is marshaled and queued for the writer. Event delivery is best effort. The client layer can restore subscriptions after a connection loss. Applications that need complete history must combine subscriptions with block or transaction queries.

References: node/node.go• L865-883 rpc/…/events.go• L21-133 rpc/…/jsonrpc_fuzz_test.go• L251-306 rpc/…/ws_handler.go• L29-99 rpc/…/ws_handler.go• L220-277 rpc/…/ws_handler.go• L380-461 rpc/…/ws_handler_test.go• L15-65 rpc/…/http.go• L22-38 rpc/…/http.go• L746-926

gRPC transport

The gRPC service provides typed access to transaction broadcast, block retrieval, commits, validator sets, status, new-height streams, and data-root inclusion proofs. Block retrieval uses server streaming because a block can be returned as several parts, while new-height notifications use a separate stream.

Large unary and block-streaming calls share the process-wide heavy-response budget with HTTP and JSON-RPC. New-height streams use a separate listener limit so long-lived subscriptions do not consume that budget. The service forwards block height, hash, time, and catch-up state to active listeners, but it drops an event for a slow listener rather than blocking other listeners. A listener that reaches the cap receives a resource-exhausted error and can retry after another stream ends. The gRPC event-bus subscription also retries after a temporary subscription failure.

The current gRPC surface is a convenience API and is marked for replacement after the v0.38 line. New integrations should confirm the API life cycle before depending on it.

References: proto/…/types.proto• L36-66 proto/…/types.proto• L68-198 rpc/…/api.go• L24-57 rpc/…/api.go• L66-189 rpc/…/api.go• L192-237 rpc/…/api.go• L278-347 rpc/…/api.go• L478-516 rpc/…/api_test.go• L50-328 rpc/…/interceptor.go• L11-93 rpc/…/client_server.go• L23-79 rpc/…/grpc_fuzz_test.go• L22-140

Client integrations

Client integrations give callers one high-level interface across the main access modes. Remote production code normally uses the HTTP client over JSON-RPC and WebSocket, while code that runs in the same process can call the RPC service without a network hop.

Client choices

The client interface groups access by purpose, such as application calls, history, network state, status, events, mempool data, and evidence. This lets application code depend on the capability contract instead of a specific transport.

ClientConnection modelBest fit
HTTP clientJSON-RPC over HTTP plus WebSocket eventsRemote applications and operators
Local clientDirect calls into a nodeIn-process applications and tests
Mock clientControlled responses behind the same client shapeTests that need chosen node results
gRPC clientsTyped calls to the gRPC servicesConsumers of the typed gRPC subset

The HTTP client also provides a batch form for grouping JSON-RPC calls into one HTTP request. Its event layer requires an explicit running lifecycle, reports events through subscription channels, and restores subscriptions after a connection loss. See RPC transports and clients for the related page, including focused guidance for JSON-RPC, gRPC, and client integrations.

References: rpc/…/interface.go• L32-44 rpc/…/interface.go• L122-171 rpc/…/http.go• L22-38 rpc/…/http.go• L61-105 rpc/…/http.go• L176-205 rpc/…/http.go• L746-926 rpc/…/local.go• L20-61 rpc/…/client_server.go• L81-135

Change checklist

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

  • Keep the shared route names and result meanings aligned with the HTTP client methods and the public OpenAPI reference.
  • When a route becomes heavy or stops being heavy, review the matching gRPC method and the shared concurrency budget.
  • When subscription limits or slow-client behavior changes, review the WebSocket client recovery and event backfill expectations.
  • When the JSON-RPC endpoint format or response-size limit changes, review HTTP, TLS, Unix-socket, and batch clients together.
  • When a gRPC request or response changes, update the protocol definition and every generated or typed client that consumes it.
  • When gRPC height-stream admission or drop behavior changes, review the listener cap, retry behavior, and the requirement to backfill missed heights.
  • When a node resource becomes optional or changes its retained range, review RPC startup configuration and the errors returned for unavailable indexed or pruned data.
  • When block-range or data-root proof bounds change, review both the public route contract and client validation for end-exclusive ranges.
  • When transaction broadcast or status semantics change, review callers that use broadcast results to decide whether to poll or query for commitment.
  • When evidence validation or pool acceptance changes, review the evidence callers and the error contract exposed by each transport.
  • When a route joins or leaves the heavy-response group, update the OpenAPI 503 contract and the route-level saturation checks.
  • When batch transaction status rules change, keep the route behavior, OpenAPI limit, result order, and client request shape aligned.
  • When JSON-RPC batch admission or response writing changes, keep the one-slot batch behavior and slot lifetime aligned for URI and JSON-RPC requests.
  • When JSON-RPC request validation or envelope behavior changes, review URI, HTTP, WebSocket, batch, notification, and client error handling together.
  • When block search response limits or pruning behavior changes, keep the stored-size admission rule, single-block exception, and returned-page behavior aligned.
  • When ABCI query paths change, keep the dedicated transaction and share inclusion-proof routes separate from general application queries. Review path matching for leading slashes and case-sensitive route names.

Important failure modes

TriggerConsequenceGuard
A required node resource is not available when RPC startsThe node cannot configure a complete RPC service contextKeep ConfigureRPC resource setup aligned with the capabilities enabled by the route set
A caller asks for a pruned block or uses a disabled transaction or block indexThe query returns an unavailable or disabled-index errorCheck the node's retained height and index configuration before relying on historical search
The shared heavy-response budget is fullLarge HTTP, WebSocket, or gRPC requests fail fast while light requests continueSize max_concurrent_heavy_requests against spare memory and retry rejected heavy requests with backoff
A heavy JSON-RPC batch uses more than one shared slot or releases its slot before the response is writtenThe batch can reject its own heavy calls or allow too many large response buffers at oncePreserve one slot per heavy batch and hold it through response writing
A block-search page exceeds 64 MiB across multiple retained blocksThe page is rejected before block contents are loadedLower per_page or query smaller blocks; use per_page=1 to keep an oversized single block reachable
A JSON-RPC response exceeds the client's configured body limitThe client rejects the response before decoding itSet SetMaxResponseBodyBytes to a bound that fits the largest expected result
A caller uses broadcast_tx_commit for normal production trafficThe call can hold the request until commit and still return a non-OK application result without a transport errorUse synchronous or asynchronous broadcast and track commitment through status or events
A WebSocket consumer reads too slowlyResponses can time out, events can be dropped, or the connection can be canceledRead responses promptly and backfill chain data after a gap
A client exceeds the configured subscription or query limitsThe subscription request is rejected before event delivery startsKeep client and query counts within the node's configured limits
A gRPC height stream reaches the listener capThe new stream receives ResourceExhausted and no listener is registeredLimit concurrent streams and retry after an active stream ends
A gRPC height listener is slowIts pending height event can be dropped without blocking other listenersUse the height event as a prompt and query blocks by height to backfill
The gRPC event-bus subscription closes and recovery also failsThe height stream stops receiving new block eventsMonitor the stream and retry the client request when the service returns an error
Submitted evidence is missing, invalid, or rejected by the evidence poolThe node returns an error and does not queue the evidenceValidate evidence before submission and handle pool rejection as a failed write
A gRPC block stream loses a part or the stream closesThe caller receives an incomplete block responseTreat the stream as one response made of parts and retry the block request when it fails
A data-root request uses a missing block metadata record, an invalid range, or more than 10,000 blocksCommitment or proof generation fails instead of producing verifiable dataKeep the range within retained chain data, use a non-empty end-exclusive range within the current height, and stay within the request limit
A share proof request has a start at or after its endThe request fails before it can produce a proofSend a non-empty end-exclusive share range
A genesis request arrives while the heavy-response budget is fullThe full or chunked genesis route returns service unavailableRetry with backoff and reserve capacity for large genesis responses
A batch status request contains more than 20 hashesThe request is rejected instead of returning a complete status listSplit the request into batches of 20 or fewer hashes
A caller sends malformed JSON-RPC input or expects a reply to a notificationThe server returns a parse or request error, or sends no response for the notificationTreat JSON-RPC errors and notification silence as part of the protocol contract
An application sends a transaction or share inclusion-proof path through abci_queryThe request is rejected before it reaches the applicationUse the dedicated inclusion-proof routes, which use block data owned by the node

Key files

FileWhy to read it
node/node.goShows how node resources are assembled into the RPC service context and how HTTP, WebSocket, and gRPC listeners start and stop.
rpc/…/routes.goDefines the public capability names, marks WebSocket-only routes, and applies the heavy-response budget.
rpc/…/routes_test.goConfirms that full and chunked genesis responses honor the shared heavy-request limit.
rpc/…/env.goDescribes the shared service context, block-search response bound, and cross-transport response limit.
rpc/…/fuzz_env_test.goBuilds a deterministic RPC environment with committed chain data and the supporting node services used by handler and transport checks.
rpc/…/status.goShows the information represented by the node status view.
rpc/…/blocks.goShows the chain data, signed-block, search, commitment, and proof results exposed to callers.
rpc/…/blocks_test.goConfirms block range validation, data-root proof bounds, share-range validation, and block-search response-size behavior.
rpc/…/handlers_fuzz_test.goExercises the core capability groups through varied transaction, search, event, block, validator, and proof inputs.
rpc/…/abci.goDefines the application query and info boundary, including the separation between general queries and dedicated inclusion-proof routes.
rpc/…/abci_test.goConfirms that inclusion-proof paths are rejected by general application queries while other paths reach the application.
rpc/…/tx.goShows transaction broadcast, lookup, proof, and status behavior, including batch status limits and deprecated lookup routes.
rpc/…/evidence.goShows how the API validates and queues evidence submitted by a caller.
rpc/…/events.goShows subscription limits, event delivery, and slow-client handling.
rpc/…/http_json_handler.goExplains JSON-RPC request parsing, batch and notification behavior, response writing, and heavy-response admission.
rpc/…/jsonrpc_fuzz_test.goChecks JSON-RPC behavior across HTTP POST, URI GET, WebSocket frames, batches, notifications, malformed input, and response envelopes.
rpc/…/http_json_handler_test.goConfirms notification behavior and heavy-response slot use through response writing.
rpc/…/ws_handler.goExplains the long-lived WebSocket request, response, event, and connection boundary.
rpc/…/ws_handler_test.goConfirms WebSocket upgrade and request-response behavior.
rpc/…/http_json_client.goShows endpoint normalization, JSON-RPC calls, batching, and response-size protection for remote clients.
rpc/…/api.goDescribes typed status, block, broadcast, proof, and new-height stream capabilities.
rpc/…/api_test.goConfirms listener caps, cleanup, slow-listener isolation, and new-height event fields.
rpc/…/interceptor.goShows how gRPC applies the shared limit to large responses while keeping long-lived height streams separate.
proto/…/types.protoDefines the typed gRPC services and their message-level contract.
rpc/…/grpc_fuzz_test.goExercises the legacy typed gRPC broadcast, block, commit, validator, and proof calls over an in-memory transport.
rpc/…/openapi.yamlDescribes the public HTTP and JSON-RPC routes, response shapes, and service-unavailable contract.
rpc/…/interface.goDefines the high-level client capability contract.
rpc/…/http.goShows the remote client model, batching, and event subscription behavior.
rpc/…/local.goShows the in-process client model.