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 / abci-application-integration

ABCI application integration

ABCI (Application Blockchain Interface) is the boundary between the CometBFT consensus node and a deterministic application state machine. The node sends typed requests for queries, transaction checks, block execution, state commit, vote extensions, and state sync. The application returns typed results that guide consensus and define the next application state.

Integration boundary

The application boundary presents one application contract while supporting local and remote execution. CometBFT uses the same application operations whether the application runs in the node process or behind a socket or gRPC service.

Application contract

An ABCI application implements the types.Application contract in abci/…/application.go. The contract groups operations by the work they support:

  • Query operations read application state and report application information.
  • Mempool operations check transactions before they enter the node's pending transaction set.
  • Consensus operations initialize the chain, shape and assess proposals, execute decided blocks, commit state, and handle vote extensions.
  • State sync operations list snapshots and exchange snapshot chunks during application restore.

The application owns its state and the meaning of application results. The node owns consensus and uses results such as transaction status, the application hash, validator updates, consensus parameter updates, and proposal status to advance the chain.

References: abci/…/application.go• L7-36 proto/…/types.proto• L81-89 proto/…/types.proto• L134-209 proto/…/types.proto• L265-399

Connection roles

CometBFT separates application work into four logical connections. The split prevents a query or a pending transaction check from being confused with consensus work, while each connection still uses the same ABCI request and response model.

ConnectionMain responsibilityOperations
QueryRead state and identify the applicationEcho, Info, Query
MempoolCheck pending transactionsCheckTx, QuerySequence, Flush
ConsensusDrive chain execution and votingInitChain, proposal methods, vote-extension methods, FinalizeBlock, Commit
SnapshotRestore application stateListSnapshots, OfferSnapshot, LoadSnapshotChunk, ApplySnapshotChunk

The proxy layer exposes these roles as narrow interfaces. This keeps a caller from sending a consensus-only request through a query or mempool connection. The node creates one client for each role through a shared client creator.

References: proxy/multi_app_conn.go• L12-32 proxy/multi_app_conn.go• L61-68 proxy/app_conn.go• L18-54 proxy/multi_app_conn.go• L87-117

Client connections

ABCI clients hide the transport from the node services that use them. A client provides the application contract plus service lifecycle, transport error reporting, response callbacks, and the asynchronous transaction-check path needed by the mempool.

Client selection

The client factory selects a socket or gRPC client from the configured transport. A local client wraps an application directly and uses a mutex to preserve the selected application access model. The proxy can therefore use an embedded application for tests or a separate application process in production without changing the higher-level connection roles.

The mustConnect choice changes startup behavior for remote clients. A strict client fails if it cannot connect during startup. A non-strict client keeps retrying so the node can wait for an application that starts later.

References: abci/…/client.go• L20-57 abci/…/local_client.go• L25-39 abci/…/socket_client.go• L49-91 abci/…/grpc_client.go• L36-49 abci/…/grpc_client.go• L56-119 proxy/client.go• L15-19 proxy/client.go• L73-99

Connection assembly

The multi-connection proxy creates the query, snapshot, mempool, and consensus clients as one service. It starts them in sequence and stops all clients if a later connection cannot start. If a running client reports a transport or application exception, the proxy treats that connection loss as an application failure and stops the node process.

The role wrappers also record method timing. Their main purpose is to preserve the boundary between node subsystems and the full ABCI client, not to change application results.

References: proxy/multi_app_conn.go• L39-68 proxy/multi_app_conn.go• L87-127 proxy/multi_app_conn.go• L129-180 proxy/app_conn.go• L57-111 proxy/app_conn.go• L113-227

Request lifecycle

Each ABCI operation moves from a node service to a client, across the selected boundary, into an application method, and back as a typed response. The exact transport changes the message handling, but the application-facing lifecycle remains the same.

Synchronous request path

For a normal request, the caller supplies a context and a typed request. The client sends it and waits for the matching response. The caller receives either a transport error or the application response, whose application-level status is carried in response fields such as a code or status.

The socket path wraps requests and responses in a common protobuf oneof envelope. It queues requests, records them before sending, tracks them in send order, and matches each response to the first pending request. A flush marks the point at which buffered socket data must be written and read back. This ordering also protects the client from a fast server response that arrives before the request is recorded.

The following diagram shows the common request path and the transport-specific split.

sequenceDiagram
    participant N as Node service
    participant C as ABCI client
    participant T as Socket or gRPC transport
    participant S as ABCI server
    participant A as Application
    N->>C: Typed request with context
    alt In-process application
        C->>A: Application method call
        A-->>C: Typed response or error
    else Socket or gRPC application
        C->>T: Encode and send request
        T->>S: Deliver request
        S->>A: Call application method
        A-->>S: Typed response or error
        S-->>T: Encode response
        T-->>C: Deliver matching response
    end
    C-->>N: Response or transport error

References: abci/…/client.go• L20-42 abci/…/socket_client.go• L129-191 abci/…/socket_client.go• L194-236 abci/…/socket_client.go• L241-269 abci/…/grpc_client.go• L184-251 abci/…/local_client.go• L84-192

Asynchronous transaction checks

CheckTxAsync is the exception to the normal synchronous pattern. The mempool can submit a check and handle its result later through a request result or callback. Socket clients complete the result when the ordered response arrives. gRPC clients receive the result from the unary call but delay completion and callback delivery until results pass through an ordered dispatch queue.

This ordering matters because callbacks can update mempool state while callers hold locks. The client also supports a global response callback for connection users and a request-specific callback for one pending request.

References: abci/…/client.go• L60-115 abci/…/socket_client.go• L113-125 abci/…/socket_client.go• L194-236 abci/…/grpc_client.go• L27-46 abci/…/grpc_client.go• L61-86 abci/…/grpc_client.go• L164-179 proxy/app_conn.go• L128-153

Error and shutdown path

Transport failures are client errors. They include failed reads, failed writes, connection loss, and responses that do not match the request that was sent. Application errors are returned as application responses when the application reports a transaction or query failure. A server-side exception is different: it is sent as an exception response and closes the socket connection.

When a client stops, it closes its connection and completes queued or in-flight request results so callers do not wait forever. The socket client clears its pending-response list during this cleanup. A response that arrives after cleanup is rejected as unexpected rather than completing a request that was already resolved. The proxy then uses the client error to decide whether the node must stop.

References: abci/…/client.go• L20-25 abci/…/socket_client.go• L165-188 abci/…/socket_client.go• L206-236 abci/…/socket_client.go• L447-471 abci/…/socket_client.go• L515-529 abci/…/socket_client_internal_test.go• L11-21 abci/…/socket_server.go• L201-215 abci/…/socket_server.go• L320-344 proxy/multi_app_conn.go• L129-157

Server implementations

An ABCI server adapts a transport request to the application contract and adapts the application result back to the transport. The server factory supports socket and gRPC listeners for applications that run outside the node process.

In-process integration

The in-process path does not open a network listener. A local client calls the application methods directly and places one shared mutex around calls when the local client creator selects shared synchronization. This path removes serialization and connection failure from the boundary, so it is useful for embedded applications and tests but does not validate remote transport behavior.

References: abci/…/local_client.go• L11-39 abci/…/local_client.go• L47-58 abci/…/local_client.go• L88-192 proxy/client.go• L21-70

Socket integration

The socket server listens on a TCP or Unix address and accepts multiple connections. Each connection reads length-delimited protobuf messages, calls the matching application method, and writes responses in order. The server serializes application calls through its application lock and flushes its buffered writer when it receives a flush request.

The socket protocol is a raw ordered message path. A request or response is encoded as a protobuf message with an unsigned-varint length prefix. An application error becomes an exception response and ends the connection so both sides can stop with the same failure.

References: abci/…/server.go• L17-30 abci/…/socket_server.go• L20-54 abci/…/socket_server.go• L62-71 abci/…/socket_server.go• L114-141 abci/…/socket_server.go• L162-215 abci/…/socket_server.go• L320-346 abci/…/messages.go• L16-26

gRPC integration

The gRPC server registers the generated ABCI service on a TCP or Unix listener. Each RPC maps to one application operation, while Echo and Flush provide transport-level health and buffer operations. The gRPC client waits for an echo response before it reports startup success, which confirms that the service is ready rather than only that a connection object exists.

The generated service contract is the source of the gRPC method names and typed request and response pairs. The server wrapper supplies the small transport-specific methods and delegates application work through the shared application interface.

References: abci/…/grpc_server.go• L27-65 abci/…/grpc_server.go• L69-84 abci/…/grpc_client.go• L88-118 abci/…/types.pb.go• L4236-4257 abci/…/types.pb.go• L4420-4499

Compatibility versioning

ABCI compatibility depends on more than a package version. The node and application must agree on the ABCI protocol schema, method set, and the meaning of request and response fields. The protocol version is reported through the information exchange and is also held as a repository-wide semantic version.

Version signals

The node sends its version, block protocol version, peer-to-peer protocol version, and ABCI version in RequestInfo. The application returns its own version and application version in ResponseInfo. The current repository ABCI semantic version is 2.0.0, exposed to the ABCI package through abci/version.

These values identify compatibility information. They do not replace the generated bindings or the protobuf schema. A change to a message or RPC method must keep the schema, generated client and server contracts, and application interface aligned.

References: proto/…/types.proto• L74-79 proto/…/types.proto• L253-263 version/version.go• L3-9 abci/…/version.go• L1-9

Generated binding relationship

The protobuf definition in proto/…/types.proto defines the wire messages and the gRPC service. Generated code in abci/…/types.pb.go gives Go clients, servers, message types, and registration functions. Hand-written adapters in the client and server packages connect those generated contracts to local application methods.

For protocol definitions and the code-generation layout, see ABCI protocol and types. That child page is the detailed reference for request fields, response fields, version contracts, and generated bindings.

References: proto/…/types.proto• L20-40 proto/…/types.proto• L45-66 abci/…/types.pb.go• L4236-4257 abci/…/types.pb.go• L4420-4499 scripts/proto-gen.sh• L1-80

Change checklist

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

  • Keep the four connection role interfaces aligned with the clients created by multiAppConn. A new application operation must have a clear owning role.
  • Keep client and server transport selection aligned. The same address scheme and transport name must work through the client factory, server factory, and node configuration.
  • Keep socket request order, response matching, and flush behavior aligned on both sides. A change can otherwise turn a valid response into an unexpected-response failure.
  • Keep socket shutdown cleanup aligned with response handling. Late responses must be rejected safely after queued and in-flight requests are resolved.
  • Keep application exceptions distinct from application-level response codes. Changing one error path can change whether the node continues or stops.
  • Keep the protobuf service, generated bindings, application interface, and transport adapters aligned when adding or changing an ABCI method.
  • Keep the reported ABCI version aligned with schema and method compatibility. A version change without matching bindings can leave peers and applications unable to interoperate.

Important failure modes

TriggerConsequenceGuard
The node and application use different ABCI message or method definitionsRequests fail to decode, bind to the wrong method, or return incomplete resultsRegenerate bindings from the shared protobuf definition and review the application interface together with transport adapters
A remote application is unavailable at client start with strict connection modeThe ABCI client does not start and the node cannot assemble its application connectionsUse strict mode only when the application must be ready at startup; otherwise allow retry behavior
A socket response arrives without a matching pending request or in the wrong type orderThe client stops because it cannot associate the response with a requestPreserve ordered request tracking and return one matching response for each request; keep late-response handling safe after shutdown cleanup
An application method returns an error that the socket server turns into an exceptionThe server closes the connection and the proxy can stop the nodeTreat application errors as part of the ABCI contract and inspect the client error before retry or recovery
One of the four application clients fails after startupThe proxy reports an application failure and stops CometBFTRun the application with all required connection roles and monitor each client lifecycle
The application reports a version or schema that does not match the nodeStartup health checks may pass while later requests fail or produce incompatible state resultsCheck the ABCI version and generated bindings as one compatibility unit

Key files

FileWhy to read it
abci/…/application.goDefines the application-facing contract and groups operations by connection role.
proxy/multi_app_conn.goShows how the node creates, owns, and stops the four application connections.
proxy/app_conn.goShows the narrow role interfaces that protect request ownership between node subsystems.
abci/…/client.goDefines the transport-neutral client contract and request callback model.
abci/…/socket_client.goShows ordered socket requests, response matching, flush behavior, and safe shutdown cleanup.
abci/…/socket_client_internal_test.goShows the guard for a late response after pending requests are cleared during shutdown.
abci/…/grpc_client.goShows gRPC startup health checks and ordered asynchronous callback delivery.
abci/…/local_client.goShows the in-process application path and local synchronization boundary.
abci/…/socket_server.goShows socket listener lifecycle and request-to-application dispatch.
abci/…/grpc_server.goShows gRPC service registration and transport wrapper behavior.
proto/…/types.protoDefines the ABCI wire messages and gRPC service contract.
abci/…/types.pb.goProvides the generated Go message, client, server, and registration bindings.
version/version.goDefines the repository ABCI semantic version reported for compatibility.
abci/…/client_server_test.goDemonstrates the basic server and client startup boundary for a socket application.