示例讲解
我们首先与应用程序建立三个连接(mempool、consensus 和 query)。
此处应用程序是在本地运行的 kvstore。
prevote,然后是 precommit,最后进入提交区块的阶段。详情请参阅拜占庭共识算法。
模块列表
下面列出你可能会在 CometBFT 日志中遇到的模块,并简要说明它们的作用。abci-client如应用开发指南中所述,相对于应用程序,CometBFT 充当一个 ABCI 客户端,并维护 3 条连接:mempool、consensus和query。CometBFT 使用的代码可在这里找到。blockchain为区块存储以及节点之间区块的交换提供存储、池(peer 组)和 reactor。consensusCometBFT 的核心,即共识算法的实现。它还包含两个“子模块”:wal(预写日志)用于确保数据完整性,replay用于在崩溃恢复时重放区块和消息。events简单的事件通知系统。事件列表可在这里找到。你可以通过调用subscribeRPC 方法订阅这些事件。更多信息请参阅 RPC 文档。mempoolmempool模块负责处理所有传入交易,无论这些交易来自 peer 还是应用程序。p2p提供点对点通信的抽象。更多细节请查看 README。rpcCometBFT 的 RPC。rpc-serverRPC 服务器。实现细节请阅读 doc.go。state表示最新状态以及执行子模块,负责对照应用程序执行区块。types对外公开的类型及其相关方法集合。
Walkthrough example
We first create three connections (mempool, consensus, and query) to the application (runningkvstore locally in this case).
List of modules
Here is the list of modules you may encounter in CometBFT’s logs and a brief overview of what they do.abci-clientAs mentioned in Application Development Guide, CometBFT acts as an ABCI client with respect to the application and maintains 3 connections: mempool, consensus, and query. The code used by CometBFT can be found here.blockchainProvides storage, pool (a group of peers), and reactor for both storing and exchanging blocks between peers.consensusThe heart of CometBFT, which is the implementation of the consensus algorithm. Includes two “submodules”:wal(write-ahead logging) for ensuring data integrity andreplayto replay blocks and messages on recovery from a crash.eventsSimple event notification system. The list of events can be found here. You can subscribe to them by callingsubscribeRPC method. Refer to RPC docs for additional information.mempoolMempool module handles all incoming transactions, whenever they are coming from peers or the application.p2pProvides an abstraction around peer-to-peer communication. For more details, please check out the README.rpcCometBFT’s RPC.rpc-serverRPC server. For implementation details, please read the doc.go.stateRepresents the latest state and execution submodule, which executes blocks against the application.typesA collection of the publicly exposed types and methods to work with them.