Hyperledger Fabric 2.0 Chaincode as an external service 图解

文章目录

  • Chaincode as an external service
  • 一图流讲解配置
  • 一图流讲解流程(体感)
  • 结果:
    • Ref:

Chaincode as an external service

Fabric v2.0支持在Fabric外部部署和执行链码,使用户能够独立于对等方管理链码运行时。这有助于在结构云部署(如Kubernetes)上部署链码。链码现在可以作为服务运行,其生命周期在Fabric之外进行管理,而不是在每个对等机上构建和启动链码。此功能利用Fabric v2.0外部构建器和启动程序功能,使操作员能够使用程序扩展对等机以构建、启动和发现链码。在阅读本主题之前,您应该熟悉外部生成器和启动程序内容。

一图流讲解配置

如图,蓝色的代表peer server,在server中配置的

externalBuilders:
- name: external-builder
path: /builders/external
environmentWhitelist:
- GOPROXY
是要对应真正的处理逻辑文件,build,detect脚本的。(这个要手写)
右侧是准备的chaincode服务器,地址要保存在connection.json中
里边ccid对应的是比如cli安装chaincode给出的id
lab也要对应给metadata.json
通过detect来做过滤,在detect脚本中如果exit code为0,则进入对应的external service的处理,执行build,release…
Hyperledger Fabric 2.0 Chaincode as an external service 图解_第1张图片

一图流讲解流程(体感)

当cli安装chaincode的tar包时,通过执行peer server上的脚本,将connection.json解析出来。
当需invoke的时候,会根据解析出来的connection.json去网络上的一个位置调用chaincode server(grpc).
Hyperledger Fabric 2.0 Chaincode as an external service 图解_第2张图片

结果:

bash-5.0# peer lifecycle chaincode install myccpkg.tgz
2020-06-10 06:25:26.881 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGmycc_1:c4240e0592ffc2a20e020fb20019671583124a603ac85158525bbf629a50d01b\022\006mycc_1" > 
2020-06-10 06:25:26.881 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc_1:c4240e0592ffc2a20e020fb20019671583124a603ac85158525bbf629a50d01b
bash-5.0# peer lifecycle chaincode checkcommitreadiness --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --output json --init-required
{
        "approvals": {
                "Org1MSP": true,
                "Org2MSP": false
        }
}
bash-5.0# peer lifecycle chaincode queryinstalled >&log.txt
bash-5.0#   PACKAGE_ID=`sed -n '/Package/{s/^Package ID: //; s/, Label:.*$//; p;}' log.txt`
bash-5.0# peer lifecycle chaincode approveformyorg --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${VERSION} --waitForEvent
2020-06-10 06:26:49.515 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2020-06-10 06:26:51.569 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [aac1f430b905fa2a8768151b9549f2f75432515acebb5ef5eddb4a987a99372d] committed with status (VALID) at 
bash-5.0# peer lifecycle chaincode checkcommitreadiness --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --output json --init-required
{
        "approvals": {
                "Org1MSP": true,
                "Org2MSP": true
        }
}
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer1.org2.example.com:10051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt --isInit -c '{"Args":["Init","a","100","b","100"]}'
2020-06-10 08:19:13.470 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 

在这里插入图片描述

Ref:

https://hyperledger-fabric.readthedocs.io/en/release-2.1/cc_service.html
https://blog.csdn.net/DAOSHUXINDAN/article/details/104814621

你可能感兴趣的:(Hyperledger,Fabric)