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.
| Transport | Main use | Interaction shape |
|---|---|---|
| URI over HTTP | Simple scripts and inspection | One endpoint per RPC method with query parameters |
| JSON-RPC over HTTP | General remote calls | Single requests or bounded batches with structured results and errors |
| JSON-RPC over WebSocket | Event-driven clients | Requests and asynchronous subscription results on /websocket |
| gRPC | Typed block, status, broadcast, and proof access | Protocol-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.
| Client | Connection model | Best fit |
|---|---|---|
| HTTP client | JSON-RPC over HTTP plus WebSocket events | Remote applications and operators |
| Local client | Direct calls into a node | In-process applications and tests |
| Mock client | Controlled responses behind the same client shape | Tests that need chosen node results |
| gRPC clients | Typed calls to the gRPC services | Consumers 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
| Trigger | Consequence | Guard |
|---|---|---|
| A required node resource is not available when RPC starts | The node cannot configure a complete RPC service context | Keep 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 index | The query returns an unavailable or disabled-index error | Check the node's retained height and index configuration before relying on historical search |
| The shared heavy-response budget is full | Large HTTP, WebSocket, or gRPC requests fail fast while light requests continue | Size 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 written | The batch can reject its own heavy calls or allow too many large response buffers at once | Preserve one slot per heavy batch and hold it through response writing |
| A block-search page exceeds 64 MiB across multiple retained blocks | The page is rejected before block contents are loaded | Lower 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 limit | The client rejects the response before decoding it | Set SetMaxResponseBodyBytes to a bound that fits the largest expected result |
A caller uses broadcast_tx_commit for normal production traffic | The call can hold the request until commit and still return a non-OK application result without a transport error | Use synchronous or asynchronous broadcast and track commitment through status or events |
| A WebSocket consumer reads too slowly | Responses can time out, events can be dropped, or the connection can be canceled | Read responses promptly and backfill chain data after a gap |
| A client exceeds the configured subscription or query limits | The subscription request is rejected before event delivery starts | Keep client and query counts within the node's configured limits |
| A gRPC height stream reaches the listener cap | The new stream receives ResourceExhausted and no listener is registered | Limit concurrent streams and retry after an active stream ends |
| A gRPC height listener is slow | Its pending height event can be dropped without blocking other listeners | Use the height event as a prompt and query blocks by height to backfill |
| The gRPC event-bus subscription closes and recovery also fails | The height stream stops receiving new block events | Monitor the stream and retry the client request when the service returns an error |
| Submitted evidence is missing, invalid, or rejected by the evidence pool | The node returns an error and does not queue the evidence | Validate evidence before submission and handle pool rejection as a failed write |
| A gRPC block stream loses a part or the stream closes | The caller receives an incomplete block response | Treat 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 blocks | Commitment or proof generation fails instead of producing verifiable data | Keep 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 end | The request fails before it can produce a proof | Send a non-empty end-exclusive share range |
| A genesis request arrives while the heavy-response budget is full | The full or chunked genesis route returns service unavailable | Retry with backoff and reserve capacity for large genesis responses |
| A batch status request contains more than 20 hashes | The request is rejected instead of returning a complete status list | Split the request into batches of 20 or fewer hashes |
| A caller sends malformed JSON-RPC input or expects a reply to a notification | The server returns a parse or request error, or sends no response for the notification | Treat JSON-RPC errors and notification silence as part of the protocol contract |
An application sends a transaction or share inclusion-proof path through abci_query | The request is rejected before it reaches the application | Use the dedicated inclusion-proof routes, which use block data owned by the node |
Key files
| File | Why to read it |
|---|---|
| node/node.go | Shows how node resources are assembled into the RPC service context and how HTTP, WebSocket, and gRPC listeners start and stop. |
| rpc/…/routes.go | Defines the public capability names, marks WebSocket-only routes, and applies the heavy-response budget. |
| rpc/…/routes_test.go | Confirms that full and chunked genesis responses honor the shared heavy-request limit. |
| rpc/…/env.go | Describes the shared service context, block-search response bound, and cross-transport response limit. |
| rpc/…/fuzz_env_test.go | Builds a deterministic RPC environment with committed chain data and the supporting node services used by handler and transport checks. |
| rpc/…/status.go | Shows the information represented by the node status view. |
| rpc/…/blocks.go | Shows the chain data, signed-block, search, commitment, and proof results exposed to callers. |
| rpc/…/blocks_test.go | Confirms block range validation, data-root proof bounds, share-range validation, and block-search response-size behavior. |
| rpc/…/handlers_fuzz_test.go | Exercises the core capability groups through varied transaction, search, event, block, validator, and proof inputs. |
| rpc/…/abci.go | Defines the application query and info boundary, including the separation between general queries and dedicated inclusion-proof routes. |
| rpc/…/abci_test.go | Confirms that inclusion-proof paths are rejected by general application queries while other paths reach the application. |
| rpc/…/tx.go | Shows transaction broadcast, lookup, proof, and status behavior, including batch status limits and deprecated lookup routes. |
| rpc/…/evidence.go | Shows how the API validates and queues evidence submitted by a caller. |
| rpc/…/events.go | Shows subscription limits, event delivery, and slow-client handling. |
| rpc/…/http_json_handler.go | Explains JSON-RPC request parsing, batch and notification behavior, response writing, and heavy-response admission. |
| rpc/…/jsonrpc_fuzz_test.go | Checks JSON-RPC behavior across HTTP POST, URI GET, WebSocket frames, batches, notifications, malformed input, and response envelopes. |
| rpc/…/http_json_handler_test.go | Confirms notification behavior and heavy-response slot use through response writing. |
| rpc/…/ws_handler.go | Explains the long-lived WebSocket request, response, event, and connection boundary. |
| rpc/…/ws_handler_test.go | Confirms WebSocket upgrade and request-response behavior. |
| rpc/…/http_json_client.go | Shows endpoint normalization, JSON-RPC calls, batching, and response-size protection for remote clients. |
| rpc/…/api.go | Describes typed status, block, broadcast, proof, and new-height stream capabilities. |
| rpc/…/api_test.go | Confirms listener caps, cleanup, slow-listener isolation, and new-height event fields. |
| rpc/…/interceptor.go | Shows how gRPC applies the shared limit to large responses while keeping long-lived height streams separate. |
| proto/…/types.proto | Defines the typed gRPC services and their message-level contract. |
| rpc/…/grpc_fuzz_test.go | Exercises the legacy typed gRPC broadcast, block, commit, validator, and proof calls over an in-memory transport. |
| rpc/…/openapi.yaml | Describes the public HTTP and JSON-RPC routes, response shapes, and service-unavailable contract. |
| rpc/…/interface.go | Defines the high-level client capability contract. |
| rpc/…/http.go | Shows the remote client model, batching, and event subscription behavior. |
| rpc/…/local.go | Shows the in-process client model. |