fabric2.0局域网多机版链码部署、调用、升级

fabric局域网多机链管理目录

  1. 《局域网环境、多机部署Fabric2.x版本(RAFT共识算法)+ 通道创建》

  2. 《fabric2.0局域网多机版链码部署、调用、升级》

  3. 《fabric2.0局域网多机版锚节点更新》

链码部署

fabric2.0后版本链码的部署操作比1.4步骤增加了不少。主要有:打包、安装、审批、提交、初始化等。

上传

  1. 上传链码文件至peer0主机(后续部署操作不做特殊说明均在次主机执行)的 /data/fabric/chaincode/目录
[root@localhost fabric]# tree chaincode/ -L 3
chaincode/
└── mycc
    ├── abstore.go
    ├── go.mod
    ├── go.sum
    └── vendor
        ├── github.com
        ├── golang.org
        ├── google.golang.org
        └── modules.txt

打包

  1. 打包(一个节点打包,然后复制打包文件到其他节点)
[root@localhost fabric]# docker exec cli peer lifecycle chaincode package ./channel-artifacts/mycc_01.tar.gz --path /opt/gopath/src/github.com/chaincode/mycc/ --label mycc_01 
2021-05-13 07:51:55.901 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 07:51:55.905 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable

  • 注:如果无法联网请先执行:docker exec cli go env -w GOFLAGS=" -mod=vendor"
  • 完成后复制链码文件mycc_01.tar.gz至通道内其他节点(peer1):scp ./channel-artifacts/mycc_01.tar.gz root@192.168.1.27:/data/fabric/channel-artifacts/

安装

  1. 安装 (每个节点分别安装)
[root@localhost fabric]# docker exec cli peer lifecycle chaincode install ./channel-artifacts/mycc_01.tar.gz
2021-05-13 08:06:00.009 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 08:06:00.013 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 08:06:44.723 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 003 Installed remotely: response:<status:200 payload:"\nHmycc_01:dce41aebe82a4dc8effabc38d74194008a86dcd1ce9b97212ea6ee5ef33128a2\022\007mycc_01" > 
2021-05-13 08:06:44.723 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 004 Chaincode code package identifier: mycc_01:dce41aebe82a4dc8effabc38d74194008a86dcd1ce9b97212ea6ee5ef33128a2

  • 查看已安装链码
 docker exec cli peer lifecycle chaincode queryinstalled | grep mycc_01
2021-05-13 08:08:46.977 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 08:08:46.981 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
Package ID: mycc_01:dce41aebe82a4dc8effabc38d74194008a86dcd1ce9b97212ea6ee5ef33128a2, Label: mycc_01

审批

  1. 审批(需要多组织审批)
[root@localhost fabric]# str=`docker exec cli peer lifecycle chaincode queryinstalled | grep mycc_01` && strA=${str#*ID: } && id=${strA%,*} && echo "当前packageID="$id && docker exec cli peer lifecycle chaincode approveformyorg  --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer.test.com/msp/tlscacerts/tlsca.test.com-cert.pem --channelID channel-2 --name mycc_01 --version 1 --init-required --sequence 1 --waitForEvent  --package-id $id --waitForEventTimeout 60s
2021-05-13 09:35:59.603 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:35:59.607 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
当前packageID=mycc_01:dce41aebe82a4dc8effabc38d74194008a86dcd1ce9b97212ea6ee5ef33128a2
2021-05-13 09:35:59.793 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:35:59.797 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:35:59.813 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 003 Retrieved channel (channel-2) orderer endpoint: orderer.test.com:7050
2021-05-13 09:36:00.834 UTC [chaincodeCmd] ClientWait -> INFO 004 txid [767b73c18771c6fb1a6b663ac3c612f80534cdb5b65c368d20cb2931c12d7427] committed with status (VALID) at 
  • 查看是否审批成功
[root@localhost fabric]# docker exec cli peer lifecycle chaincode queryapproved --channelID channel-2  --name mycc_01 --sequence 1 -O json
2021-05-13 09:40:00.198 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:40:00.202 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
{
        "sequence": 1,
        "version": "1",
        "endorsement_plugin": "escc",
        "validation_plugin": "vscc",
        "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
        "collections": {},
        "init_required": true,
        "source": {
                "Type": {
                        "LocalPackage": {
                                "package_id": "mycc_01:dce41aebe82a4dc8effabc38d74194008a86dcd1ce9b97212ea6ee5ef33128a2"
                        }
                }
        }
}

提交

  1. 提交
[root@localhost fabric]# docker exec cli peer lifecycle chaincode commit -o orderer.test.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/msp/tlscacerts/tlsca.test.com-cert.pem --channelID channel-2 --name mycc_01 --version 1 --sequence 1 --init-required   --peerAddresses peer0.org.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org.test.com/peers/peer0.org.test.com/tls/ca.crt   --peerAddresses peer1.org.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org.test.com/peers/peer0.org.test.com/tls/ca.crt
2021-05-13 09:44:49.214 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:44:49.218 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:44:50.409 UTC [chaincodeCmd] ClientWait -> INFO 003 txid [37d5f0349fdaf0fc11b3726d5992842e748c33c7d5a6c2976fe25aacc27399c8] committed with status (VALID) at peer1.org.test.com:7051
2021-05-13 09:44:50.427 UTC [chaincodeCmd] ClientWait -> INFO 004 txid [37d5f0349fdaf0fc11b3726d5992842e748c33c7d5a6c2976fe25aacc27399c8] committed with status (VALID) at peer0.org.test.com:7051

  • 提交后,正常情况下链码容器已经启动
[root@localhost fabric]# docker ps
CONTAINER ID        IMAGE                                                                                                                                                              COMMAND                  CREATED             STATUS              PORTS                              NAMES
3e966ef81b55        dev-peer0.org.test.com-mycc_01-dce41aebe82a4dc8effabc38d74194008a86dcd1ce9b97212ea6ee5ef33128a2-222bf3c60fae0846b9567d8be8398528d11d31bb24a9f10f3c322850154ba8d8   "chaincode -peer.add…"   28 seconds ago      Up 27 seconds                                          dev-peer0.org.test.com-mycc_01-dce41aebe82a4dc8effabc38d74194008a86dcd1ce9b97212ea6ee5ef33128a2

初始化

  1. 初始化 (“a”,“10000”,“b”,“300000”)
[root@localhost fabric]# docker exec cli peer chaincode invoke -o orderer.test.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/msp/tlscacerts/tlsca.test.com-cert.pem  -C channel-2 -n mycc_01 --peerAddresses peer0.org.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org.test.com/peers/peer0.org.test.com/tls/ca.crt --peerAddresses peer1.org.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org.test.com/peers/peer0.org.test.com/tls/ca.crt  --isInit -c '{"Args":["Init","a","10000","b","300000"]}'
2021-05-13 09:47:11.163 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:47:11.167 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:47:11.195 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 003 Chaincode invoke successful. result: status:200 

调用

  1. 调用(“a”,转账给 “b” 10 )
[root@localhost fabric]# docker exec cli peer chaincode invoke -o orderer.test.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/msp/tlscacerts/tlsca.test.com-cert.pem --channelID channel-2 -n mycc_01 --peerAddresses peer0.org.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org.test.com/peers/peer0.org.test.com/tls/ca.crt  --peerAddresses peer1.org.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org.test.com/peers/peer0.org.test.com/tls/ca.crt  -c  '{"Args":["invoke", "a", "b","10"]}'
2021-05-13 09:48:32.273 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:48:32.277 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:48:32.303 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 003 Chaincode invoke successful. result: status:200 

查询

  1. 查询
[root@localhost ~]# docker exec cli peer chaincode query -C channel-2 -n mycc_01 -c '{"Args":["query", "a"]}'
2021-05-13 09:50:41.220 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2021-05-13 09:50:41.225 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
9990

  • 结果符合预期、链码正常安装

升级

  1. 升级

    2.X链码升级步骤同初次部署类似。链码名称不变。–sequence +1 初始化操作根据实际情况进行初始化(理论上 提交成功后,升级已经成功了)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值