CometBFT 是一个分布式的、拜占庭容错的状态机复制引擎。同时也是 tendermint 的继任者。
CometBFT 提供了一个区块链分布式框架,允许用户实现简单的接口来得到一个分布式的、拜占庭容错的应用程序。
CometBFT 提供了: - 分布式网络通信。 - 基于 tendermint 的共识协议。 - 基于 ABCI 定义的 RPC 接口。 - 数据加密和签名。 - 不透明的消息交换(交易)。 CometBFT 没有提供:
可以将 CometBFT 简单理解为一个分布式数据库系统,当数据库发送数据变更(或相关事件)时会通过接口(Application 接口)通知用户,从而允许用户执行相应的操作。其中 CometBFT 对数据的具体内容是不可知的,其只了解数据发生了变更。 |
CometBFT 的大致结构如下:
用户程序通过实现 ABCI 中的 Application 接口来实现一个事件处理器。CometBFT 在发生事件时会通知应用程序,从而允许应用程序实现自己的逻辑。
type Application interface {
// Info/Query Connection
Info(RequestInfo) ResponseInfo // Return application info
SetOption(RequestSetOption) ResponseSetOption // Set application option
Query(RequestQuery) ResponseQuery // Query for state
// Mempool Connection
CheckTx(RequestCheckTx) ResponseCheckTx // Validate a tx for the mempool
// Consensus Connection
InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain w validators/other info from TendermintCore
BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
DeliverTx(RequestDeliverTx) ResponseDeliverTx // Deliver a tx for full processing
EndBlock(RequestEndBlock) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
// State Sync Connection
ListSnapshots(RequestListSnapshots) ResponseListSnapshots // List available snapshots
OfferSnapshot(RequestOfferSnapshot) ResponseOfferSnapshot // Offer a snapshot to the application
LoadSnapshotChunk(RequestLoadSnapshotChunk) ResponseLoadSnapshotChunk // Load a snapshot chunk
ApplySnapshotChunk(RequestApplySnapshotChunk) ResponseApplySnapshotChunk // Apply a shapshot chunk
}
每个方法的具体作用参见 ACBI::methods
mempool 提供了对重放攻击的基本保护,但是应用程序应当实现自己的重放攻击保护策略。 |
并发
原则上来讲,ABCI 的四个连接是并行发生的。实际上在处理每个连接时都会加一个全局锁,这意味着事件处理是串行的,因此可以无须保护应用状态。