消息协议与同步性
消息协议由请求与响应成对组成,其定义见protobuf 文件。 有些消息不包含任何字段,另一些则可能包含字节数组、字符串、整数, 或自定义 protobuf 类型。 有关 protobuf 的更多细节,请参阅文档。服务端实现
要在你选择的编程语言中使用 ABCI,该语言中必须有一个 ABCI 服务端。CometBFT 支持四种 ABCI 服务端实现:- 在 CometBFT 仓库中:
- 进程内
- ABCI-socket
- GRPC
- tendermint-rs
- tower-abci
--abci 参数,使用 abci-cli 进行测试。
可参考以下示例,它们处于不同的维护阶段:
Go、
JavaScript,以及
Java。
进程内
最简单的实现方式是在 Golang 中使用函数调用。 这意味着用 Golang 编写的 ABCI 应用可以与 CometBFT 链接,并作为单个二进制程序运行。GRPC
如果你使用的不是 Golang, 但你的语言支持 GRPC,那么这是最简单的方案, 不过它会带来明显的性能开销。 请查阅 GRPC 的文档,了解如何将应用设置为一个 ABCI GRPC 服务端。Socket
CometBFT Socket Protocol 是一种异步的原始套接字服务端协议,可通过 Unix 或 TCP 套接字提供有序的 消息传递。消息使用 Protobuf3 序列化,并以前缀长度方式编码,长度前缀采用 unsigned varint。 如果你的语言不支持 gRPC,或者你需要更高性能,或者 你只是喜欢底层编程,那么你可以使用 CometBFT Socket Protocol 实现自己的 ABCI 服务端。第一步仍然是使用protoc 在你的语言中自动生成
相关的数据类型和编解码器,然后你还需要
确保在从套接字读取和向套接字写入消息时,正确处理基于无符号 varint 的
消息长度编码方案。
请注意,我们的长度前缀方案不适用于 gRPC。
另请注意,你的 ABCI 服务端必须能够处理多个连接,
因为 CometBFT 会使用四个连接。
客户端
当前 ABCI 客户端主要有两种使用场景。其一是测试工具, 这些工具允许通过命令行将 ABCI 请求发送到实际应用。abci-cli 就是一个例子,它接收 CLI 命令,
并发送相应的 ABCI 请求。
另一种场景是共识引擎,例如 CometBFT,
它会按照所使用的共识算法规定,向应用发起 ABCI 请求。
This section is for those looking to implement their own ABCI Server, perhaps in a new programming language. You are expected to have read all previous sections of ABCI++ specification, namely Basic Concepts, Methods, Application Requirements, and Expected Behavior.
Message Protocol and Synchrony
The message protocol consists of pairs of requests and responses defined in the protobuf file. Some messages have no fields, while others may include byte-arrays, strings, integers, or custom protobuf types. For more details on protobuf, see the documentation.Server Implementations
To use ABCI in your programming language of choice, there must be an ABCI server in that language. CometBFT supports four implementations of the ABCI server:- in CometBFT’s repository:
- In-process
- ABCI-socket
- GRPC
- tendermint-rs
- tower-abci
abci-cli by setting
the --abci flag appropriately.
See examples, in various stages of maintenance, in
Go,
JavaScript, and
Java.
In Process
The simplest implementation uses function calls in Golang. This means ABCI applications written in Golang can be linked with CometBFT and run as a single binary.GRPC
If you are not using Golang, but GRPC is available in your language, this is the easiest approach, though it will have significant performance overhead. Please check GRPC’s documentation to know to set up the Application as an ABCI GRPC server.Socket
The CometBFT Socket Protocol is an asynchronous, raw socket server protocol which provides ordered message passing over Unix or TCP sockets. Messages are serialized using Protobuf3 and length-prefixed with an unsigned varint If gRPC is not available in your language, or you require higher performance, or otherwise enjoy programming, you may implement your own ABCI server using the CometBFT Socket Protocol. The first step is still to auto-generate the relevant data types and codec in your language usingprotoc, and then you need to
ensure you handle the unsigned varint-based message length encoding scheme
when reading and writing messages to the socket.
Note that our length prefixing scheme does not apply to gRPC.
Also note that your ABCI server must be able to handle multiple connections,
as CometBFT uses four connections.
Client
There are currently two use-cases for an ABCI client. One is testing tools that allow ABCI requests to be sent to the actual application via command line. An example of this isabci-cli, which accepts CLI commands
to send corresponding ABCI requests.
The other is a consensus engine, such as CometBFT,
which makes ABCI requests to the application as prescribed by the consensus
algorithm used.