本文基于 Fabric v2.0.1
,与 v1.x
版不同,v2
版将 protos
定义放到一个独立仓库 fabric-protos 进行管理,并且使用 protoc
工具生成的具体语言代码也使用独立的仓库存放,如 golang
版 fabric-protos-go。
服务定义于 orderer/ab.proto
service AtomicBroadcast {
// broadcast receives a reply of Acknowledgement for each common.Envelope in order, indicating success or type of failure
rpc Broadcast(stream common.Envelope) returns (stream BroadcastResponse);
// deliver first requires an Envelope of type DELIVER_SEEK_INFO with Payload data as a mashaled SeekInfo message, then a stream of block replies is received.
rpc Deliver(stream common.Envelope) returns (stream DeliverResponse);
}
Broadcast
接口用于接收待排序的消息,包括普通事务 tx
消息和 channel
配置消息。
客户端将事务消息提交到 endorsing peers
预执行 chaincode
并背书读写集结果,由客户端将返回结果提交到 Orderer
进行排序。
Deliver
接口用于向 peers
分发已经过排序 block
数据,peer
节点通过 join channel
从 Orderer
获取已排序的 block
。
服务定义于 orderer/cluster.proto
// Cluster defines communication between cluster members.
service Cluster {
// Step passes an implementation-specific message to another cluster member.
rpc Step(stream StepRequest) returns (stream StepResponse);
}
Fabric v1.1 之后支持 EtcdRaft
共识算法,与使用 Kafka
共识算法各orderer
独立连接中心化的 kafka
集群不同,使用 EtcdRaft
共识算法各 orderer
组成一个集群, Step
用于集群节点间消息交换。
服务定义于 peer/peer.proto
service Endorser {
rpc ProcessProposal(SignedProposal) returns (ProposalResponse);
}
ProcessProposal
接口用于客户端将已签名的事务消息提交到 endorsing peers
进行预执行并背书读写集。所谓预执行是指使用当前本地账本状态执行 chaincode
生成读写集,但执行结果不写入账本。
服务定义于 peer/events.proto
service Deliver {
// Deliver first requires an Envelope of type ab.DELIVER_SEEK_INFO with
// Payload data as a marshaled orderer.SeekInfo message,
// then a stream of block replies is received
rpc Deliver (stream common.Envelope) returns (stream DeliverResponse) {
}
// DeliverFiltered first requires an Envelope of type ab.DELIVER_SEEK_INFO with
// Payload data as a marshaled orderer.SeekInfo message,
// then a stream of **filtered** block replies is received
rpc DeliverFiltered (stream common.Envelope) returns (stream DeliverResponse) {
}
// DeliverWithPrivateData first requires an Envelope of type ab.DELIVER_SEEK_INFO with
// Payload data as a marshaled orderer.SeekInfo message,
// then a stream of block and private data replies is received
rpc DeliverWithPrivateData (stream common.Envelope) returns (stream DeliverResponse) {
}
}
Deliver
接口用于向客户端分发已写入本地账本的 block
数据。客户端将 endorsing peers
返回的结果提交给 orderer
后,等待 peer
通知事务处理完毕。
DeliverWithPrivateData
v2.0 版本新增,分发带私密数据的 block
数据
服务定义于 peer/chaincode_shim.proto
// Interface that provides support to chaincode execution. ChaincodeContext
// provides the context necessary for the server to respond appropriately.
service ChaincodeSupport {
rpc Register(stream ChaincodeMessage) returns (stream ChaincodeMessage);
}
Register
用于 Chaincode
启动时向 peer
注册当前 Chaincode
服务定义于 peer/chaincode_shim.proto
// Chaincode as a server - peer establishes a connection to the chaincode as a client
// Currently only supports a stream connection.
service Chaincode {
rpc Connect(stream ChaincodeMessage) returns (stream ChaincodeMessage);
}
v2
新增服务,Chaincode
启动并作为服务端,由 peer
通过 Connect
接口连接 Chaincode
服务定义于 gossip/message.proto
// Gossip
service Gossip {
// GossipStream is the gRPC stream used for sending and receiving messages
rpc GossipStream (stream Envelope) returns (stream Envelope);
// Ping is used to probe a remote peer's aliveness
rpc Ping (Empty) returns (Empty);
}
为减轻 Orderer
压力,组织内只有少量 peer
连接 orderer
获取最新 block
,组织内各 peer
通过 Gossip
互联,通过 Gossip
交换 block
数据及私密数据。
服务定义于 discovery/protocol.proto
// Discovery defines a service that serves information about the fabric network
// like which peers, orderers, chaincodes, etc.
service Discovery {
// Discover receives a signed request, and returns a response.
rpc Discover (SignedRequest) returns (Response);
}
Discovery
服务用于方便客户端获取整个 Fabric
网络的情况,只需要知道一个初始节点便可查询到 channel
内的 peers
、config
、membership
、chaincode
等。
参考: