fabric应用grpc解读

fabric应用grpc解读

++本代码解读基于fabric v1.4.4版本++

fabric proto文件主要集中在protos目录下,实现grpc服务的proto全在protos目录下,其中实现grpc服务的有:

一、discovery / 服务发现

discovery服务定义于discovery/protocol.proto:17,主要用于peer向cli/sdk提供查询服务,具体如下:

1、配置查询:返回通道中所有组织和排序节点的 MSPConfig。

2、节点成员查询:返回加入通道的 Peer 节点。

3、背书查询:返回通道中指定链码的背书描述。

4、本地节点成员查询:返回响应查询的 Peer节点的本地成员信息。默认情况下,需要管理员身份的客户端响应该查询。

// 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) {}
}

二、gossip

gossip服务定义于gossip/message.proto:14,主要用于peer节点在通道内同步账和发现通道节点,具体如下

1、通过持续的识别可用成员节点来管理节点发现和通道成员,还有检测离线节点。

2、向通道中的所有节点传播账本数据。所有没有和当前通道的数据同步的节点会识别丢失的区块,并将正确的数据复制过来以使自己同步。

3、通过点对点的数据传输方式,使新节点以最快速度连接到网络中并同步账本数据。

// gossip/message.proto:14
// 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) {}
}

三、order

1、broadcast

broadcast服务定义于orderer/ab.proto:88,主要用于定义cli向order提交交易的接口,以及order向peer发送区块,以及peer向order查询(区块)的接口

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) {}
}

2、cluster

cluster服务定义于orderer/cluster.proto:17,主要用于定义order节点们达成共识需要的通信接口

// 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);
}

四、peer

1、admin

admin服务定义于peer/admin.proto:19,现在主要用于管理员设置peer的日志级别(该服务被v2.0 beta删除了,GetLogSpec和SetLogSpec两个服务接口可调用HTTP operations service)

// Interface exported by the server.
service Admin {
    rpc GetStatus(common.Envelope) returns (ServerStatus) {}
    rpc StartServer(common.Envelope) returns (ServerStatus) {}
    rpc GetModuleLogLevel(common.Envelope) returns (LogLevelResponse) {}
    rpc SetModuleLogLevel(common.Envelope) returns (LogLevelResponse) {}
    rpc RevertLogLevels(common.Envelope) returns (google.protobuf.Empty) {}
    rpc GetLogSpec(common.Envelope) returns (LogSpecResponse) {}
    rpc SetLogSpec(common.Envelope) returns (LogSpecResponse) {}
}

2、chaincode

chaincode服务定义于peer/chaincode_shim.proto:179,主要用于定义peer和chaincode通信的消息类型

// 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) {}
}

消息类型定义于peer/chaincode_shim.pb.go:984,和core/chaincode/shim/interface.go的ChaincodeStubInterface接口对应,该接口是合约获取状态数据的接口

func init() {
	proto.RegisterType((*ChaincodeMessage)(nil), "protos.ChaincodeMessage")
	proto.RegisterType((*GetState)(nil), "protos.GetState")
	proto.RegisterType((*GetStateMetadata)(nil), "protos.GetStateMetadata")
	proto.RegisterType((*PutState)(nil), "protos.PutState")
	proto.RegisterType((*PutStateMetadata)(nil), "protos.PutStateMetadata")
	proto.RegisterType((*DelState)(nil), "protos.DelState")
	proto.RegisterType((*GetStateByRange)(nil), "protos.GetStateByRange")
	proto.RegisterType((*GetQueryResult)(nil), "protos.GetQueryResult")
	proto.RegisterType((*QueryMetadata)(nil), "protos.QueryMetadata")
	proto.RegisterType((*GetHistoryForKey)(nil), "protos.GetHistoryForKey")
	proto.RegisterType((*QueryStateNext)(nil), "protos.QueryStateNext")
	proto.RegisterType((*QueryStateClose)(nil), "protos.QueryStateClose")
	proto.RegisterType((*QueryResultBytes)(nil), "protos.QueryResultBytes")
	proto.RegisterType((*QueryResponse)(nil), "protos.QueryResponse")
	proto.RegisterType((*QueryResponseMetadata)(nil), "protos.QueryResponseMetadata")
	proto.RegisterType((*StateMetadata)(nil), "protos.StateMetadata")
	proto.RegisterType((*StateMetadataResult)(nil), "protos.StateMetadataResult")
	proto.RegisterEnum("protos.ChaincodeMessage_Type", ChaincodeMessage_Type_name, ChaincodeMessage_Type_value)
}

3、event

基于通道的节点事件服务定义于peer/events.proto:59,cli向order提交交易后,会等待peer的事件通知,当 Peer节点的账本中新增一个区块的时候该服务就会发送一个事件,有2种方式:

1、Deliver

该服务发送已经提交到账本的所有区块。可以在区块的 ChaincodeActionPayload 中查看链码设置的所有事件。

2、DeliverFiltered

该服务发送“经筛选”的区块,已经提交到账本的区块信息的最小集合。它用在 Peer 节点希望外部客户端主要用来接收交易的信息和状态的网络中。可以在区块的 FilteredChaincodeAction 中查看链码设置的所有事件。

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) {
    }
    // deliver 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) {
    }
}

4、peer

peer服务定义于peer/peer.proto:35,主要用于peer和cli通信。

peer在收到cli发过来的proposal后,将其发给chaincode,chaincode执行完之后将回复peer,chaincode执行期间需要读取的区块链状态数据通过grpc向peer请求。

service Endorser {
	rpc ProcessProposal(SignedProposal) returns (ProposalResponse) {}
}

5、token服务

token服务定义于token/prover.proto:220,是fabric的token框架,目前还没有使用

// Prover provides support to clients for the creation of FabToken transactions,
// and to query the ledger.
service Prover {
    // ProcessCommand processes the passed command ensuring proper access control.
    // The returned response allows the client to understand if the
    // operation was succeffully executed and if not, the response
    // reports the reason of the failure.
    rpc ProcessCommand(SignedCommand) returns (SignedCommandResponse) {}
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值