美文网首页Fabric
Hyperledger Fabric(四) 官方教程:添加一个O

Hyperledger Fabric(四) 官方教程:添加一个O

作者: yuyangray | 来源:发表于2018-03-24 18:52 被阅读162次

    前言

    官方英文:Adding an Org to a Channel

    由于水平有限,怕误人子弟,这里我不会翻译全部内容。如果希望看完整及原汁原味的文档,推荐看官方英文文档。

    本文基于Mac OS以及Hyperledger Fabric 1.1.0

    Adding an Org to a Channel

    这篇教程是对Hyperledger Fabric官方教程:构建第一个网络的延展,将会演示的是如何将一个新的组织Org3添加到Channel-mychannel中。

    Fabric在启动之前需要生成Orderer的创世区块和channel的配置区块。也就是说在Fabric网络启动之前我们就必须定好了有哪些Org,而当Fabric已经跑起来之后,想要增加Org却是很麻烦的事情。

    官方给出的解决方案是:使用configtxlator,可以将配置区块二进制转换为JSON,然后修改JSON,增加Org,再使用这个工具生成一个增量区块。最后再配合peer channel update命令,实现对原有配置的更新。

    如果之前的教程都能顺利运行,说明环境应该没问题,这里就不再啰嗦了。

    这里只是演示Channel更新配置的一种方式。如果想要更新修改政策或者变更batch大小,以及更多关于Channel的配置更新,可以查看这篇文章:Updating a Channel Configuration

    设置环境

    定位到fabric-samples/first-network文件夹,然后准备几个命令行窗口。

    首先,使用byfn.sh命令进行清理。这个命令会清理掉任何旧有的或当前活动的容器以及之前的配置。更新channel配置本身没有必要关闭Fabric网络,但看在这是教程的面子上,我们最好确保所有的状态都是初始的。因此我们执行以下命令进行清理:

    yuyangdeMacBook-Pro:first-network yuyang$ ./byfn.sh -m down
    

    然后生成配置文件:

    yuyangdeMacBook-Pro:first-network yuyang$ ./byfn.sh -m generate
    

    启动网络:

    yuyangdeMacBook-Pro:first-network yuyang$ ./byfn.sh -m up
    

    现在你已经在机器上运行了一个全新的BYFN版本。现在有两条路继续。首先,我们提供了一个全注释的脚本来执行配置交易,来将Org3更新到网络中。

    其次,我们提供了一个手动版本,展示了每一步的操作并且做出相应的解释。当然,你也可以执行脚本来查看每一步发生了什么。

    使用脚本将Org3加入到Channel

    在命令行输入以下指令:

    yuyangdeMacBook-Pro:first-network yuyang$ ./eyfn.sh up
    

    输出的内容非常值得阅读。你会看到Org3的证明才被添加,配置文件被生成和签署,然后链码被安装,允许Og3执行一些账本查询操作。

    全部内容:

    proceeding ...
    /Users/yuyang/fabric-sample/fabric-samples/first-network/../bin/cryptogen
    
    ###############################################################
    ##### Generate Org3 certificates using cryptogen tool #########
    ###############################################################
    + cryptogen generate --config=./org3-crypto.yaml
    org3.example.com
    + set +x
    
    /Users/yuyang/fabric-sample/fabric-samples/first-network/../bin/configtxgen
    ##########################################################
    #########  Generating Org3 config material ###############
    ##########################################################
    + configtxgen -printOrg Org3MSP
    2018-03-21 17:51:29.027 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
    2018-03-21 17:51:29.028 CST [msp] getMspConfig -> INFO 002 Loading NodeOUs
    + set +x
    
    
    ###############################################################
    ####### Generate and submit config tx to add Org3 #############
    ###############################################################
    
    ========= Creating config transaction to add org3 to network =========== 
    
    Installing jq
    Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
    Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
    Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [74.1 kB]
    Get:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [592 kB]
    Get:5 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
    Get:6 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [409 kB]
    Get:7 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3492 B]
    Get:8 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
    Get:9 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
    Get:10 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
    Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
    Get:12 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
    Get:13 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
    Get:14 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
    Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [246 kB]
    Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [960 kB]
    Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
    Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [774 kB]
    Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [18.5 kB]
    Get:20 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [5153 B]
    Get:21 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7696 B]
    Fetched 25.0 MB in 3min 22s (124 kB/s)
    Reading package lists...
    Reading package lists...
    Building dependency tree...
    Reading state information...
    The following additional packages will be installed:
      libonig2
    The following NEW packages will be installed:
      jq libonig2
    0 upgraded, 2 newly installed, 0 to remove and 44 not upgraded.
    Need to get 232 kB of archives.
    After this operation, 829 kB of additional disk space will be used.
    Get:1 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libonig2 amd64 5.9.6-1 [88.1 kB]
    Get:2 http://archive.ubuntu.com/ubuntu xenial/universe amd64 jq amd64 1.5+dfsg-1 [144 kB]
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (This frontend requires a controlling tty.)
    debconf: falling back to frontend: Teletype
    dpkg-preconfigure: unable to re-open stdin: 
    Fetched 232 kB in 5s (45.5 kB/s)
    Selecting previously unselected package libonig2:amd64.
    (Reading database ... 22650 files and directories currently installed.)
    Preparing to unpack .../libonig2_5.9.6-1_amd64.deb ...
    Unpacking libonig2:amd64 (5.9.6-1) ...
    Selecting previously unselected package jq.
    Preparing to unpack .../jq_1.5+dfsg-1_amd64.deb ...
    Unpacking jq (1.5+dfsg-1) ...
    Setting up libonig2:amd64 (5.9.6-1) ...
    Setting up jq (1.5+dfsg-1) ...
    Processing triggers for libc-bin (2.23-0ubuntu10) ...
    + peer channel fetch config config_block.pb -o orderer.example.com:7050 -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    Fetching the most recent configuration block for the channel
    2018-03-21 09:55:07.148 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    2018-03-21 09:55:07.153 UTC [main] main -> INFO 002 Exiting.....
    + set +x
    Decoding config block to JSON and isolating config to config.json
    + configtxlator proto_decode --input config_block.pb --type common.Block
    + jq '.data.data[0].payload.data.config'
    + set +x
    + jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json
    + set +x
    + configtxlator proto_encode --input config.json --type common.Config
    + configtxlator proto_encode --input modified_config.json --type common.Config
    + configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb
    + configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate
    + jq .
    ++ cat config_update.json
    + echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"mod_policy":' '"",' '"version":' '"1"' '},' '"Org2MSP":' '{' '"mod_policy":' '"",' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"version":' '"0"' '}' '},' '"values":' '{' '"Capabilities":' '{' '"mod_policy":' '"",' '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"version":' '"0"' '},' '"type":' 0, '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"mod_policy":' '"",' '"version":' '"1"' '},' '"Org2MSP":' '{' '"mod_policy":' '"",' '"version":' '"1"' '},' '"Org3MSP":' '{' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"Admins",' '"policy":' '{' '"type":' 1, '"value":' '{' '"identities":' '[' '{' '"principal":' '{' '"msp_identifier":' '"Org3MSP",' '"role":' '"ADMIN"' '},' '"principal_classification":' '"ROLE"' '}' '],' '"rule":' '{' '"n_out_of":' '{' '"n":' 1, '"rules":' '[' '{' '"signed_by":' 0 '}' ']' '}' '},' '"version":' 0 '}' '},' '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"Admins",' '"policy":' '{' '"type":' 1, '"value":' '{' '"identities":' '[' '{' '"principal":' '{' '"msp_identifier":' '"Org3MSP",' '"role":' '"MEMBER"' '},' '"principal_classification":' '"ROLE"' '}' '],' '"rule":' '{' '"n_out_of":' '{' '"n":' 1, '"rules":' '[' '{' '"signed_by":' 0 '}' ']' '}' '},' '"version":' 0 '}' '},' '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"Admins",' '"policy":' '{' '"type":' 1, '"value":' '{' '"identities":' '[' '{' '"principal":' '{' '"msp_identifier":' '"Org3MSP",' '"role":' '"MEMBER"' '},' '"principal_classification":' '"ROLE"' '}' '],' '"rule":' '{' '"n_out_of":' '{' '"n":' 1, '"rules":' '[' '{' '"signed_by":' 0 '}' ']' '}' '},' '"version":' 0 '}' '},' '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"config":' '{' '"FabricNodeOUs":' '{' '"Enable":' true, '"clientOUIdentifier":' '{' '"certificate":' '"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNRekNDQWVxZ0F3SUJBZ0lSQVBuY3dWcjUwb3BhRWIrckVKcWZmL013Q2dZSUtvWkl6ajBFQXdJd2N6RUwKTUFrR0ExVUVCaE1DVlZNeEV6QVJCZ05WQkFnVENrTmhiR2xtYjNKdWFXRXhGakFVQmdOVkJBY1REVk5oYmlCRwpjbUZ1WTJselkyOHhHVEFYQmdOVkJBb1RFRzl5WnpNdVpYaGhiWEJzWlM1amIyMHhIREFhQmdOVkJBTVRFMk5oCkxtOXlaek11WlhoaGJYQnNaUzVqYjIwd0hoY05NVGd3TXpJeE1EazBOakk0V2hjTk1qZ3dNekU0TURrME5qSTQKV2pCek1Rc3dDUVlEVlFRR0V3SlZVekVUTUJFR0ExVUVDQk1LUTJGc2FXWnZjbTVwWVRFV01CUUdBMVVFQnhNTgpVMkZ1SUVaeVlXNWphWE5qYnpFWk1CY0dBMVVFQ2hNUWIzSm5NeTVsZUdGdGNHeGxMbU52YlRFY01Cb0dBMVVFCkF4TVRZMkV1YjNKbk15NWxlR0Z0Y0d4bExtTnZiVEJaTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEEwSUEKQkwybjBjVzZIRE0yMU5FZDBYcVEra0ZuTWptWWdKUnE2a1RCWEhHbjhqYzI4aHlOYzJFUlBpVzFPOG1HbGNyMgp1ODBUa0lYQUxaUDhYdk9IcU1lZ1JVNmpYekJkTUE0R0ExVWREd0VCL3dRRUF3SUJwakFQQmdOVkhTVUVDREFHCkJnUlZIU1VBTUE4R0ExVWRFd0VCL3dRRk1BTUJBZjh3S1FZRFZSME9CQ0lFSUhoVVRiZHMyWHpkWThHNlJ0ejYKcjlJQ2pmaWFGM2JoWEJYeG9GOHRRM3VkTUFvR0NDcUdTTTQ5QkFNQ0EwY0FNRVFDSUVQVGd2aWV4ZDk2WlJtaQpRcEpKbHpHWURlVEVYZ3BJOW9kelJWTDZZRE5TQWlCRVFEK3JUZnM0TXh4RC81c2kvQXZkeHJTN1JiWHpoVC8xCnVmbGRJUTBqR0E9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==",' '"organizational_unit_identifier":' '"client"' '},' '"peerOUIdentifier":' '{' '"certificate":' '"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNRekNDQWVxZ0F3SUJBZ0lSQVBuY3dWcjUwb3BhRWIrckVKcWZmL013Q2dZSUtvWkl6ajBFQXdJd2N6RUwKTUFrR0ExVUVCaE1DVlZNeEV6QVJCZ05WQkFnVENrTmhiR2xtYjNKdWFXRXhGakFVQmdOVkJBY1REVk5oYmlCRwpjbUZ1WTJselkyOHhHVEFYQmdOVkJBb1RFRzl5WnpNdVpYaGhiWEJzWlM1amIyMHhIREFhQmdOVkJBTVRFMk5oCkxtOXlaek11WlhoaGJYQnNaUzVqYjIwd0hoY05NVGd3TXpJeE1EazBOakk0V2hjTk1qZ3dNekU0TURrME5qSTQKV2pCek1Rc3dDUVlEVlFRR0V3SlZVekVUTUJFR0ExVUVDQk1LUTJGc2FXWnZjbTVwWVRFV01CUUdBMVVFQnhNTgpVMkZ1SUVaeVlXNWphWE5qYnpFWk1CY0dBMVVFQ2hNUWIzSm5NeTVsZUdGdGNHeGxMbU52YlRFY01Cb0dBMVVFCkF4TVRZMkV1YjNKbk15NWxlR0Z0Y0d4bExtTnZiVEJaTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEEwSUEKQkwybjBjVzZIRE0yMU5FZDBYcVEra0ZuTWptWWdKUnE2a1RCWEhHbjhqYzI4aHlOYzJFUlBpVzFPOG1HbGNyMgp1ODBUa0lYQUxaUDhYdk9IcU1lZ1JVNmpYekJkTUE0R0ExVWREd0VCL3dRRUF3SUJwakFQQmdOVkhTVUVDREFHCkJnUlZIU1VBTUE4R0ExVWRFd0VCL3dRRk1BTUJBZjh3S1FZRFZSME9CQ0lFSUhoVVRiZHMyWHpkWThHNlJ0ejYKcjlJQ2pmaWFGM2JoWEJYeG9GOHRRM3VkTUFvR0NDcUdTTTQ5QkFNQ0EwY0FNRVFDSUVQVGd2aWV4ZDk2WlJtaQpRcEpKbHpHWURlVEVYZ3BJOW9kelJWTDZZRE5TQWlCRVFEK3JUZnM0TXh4RC81c2kvQXZkeHJTN1JiWHpoVC8xCnVmbGRJUTBqR0E9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==",' '"organizational_unit_identifier":' '"peer"' '}' '},' '"admins":' '[' '"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNLVENDQWRDZ0F3SUJBZ0lRZm85M0s1UGFLSmFVRVpNNEVSSk9qVEFLQmdncWhrak9QUVFEQWpCek1Rc3cKQ1FZRFZRUUdFd0pWVXpFVE1CRUdBMVVFQ0JNS1EyRnNhV1p2Y201cFlURVdNQlFHQTFVRUJ4TU5VMkZ1SUVaeQpZVzVqYVhOamJ6RVpNQmNHQTFVRUNoTVFiM0puTXk1bGVHRnRjR3hsTG1OdmJURWNNQm9HQTFVRUF4TVRZMkV1CmIzSm5NeTVsZUdGdGNHeGxMbU52YlRBZUZ3MHhPREF6TWpFd09UUTJNamhhRncweU9EQXpNVGd3T1RRMk1qaGEKTUd3eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZBWURWUVFIRXcxVApZVzRnUm5KaGJtTnBjMk52TVE4d0RRWURWUVFMRXdaamJHbGxiblF4SHpBZEJnTlZCQU1NRmtGa2JXbHVRRzl5Clp6TXVaWGhoYlhCc1pTNWpiMjB3V1RBVEJnY3Foa2pPUFFJQkJnZ3Foa2pPUFFNQkJ3TkNBQVJud2sxbE1SMWMKNjNCNUIrWEZHcjJVMjVxREYrUmJ0b2dFUHFvWThwN1J3ZW1SVjBSaENLSXJObEFhOEhiYkFJekNwdVVRdktMQQpYU2xvUjgwUWx4ajVvMDB3U3pBT0JnTlZIUThCQWY4RUJBTUNCNEF3REFZRFZSMFRBUUgvQkFJd0FEQXJCZ05WCkhTTUVKREFpZ0NCNFZFMjNiTmw4M1dQQnVrYmMrcS9TQW8zNG1oZDI0VndWOGFCZkxVTjduVEFLQmdncWhrak8KUFFRREFnTkhBREJFQWlBQW44ZzVyRjZDcHhHM1kyOGxuSzRMdWxwL24wSk1WdHVobUdMQjRlNUhuZ0lnVk1LQgpIeEEwQS9CeTljb1QxcGhMdEZNWUpwK1JWMXlGQXhSL00xS3QvWFk9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K"' '],' '"crypto_config":' '{' '"identity_identifier_hash_function":' '"SHA256",' '"signature_hash_family":' '"SHA2"' '},' '"name":' '"Org3MSP",' '"root_certs":' '[' '"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNRekNDQWVxZ0F3SUJBZ0lSQVBuY3dWcjUwb3BhRWIrckVKcWZmL013Q2dZSUtvWkl6ajBFQXdJd2N6RUwKTUFrR0ExVUVCaE1DVlZNeEV6QVJCZ05WQkFnVENrTmhiR2xtYjNKdWFXRXhGakFVQmdOVkJBY1REVk5oYmlCRwpjbUZ1WTJselkyOHhHVEFYQmdOVkJBb1RFRzl5WnpNdVpYaGhiWEJzWlM1amIyMHhIREFhQmdOVkJBTVRFMk5oCkxtOXlaek11WlhoaGJYQnNaUzVqYjIwd0hoY05NVGd3TXpJeE1EazBOakk0V2hjTk1qZ3dNekU0TURrME5qSTQKV2pCek1Rc3dDUVlEVlFRR0V3SlZVekVUTUJFR0ExVUVDQk1LUTJGc2FXWnZjbTVwWVRFV01CUUdBMVVFQnhNTgpVMkZ1SUVaeVlXNWphWE5qYnpFWk1CY0dBMVVFQ2hNUWIzSm5NeTVsZUdGdGNHeGxMbU52YlRFY01Cb0dBMVVFCkF4TVRZMkV1YjNKbk15NWxlR0Z0Y0d4bExtTnZiVEJaTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEEwSUEKQkwybjBjVzZIRE0yMU5FZDBYcVEra0ZuTWptWWdKUnE2a1RCWEhHbjhqYzI4aHlOYzJFUlBpVzFPOG1HbGNyMgp1ODBUa0lYQUxaUDhYdk9IcU1lZ1JVNmpYekJkTUE0R0ExVWREd0VCL3dRRUF3SUJwakFQQmdOVkhTVUVDREFHCkJnUlZIU1VBTUE4R0ExVWRFd0VCL3dRRk1BTUJBZjh3S1FZRFZSME9CQ0lFSUhoVVRiZHMyWHpkWThHNlJ0ejYKcjlJQ2pmaWFGM2JoWEJYeG9GOHRRM3VkTUFvR0NDcUdTTTQ5QkFNQ0EwY0FNRVFDSUVQVGd2aWV4ZDk2WlJtaQpRcEpKbHpHWURlVEVYZ3BJOW9kelJWTDZZRE5TQWlCRVFEK3JUZnM0TXh4RC81c2kvQXZkeHJTN1JiWHpoVC8xCnVmbGRJUTBqR0E9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg=="' '],' '"tls_root_certs":' '[' '"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNTVENDQWUrZ0F3SUJBZ0lRSm5MUXZEK1dKaHlvcUllaVltRU5hVEFLQmdncWhrak9QUVFEQWpCMk1Rc3cKQ1FZRFZRUUdFd0pWVXpFVE1CRUdBMVVFQ0JNS1EyRnNhV1p2Y201cFlURVdNQlFHQTFVRUJ4TU5VMkZ1SUVaeQpZVzVqYVhOamJ6RVpNQmNHQTFVRUNoTVFiM0puTXk1bGVHRnRjR3hsTG1OdmJURWZNQjBHQTFVRUF4TVdkR3h6ClkyRXViM0puTXk1bGVHRnRjR3hsTG1OdmJUQWVGdzB4T0RBek1qRXdPVFEyTWpoYUZ3MHlPREF6TVRnd09UUTIKTWpoYU1IWXhDekFKQmdOVkJBWVRBbFZUTVJNd0VRWURWUVFJRXdwRFlXeHBabTl5Ym1saE1SWXdGQVlEVlFRSApFdzFUWVc0Z1JuSmhibU5wYzJOdk1Sa3dGd1lEVlFRS0V4QnZjbWN6TG1WNFlXMXdiR1V1WTI5dE1SOHdIUVlEClZRUURFeFowYkhOallTNXZjbWN6TG1WNFlXMXdiR1V1WTI5dE1Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMEQKQVFjRFFnQUViMzVpZ3haVmZXU3greEEyQzg4a1ltMEJJOHlVK1E2NWp6bjEwaFlONXh0MVRkbXpmUS9TejFOUQo4WTkrOHZ6SWRmbGtRQlVsMHd2TGxtVWxCSC8yUGFOZk1GMHdEZ1lEVlIwUEFRSC9CQVFEQWdHbU1BOEdBMVVkCkpRUUlNQVlHQkZVZEpRQXdEd1lEVlIwVEFRSC9CQVV3QXdFQi96QXBCZ05WSFE0RUlnUWd4OW8xWHVHNVdCNDgKckpxYUZIWkttZk9MMERlcXh3QkpIQzJ3TWFCaXR3Z3dDZ1lJS29aSXpqMEVBd0lEU0FBd1JRSWhBSlZDVTh6Sgo4ZE1ab1I4a2M3eTBqY0ZySFVZaWxXSVhRbjN1WjM3MFMxQUhBaUFJMG9naWh4aU5ha1h2QXJ5bmQxZ2VhQk5LCmdoN05GQ3NPQk5sN2F0Zk80dz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K"' ']' '},' '"type":' 0 '},' '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"version":' '"0"' '}' '},' '"values":' '{' '"Capabilities":' '{' '"mod_policy":' '"",' '"version":' '"0"' '}' '},' '"version":' '"2"' '}' '},' '"mod_policy":' '"",' '"version":' '"0"' '}' '}}}}'
    + configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope
    + set +x
    
    ========= Config transaction to add org3 to network created ===== 
    
    Signing config transaction
    
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    + peer channel signconfigtx -f org3_update_in_envelope.pb
    2018-03-21 09:55:07.598 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    2018-03-21 09:55:07.599 UTC [main] main -> INFO 002 Exiting.....
    + set +x
    
    ========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= 
    
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org2MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    + peer channel update -f org3_update_in_envelope.pb -c mychannel -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    2018-03-21 09:55:07.697 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    2018-03-21 09:55:07.712 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
    2018-03-21 09:55:07.712 UTC [main] main -> INFO 003 Exiting.....
    + set +x
    
    ========= Config transaction to add org3 to network submitted! =========== 
    
    Creating volume "net_peer0.org3.example.com" with default driver
    Creating volume "net_peer1.org3.example.com" with default driver
    WARNING: Found orphan containers (cli, orderer.example.com, peer1.org2.example.com, peer1.org1.example.com, peer0.org1.example.com, peer0.org2.example.com) for this project. If you removed or renamed this service in your compose file, you cCreating peer0.org3.example.com ... done
    Creating Org3cli ... done
    Creating peer1.org3.example.com ... 
    Creating Org3cli ... 
    
    ###############################################################
    ############### Have Org3 peers join network ##################
    ###############################################################
    
    ========= Getting Org3 on to your first network ========= 
    
    Fetching channel config block from orderer...
    + peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    + set +x
    2018-03-21 09:55:10.117 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    2018-03-21 09:55:10.123 UTC [main] main -> INFO 002 Exiting.....
    ===================== Having peer0.org3 join the channel ===================== 
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org3MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
    CORE_PEER_ID=Org3cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org3.example.com:7051
    + peer channel join -b mychannel.block
    + set +x
    2018-03-21 09:55:10.244 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    2018-03-21 09:55:10.281 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
    2018-03-21 09:55:10.282 UTC [main] main -> INFO 003 Exiting.....
    ===================== peer0.org3 joined the channel "mychannel" ===================== 
    ===================== Having peer1.org3 join the channel ===================== 
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org3MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
    CORE_PEER_ID=Org3cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer1.org3.example.com:7051
    + peer channel join -b mychannel.block
    + set +x
    2018-03-21 09:55:10.377 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    2018-03-21 09:55:10.416 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
    2018-03-21 09:55:10.416 UTC [main] main -> INFO 003 Exiting.....
    ===================== peer1.org3 joined the channel "mychannel" ===================== 
    Installing chaincode 2.0 on peer0.org3...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org3MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
    CORE_PEER_ID=Org3cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org3.example.com:7051
    + peer chaincode install -n mycc -v 2.0 -l golang -p github.com/chaincode/chaincode_example02/go/
    + set +x
    2018-03-21 09:55:10.517 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:10.517 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    2018-03-21 09:55:10.691 UTC [main] main -> INFO 003 Exiting.....
    ===================== Chaincode is installed on peer0.org3 ===================== 
    
    
    ========= Got Org3 halfway onto your first network ========= 
    
    
    ###############################################################
    ##### Upgrade chaincode to have Org3 peers on the network #####
    ###############################################################
    
    ========= Finish adding Org3 to your first network ========= 
    
    ===================== Installing chaincode 2.0 on peer0.org1 ===================== 
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    + peer chaincode install -n mycc -v 2.0 -l golang -p github.com/chaincode/chaincode_example02/go/
    + set +x
    2018-03-21 09:55:10.881 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:10.882 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    2018-03-21 09:55:11.055 UTC [main] main -> INFO 003 Exiting.....
    ===================== Chaincode is installed on peer0.org1 ===================== 
    
    ===================== Installing chaincode 2.0 on peer0.org2 ===================== 
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org2MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    + peer chaincode install -n mycc -v 2.0 -l golang -p github.com/chaincode/chaincode_example02/go/
    + set +x
    2018-03-21 09:55:11.132 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:11.132 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    2018-03-21 09:55:11.313 UTC [main] main -> INFO 003 Exiting.....
    ===================== Chaincode is installed on peer0.org2 ===================== 
    
    ===================== Upgrading chaincode on peer0.org1 ===================== 
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    + peer chaincode upgrade -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 -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P 'OR ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'','\''Org3MSP.peer'\'')'
    2018-03-21 09:55:11.417 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:11.417 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    2018-03-21 09:55:22.592 UTC [main] main -> INFO 003 Exiting.....
    + set +x
    2018-03-21 09:55:11.132 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:11.132 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    2018-03-21 09:55:11.313 UTC [main] main -> INFO 003 Exiting.....
    ===================== Chaincode is upgraded on org1 peer0 ===================== 
    
    
    ========= Finished adding Org3 to your first network! ========= 
    
    
     ____    _____      _      ____    _____ 
    / ___|  |_   _|    / \    |  _ \  |_   _|
    \___ \    | |     / _ \   | |_) |   | |  
     ___) |   | |    / ___ \  |  _ <    | |  
    |____/    |_|   /_/   \_\ |_| \_\   |_|  
    
    Extend your first network (EYFN) test
    
    Channel name : mychannel
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org3MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
    CORE_PEER_ID=Org3cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org3.example.com:7051
    ===================== Querying on peer0.org3 on channel 'mychannel'... ===================== 
    Attempting to Query peer0.org3 ...3 secs
    + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    + set +x
    
    2018-03-21 09:55:25.806 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:25.806 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    Query Result: 90
    2018-03-21 09:55:36.978 UTC [main] main -> INFO 003 Exiting.....
    ===================== Query on peer0.org3 on channel 'mychannel' is successful ===================== 
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org3MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
    CORE_PEER_ID=Org3cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org3.example.com:7051
    + 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 -c '{"Args":["invoke","a","b","10"]}'
    + set +x
    2018-03-21 09:55:37.074 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:37.074 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    2018-03-21 09:55:37.083 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 003 Chaincode invoke successful. result: status:200 
    2018-03-21 09:55:37.083 UTC [main] main -> INFO 004 Exiting.....
    ===================== Invoke transaction on peer0.org3 on channel 'mychannel' is successful ===================== 
    
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org3MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
    CORE_PEER_ID=Org3cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org3.example.com:7051
    ===================== Querying on peer0.org3 on channel 'mychannel'... ===================== 
    Attempting to Query peer0.org3 ...3 secs
    + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    + set +x
    
    2018-03-21 09:55:40.185 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2018-03-21 09:55:40.185 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    Query Result: 80
    2018-03-21 09:55:40.189 UTC [main] main -> INFO 003 Exiting.....
    ===================== Query on peer0.org3 on channel 'mychannel' is successful ===================== 
    
    ========= All GOOD, EYFN test execution completed =========== 
    
    
     _____   _   _   ____   
    | ____| | \ | | |  _ \  
    |  _|   |  \| | | | | | 
    | |___  | |\  | | |_| | 
    |_____| |_| \_| |____/  
    

    如果顺利执行,最后你会看到以下内容:

    ========= All GOOD, EYFN test execution completed ===========
    

    你可以使用eyfn.sh来执行使用Node.js编写的链码及数据库(通过替换./byfn.sh -m -up):

    启动网络:

    ./byfn.sh up -c testchannel -s couchdb -l node
    

    执行脚本:

    ./eyfn.sh up -c testchannel -s couchdb -l node
    

    手动将Org3加入到Channel

    首先需要将cliOrg3cli容器的日志等级设为DEBUG

    first-network文件夹内找到docker-compose-cli.yamldocker-compose-org3.yaml进行修改。

    cli:
      container_name: cli
      image: hyperledger/fabric-tools:$IMAGE_TAG
      tty: true
      stdin_open: true
      environment:
        - GOPATH=/opt/gopath
        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
        #- CORE_LOGGING_LEVEL=INFO
        - CORE_LOGGING_LEVEL=DEBUG
    
    Org3cli:
      container_name: Org3cli
      image: hyperledger/fabric-tools:$IMAGE_TAG
      tty: true
      stdin_open: true
      environment:
        - GOPATH=/opt/gopath
        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
        #- CORE_LOGGING_LEVEL=INFO
        - CORE_LOGGING_LEVEL=DEBUG
    

    如果你使用过了eyfn.sh脚本,使用以下命令停止网络:

    yuyangdeMacBook-Pro:first-network yuyang$ ./eyfn.sh down
    

    这将会停止网络,删除所有容器,恢复成还未添加Org3的状态。

    当网络停止后,重新生成配置文件:

    yuyangdeMacBook-Pro:first-network yuyang$ ./byfn.sh -m generate
    

    开启网络:

    yuyangdeMacBook-Pro:first-network yuyang$ ./byfn.sh -m up
    

    这会将你的网络恢复成执行eyfn.sh之前的状态。

    现在我们准备好手动添加Org3了。第一步,我们需要生成Org3的证书材料。

    生成Org3的证书材料

    新开命令窗口,进入first-network下的org3-artifacts文件夹:

    cd org3-artifacts
    

    这里有两个文件,org3-crypto.yamlconfigtx.yaml。首先,为Org3生成证书材料:

    yuyangdeMacBook-Pro:org3-artifacts yuyang$ ../../bin/cryptogen generate --config=./org3-crypto.yaml
    

    这个命令会读取org3-crypto.yaml文件,然后利用cryptogen工具,为新的Org3以及绑定在其上的两个节点,生成密钥和证书,并将其放入当前路径新生成的crypto-config文件夹中。

    现在使用configtxgen工具打印出Org3的配置材料,以JSON为格式。我们会告诉工具使用当前路径的configtx.yaml文件:

    yuyangdeMacBook-Pro:org3-artifacts yuyang$ export FABRIC_CFG_PATH=$PWD && ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json
    

    上面的指令在first-network/channel-artifacts文件夹中生成了名为org3.json的JSON文件。这个文件定义了对Org3的许可,以及三个重要的证书:管理员用户证书(稍后Org3的管理员会需要),CA根证书,TSL根证书。后面我们会将此JSON文件加入到channel的配置中。

    这里的最后一步,我们需要将OrdererOrg’s MSP材料指向Org3的crypto-config路径。我们特别关心Orderer的TLS 根证书,它允许Org3实体与网络的ordering node保持安全的连接。

    yuyangdeMacBook-Pro:org3-artifacts yuyang$ cd ../ && cp -r crypto-config/ordererOrganizations org3-artifacts/crypto-config/
    

    现在我们已经准备好更新channel的配置了... ...

    准备CLI环境(Prepare the CLI Environment)

    configtxlator 工具提供了一个与 SDK 独立的真正无状态的 REST API,以简化 Hyperledger Fabric 区块链网络中的配置任务。该工具能够在不同的等效数据表示/格式之间轻松转换。例如,在工具操作的一种模式中,该工具在二进制 protobuf 格式与人类可读的 JSON 文本格式间来回转换。此外,该工具可以基于两组不同的配置交易之间的区别来计算配置更新。

    首先进入CLI容器,启动后我们使用的是Org1的管理员身份。

    yuyangdeMacBook-Pro:first-network yuyang$ docker exec -it cli bash
    

    现在安装jq工具到容器。:

    root@e17553e53d38:/opt/gopath/src/github.com/hyperledger/fabric/peer# apt update && apt install -y jq
    

    定义ORDERER_CACHANNEL_NAME的环境变量:

    root@e17553e53d38:/opt/gopath/src/github.com/hyperledger/fabric/peer# export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem  && export CHANNEL_NAME=mychannel
    

    检查以确保环境变量设置成功:

    root@e17553e53d38:/opt/gopath/src/github.com/hyperledger/fabric/peer# echo $ORDERER_CA && echo $CHANNEL_NAME
    

    如果你重启了CLI容器,你需要重新设置ORDERER_CACHANNEL_NAME的环境变量。jq会存留,所以不需要重新安装。注:经测试,关机后需要重新安装。

    获取配置(Fetch the Configuration)

    现在我们有了CLI容器,并且已经设置好两个环境变量。现在需要找到channel – mychannel最近的配置区块。

    以下是为何需要获取最近channel配置的原因:安全原因和并发性。

    The reason why we have to pull the latest version of the config is because channel config elements are versioned.. Versioning is important for several reasons. It prevents config changes from being repeated or replayed (for instance, reverting to a channel config with old CRLs would represent a security risk). Also it helps ensure concurrency (if you want to remove an Org from your channel, for example, after a new Org has been added, versioning will help prevent you from removing both Orgs, instead of just the Org you want to remove).

    root@7b962ac2d903:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
    

    这条命令会将channel的配置区块的二进制文件保存在config_block.pb中。注意,名称和后缀名都是任意的。但是最好使用约定俗成的方式。

    当你执行peer channel fetch命令,终端上会显示很多输出内容。最后一条很有趣:

    2018-03-22 03:46:34.631 UTC [channelCmd] readBlock -> DEBU 011 Received block: 2
    

    这告诉我们mychannel最近的配置区块其实是block2,而不是创世区块genesis block。默认的。peer channel fetch config命令会返回指定channel最近的配置区块,在本案例中是第三个区块。这是因为BYFN脚本为我们的两个组织Org1Org2指定了锚节点,是两个分离的channel更新交易。

    所以说,我们的配置序列是下面这样的:

    • block 0: genesis block.创世区块。

    • block 1: Org1 anchor peer update.Org1的锚点更新。

    • block 2: Org2 anchor peer update.Org2的锚点更新。

    转换配置文件为JSON格式文件并进行修剪(Convert the Configuration to JSON and Trim It Down)

    现在我们将使用configtxlator工具将channel的配置区块解码为JSON文件(以便人们阅读和修改)。我们还必须去掉headers, metadata, creator signatures这些不相关的内容。我们使用jq工具来实现这一目的:

    root@7b962ac2d903:/opt/gopath/src/github.com/hyperledger/fabric/peer# configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json
    

    现在我们有了一个修剪过的JSON文件-config.json,它位于first-network文件夹中。这是我们更新配置的基础。

    花些时间阅读它。即使完成了此篇教程,对于理解配置原理及channel的其他更新,都很有用。我们将在Updating a Channel Configuration中讨论更多细节。

    注意:我这里其实并没有在first-network文件夹中发现config_block.pb或者config.json文件。而在命令行中查看,发现这两个文件和其他几个文件一起,都位于当前peer的CLI容器中。

    root@7b962ac2d903:/opt/gopath/src/github.com/hyperledger/fabric/peer# ls
    channel-artifacts  config_block.pb  log.txt          scripts
    config.json        crypto           mychannel.block
    

    我暂时没找到如何查看此文件的方法。有知道的朋友请告知一声,感谢!

    添加Org3证书材料

    来到了这个节点,也意味着我们很接近一个事实:我们可以进行各种配置更新,它们都大同小异。在这个教程里,我们选择添加一个新组织的原因是,这可能是你所能做的最复杂的channel配置更新之一。

    我们再一次使用jq工具,将定义的Org3配置文件org3.json,添加至channel的应用群组域,起名为modified_config.json

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json > modified_config.json
    

    现在,在我们的CLI容器中已经有两个JSON文件config.jsonmodified_config.json了。初始的文件中只包含了Org1和Org2材料,而新的文件包含了全部三个Org的材料。接着我们将这两个JSON文件转换为pb文件。

    首先,将config.json转换为pb文件config.pb

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# configtxlator proto_encode --input config.json --type common.Config --output config.pb
    

    接着,将modified_config.json转换为pb文件modified_config.pb

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb
    

    现在我们使用configtxlator工具来计算这两个pb文件的差值。下面这条指令会生成一个新的pb文件org3_update.pb

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output org3_update.pb
    

    由于Org1和Org2的证书材料已经在channel的创世区块中生成了,而Org3的证书材料org3_update.pb也指向了它们,所以我们只需要算出这两个配置的区间值。

    在我们提交channel更新前,还有最后几个步骤。首先将org3_update.pb转换为JSON文件,起名为org3_update.json

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# configtxlator proto_decode --input org3_update.pb --type common.ConfigUpdate | jq . > org3_update.json
    

    现在我们已经有了一个编好码的更新文件org3_update.json,我们需要把它包裹在“信封”中。这一步会将我们之前去掉的header域重新加上。将这个文件起名为org3_update_in_envelope.json

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json
    

    我们将最后一次利用configtxlator工具,将JSON文件org3_update_in_envelope.json转换为Fabric要求的,完整的pb格式文件。我们将文件起名为org3_update_in_envelope.pb

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# configtxlator proto_encode --input org3_update_in_envelope.json --type common.Envelope --output org3_update_in_envelope.pb
    

    签名并且提交配置更新

    就快完成了!

    现在在我们的CLI容器中,已经有了一个pb文件org3_update_in_envelope.pb。然而,在我们将配置提交到账本之前,我们必须需要管理员的签署。我们的channel应用群组的修改机制默认需要大多数-MAJORITY,这意味着我们需要大多数已存在的Org管理员来进行签署。由于我们现在只有两个Org,Org1和Org2,两个的大多数指的就是两个,所以我们需要它们都来进行签署。没有它们两个的签署,ordering service 会拒绝执行这次交易。

    首先,我们以Org1的管理员身份对本次更新进行签署。还记得CLI容器是以Org1的MSP材料进行启动的吗?所以我们只需要简单的执行peer channel signconfigtx命令:

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel signconfigtx -f org3_update_in_envelope.pb
    

    输出内容:

    2018-03-23 04:45:32.371 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-23 04:45:32.371 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-23 04:45:32.371 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    2018-03-23 04:45:32.371 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
    2018-03-23 04:45:32.371 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
    2018-03-23 04:45:32.371 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP
    2018-03-23 04:45:32.371 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity
    2018-03-23 04:45:32.372 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0AB6060A074F7267314D535012AA062D...72697465727312002A0641646D696E73 
    2018-03-23 04:45:32.372 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: F5B563E7169C3655196D5F37671F8062FC1817807A465FFDF94C8CDF8A0B2741 
    2018-03-23 04:45:32.372 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP
    2018-03-23 04:45:32.372 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity
    2018-03-23 04:45:32.373 UTC [msp] GetLocalMSP -> DEBU 00c Returning existing local MSP
    2018-03-23 04:45:32.373 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity
    2018-03-23 04:45:32.373 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AED060A1508021A0608EC8CD2D50522...136E48E752E94DFF68E4FDBF9594046B 
    2018-03-23 04:45:32.373 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: DAC824DC04FB8E16BB0CF13AD92E4C270E5DE4F1378CD8E67FCA05FFA84A5F03 
    2018-03-23 04:45:32.373 UTC [main] main -> INFO 010 Exiting.....
    

    然后将CLI容器的身份切换为Org2的管理员身份。我们需要设置环境变量来指定Org2的MSP材料。

    现实世界里,在Fabric系统中进行不同组织间切换并签署配置更新(或者做其他任何事),是不真实的。一个单独的容器不可能安装整个网络的证明材料。当然,一个配置更新提案需要安全通过,必须由外部的Org2进行检查和同意。

    这里我的理解是,在这个教程中,因为Org1和Org2的所有节点都在本机的同一端口上。所以Org1的节点执行了某些操作,Org2的节点也同样执行了这些操作。所以当切换到Org2的节点上时,可以看见节点中野包含了所有上面生成的文件。而在真实情况中,Org2的节点肯定在不同地址的不同端口,所以没有切换组织一说。Org2想要签署,必须由Org2的节点执行签署操作

    设置Org2的环境变量,切换到peer0.org2:

    # you can issue all of these commands at once
    # 你可以一次性执行以下所有指令
    
    export CORE_PEER_LOCALMSPID="Org2MSP"
    
    export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    
    export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    
    export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    

    最后,我们执行peer channel update指令。前面说了,在这个教程中,Org1签署也意味着Org2也签署了,所以这里不需要Org2再进行签署。

    在更新指令发出后,ordering service会进行一系列的系统签署和证书检查。你可以在ordering node的日志中查看和检查很多有用的信息。新开一个命令窗口,执行docker logs -f orderer.example.com命令来查看。

    执行更新指令:

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel update -f org3_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA
    

    输出内容:

    2018-03-23 05:18:02.670 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-23 05:18:02.671 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-23 05:18:02.678 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    2018-03-23 05:18:02.679 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
    2018-03-23 05:18:02.679 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
    2018-03-23 05:18:02.679 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP
    2018-03-23 05:18:02.680 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity
    2018-03-23 05:18:02.680 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0AB6060A074F7267324D535012AA062D...72697465727312002A0641646D696E73 
    2018-03-23 05:18:02.680 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 175B2A235EFA28604E674101D2A1850ACEC67983FE947903383A320434E9123B 
    2018-03-23 05:18:02.680 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP
    2018-03-23 05:18:02.680 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity
    2018-03-23 05:18:02.682 UTC [msp] GetLocalMSP -> DEBU 00c Returning existing local MSP
    2018-03-23 05:18:02.682 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity
    2018-03-23 05:18:02.682 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AED060A1508021A06088A9CD2D50522...F77B180AC2226E3885B633CF782CE880 
    2018-03-23 05:18:02.682 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: 34F9CD91E72250DF8119ADF07D040A805831EAB62B77302307B4FDAC319592A3 
    2018-03-23 05:18:02.707 UTC [channelCmd] update -> INFO 010 Successfully submitted channel update
    2018-03-23 05:18:02.707 UTC [main] main -> INFO 011 Exiting.....
    

    如果成功的话,其中包含了以下数字摘要信息:

    2018-03-23 05:18:02.682 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: 34F9CD91E72250DF8119ADF07D040A805831EAB62B77302307B4FDAC319592A3 
    

    以及更新交易的提交信息:

    2018-03-23 05:18:02.707 UTC [channelCmd] update -> INFO 010 Successfully submitted channel update
    

    channel的更新指令提交成功后,会返回一个新的区块-block 5(注:我这里并没有返回)。如果你没忘记的话,channel初始化的时候产生了block0-2,链码初始化和调用时产生了block3-4。channel最近一次的配置更新产生了block5,同时Org3也被定义在了channel上。

    检查peer0.org1.example.com的日志:

    docker logs -f peer0.org1.example.com
    

    可以看到block5,也就是第6个区块产生了:

    2018-03-23 05:18:02.837 UTC [kvledger] CommitWithPvtData -> INFO 03e Channel [mychannel]: Committed block [5] with 1 transaction(s)
    

    这里根据我的理解,稍微说明下为何产生了6个区块:

    • 前三个区块就不详细说了,前面已经解释过了。

      block 0: genesis block.创世区块。

      block 1: Org1 anchor peer update.Org1的锚点更新产生区块。

      block 2: Org2 anchor peer update.Org2的锚点更新产生区块。

    • 之前执行了./byfn.sh -m up脚本,我们来看看日志中的关键内容:

      # 在`peer0.org1`上安装链码
      Chaincode is installed on peer0.org1
      
      # 在`peer0.org2`上安装链码
      Chaincode is installed on peer0.org2
      
      # 在`peer0.org2`上实例化链码,block3产生
      Chaincode Instantiation on peer0.org2
      
      # 在`peer0.org1`上进行查询
      Query on peer0.org1 on channel 'mychannel' is successful
      
       # 在`peer0.org1`上进行交易,block4产生
      Invoke transaction on peer0.org1 on channel 'mychannel' is successful
      
      # 在`peer1.org2`上安装链码
      Chaincode is installed on peer1.org2
      
      # 在`peer1.org2`上进行查询
      Query on peer1.org2 on channel 'mychannel' is successful
      

      可以看到,block3产生是由于实例化了链码,block4产生是由于进行了交易。此后的block5也是一次交易,只不过是channel的配置更新。

    再来看看当前的容器有哪些:

    yuyangdeMacBook-Pro:~ yuyang$ docker ps
    CONTAINER ID        IMAGE                                                                                                  COMMAND                  CREATED             STATUS              PORTS                                              NAMES
    4679137dd7a3        dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab   "chaincode -peer.add…"   6 minutes ago       Up 6 minutes                                                           dev-peer1.org2.example.com-mycc-1.0
    203c8ab18c36        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9   "chaincode -peer.add…"   7 minutes ago       Up 7 minutes                                                           dev-peer0.org1.example.com-mycc-1.0
    c10f7d92412d        dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b   "chaincode -peer.add…"   7 minutes ago       Up 7 minutes                                                           dev-peer0.org2.example.com-mycc-1.0
    389b71000f2d        hyperledger/fabric-tools:latest                                                                        "/bin/bash"              7 minutes ago       Up 7 minutes                                                           cli
    359aac8afa52        hyperledger/fabric-peer:latest                                                                         "peer node start"        8 minutes ago       Up 7 minutes        0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.example.com
    384460892ec9        hyperledger/fabric-peer:latest                                                                         "peer node start"        8 minutes ago       Up 7 minutes        0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.example.com
    278775f100aa        hyperledger/fabric-peer:latest                                                                         "peer node start"        8 minutes ago       Up 7 minutes        0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
    da3b1d2acebf        hyperledger/fabric-orderer:latest                                                                      "orderer"                8 minutes ago       Up 7 minutes        0.0.0.0:7050->7050/tcp                             orderer.example.com
    26ff1144dc5a        hyperledger/fabric-peer:latest                                                                         "peer node start"        8 minutes ago       Up 7 minutes        0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp     peer0.org2.example.com
    

    可以看到,除了1Orderer+4Peer+1CLI这六个容器,还有三个之前安装了链码的节点。

    下面教程继续,你可以获取并解码新的配置区块来检查其中的内容。

    配置Leader的选举

    这部分内容主要包括,当channel初始化完成后新增组织,如何设置leader选举的一个基本理解。本例默认是动态的leader选举,所有的节点都是在peer-base.yaml文件中设置的。

    创世区块启动了最近加入的节点,但是不包括那些在channel配置更新时加入的组织。这些新加入的节点,无法收到属于其他组织节点转发的区块进行验证,直到它们得到其所属的组织加入channel的配置交易信息。因此这些新加入的节点必须包含以下配置信息中的一种,以便它们可以从ordering service收到区块:

    第一种:使用静态leader模式,配置节点为组织的leader:

    CORE_PEER_GOSSIP_USELEADERELECTION=false
    CORE_PEER_GOSSIP_ORGLEADER=true
    

    这种模式要求所有新加入channel的节点都使用同一种配置。

    第二种:使用同步leader选举模式,配置节点使用leader选举:

    CORE_PEER_GOSSIP_USELEADERELECTION=true
    CORE_PEER_GOSSIP_ORGLEADER=false
    

    因为新加入的组织中的节点还不清楚其他节点的成员资格,这种选项一开始和静态模式很像,每个节点一开始都宣称自己是leader。然而,一旦它们被组织加入channel的配置交易信息更新后,组织中就只会有一个节点是leader了。因此,如果你最后希望利用leader选举制度,推荐使用这个选项。

    这部分内容和共识算法有关,特别像Raft。感兴趣可以查看共识机制的基础知识

    将Org3加入到Channel

    现在,channel的配置已经更新了。这里面包括我们的新组织Org3,这也意味着附在其中的节点现在可以加入mychannel了。

    首先,启动Org3的CLI。

    first-network文件夹下新建一个终端,启动Org3组件:

    yuyangdeMacBook-Pro:first-network yuyang$ docker-compose -f docker-compose-org3.yaml up -d
    

    这个新的配置文件已经配置过了,以便连接我们的初始网络,所以其中的两个节点以及CLI容器将会被添加到已有的节点和ordering节点容器,来看看当前的容器有哪些:

    yuyangdeMacBook-Pro:~ yuyang$ docker ps
    CONTAINER ID        IMAGE                                                                                                  COMMAND                  CREATED             STATUS              PORTS                                              NAMES
    5d2fcdcd5629        hyperledger/fabric-tools:latest                                                                        "/bin/bash"              11 seconds ago      Up 41 seconds                                                          Org3cli
    78887afcb88c        hyperledger/fabric-peer:latest                                                                         "peer node start"        12 seconds ago      Up 42 seconds       0.0.0.0:12051->7051/tcp, 0.0.0.0:12053->7053/tcp   peer1.org3.example.com
    aca5ad7f98e1        hyperledger/fabric-peer:latest                                                                         "peer node start"        12 seconds ago      Up 42 seconds       0.0.0.0:11051->7051/tcp, 0.0.0.0:11053->7053/tcp   peer0.org3.example.com
    4679137dd7a3        dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab   "chaincode -peer.add…"   29 hours ago        Up 29 hours                                                            dev-peer1.org2.example.com-mycc-1.0
    203c8ab18c36        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9   "chaincode -peer.add…"   29 hours ago        Up 29 hours                                                            dev-peer0.org1.example.com-mycc-1.0
    c10f7d92412d        dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b   "chaincode -peer.add…"   29 hours ago        Up 29 hours                                                            dev-peer0.org2.example.com-mycc-1.0
    389b71000f2d        hyperledger/fabric-tools:latest                                                                        "/bin/bash"              29 hours ago        Up 29 hours                                                            cli
    359aac8afa52        hyperledger/fabric-peer:latest                                                                         "peer node start"        29 hours ago        Up 29 hours         0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.example.com
    384460892ec9        hyperledger/fabric-peer:latest                                                                         "peer node start"        29 hours ago        Up 29 hours         0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.example.com
    278775f100aa        hyperledger/fabric-peer:latest                                                                         "peer node start"        29 hours ago        Up 29 hours         0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
    da3b1d2acebf        hyperledger/fabric-orderer:latest                                                                      "orderer"                29 hours ago        Up 29 hours         0.0.0.0:7050->7050/tcp                             orderer.example.com
    26ff1144dc5a        hyperledger/fabric-peer:latest                                                                         "peer node start"        29 hours ago        Up 29 hours         0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp     peer0.org2.example.com
    

    现在有了三个新的容器在运行中,我们进入到Org3的CLI容器中:

    yuyangdeMacBook-Pro:first-network yuyang$ docker exec -it Org3cli bash
    

    就像我们在之前初始化CLI容器做的那样,设置两个关键的环境变量:

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem && export CHANNEL_NAME=mychannel
    

    检查下环境变量是否设置正确:

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# echo $ORDERER_CA && echo $CHANNEL_NAME
    

    现在,我们向ordering service发送一个获取mychannel的创世区块。ordering service将会验证Org3签名并且返回结果表示channel更新成功。如果Or3没有被成功的添加到channel的配置中,ordering service会拒绝这个请求。

    再次提醒,你可以通过查看ordering节点日志获取很多有用的信息。例如签名/验证逻辑,以及证明检查。

    使用peer channel fetch指令获取区块:

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
    

    输出内容:

    2018-03-24 08:36:23.781 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 08:36:23.781 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 08:36:23.790 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    2018-03-24 08:36:23.791 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
    2018-03-24 08:36:23.791 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
    2018-03-24 08:36:23.791 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP
    2018-03-24 08:36:23.791 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity
    2018-03-24 08:36:23.791 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0AED060A1508021A0608879CD8D50522...51995898795E12080A021A0012021A00 
    2018-03-24 08:36:23.791 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 28C6C37C980B31CED0CCDBAD04E2EE3CC8AA5C626E965DC44DEED95219AE59DE 
    2018-03-24 08:36:23.793 UTC [channelCmd] readBlock -> DEBU 00a Received block: 0
    2018-03-24 08:36:23.793 UTC [main] main -> INFO 00b Exiting.....
    

    注意,传入参数0,表明我们获取的是channel账本中的第一个区块(也就是创世区块)。如果我们只是简单的传入参数peer channel fetch config,我们获取的会是block5,也就是Org3的配置更新区块。然而,我们的账本不会从后面的区块开始,所以我们必须从block0开始。

    执行peer channel join指令,并且传入创世区块参数mychannel.block

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b mychannel.block
    

    输出内容:

    2018-03-24 08:43:08.185 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 08:43:08.185 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 08:43:08.198 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    2018-03-24 08:43:08.200 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0AB3070A5B08011A0B089C9FD8D50510...FA82F61CABD61A080A000A000A000A00 
    2018-03-24 08:43:08.200 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: B364B0BF0F84A8985AB617C543E248B0ECF58F94281CF57C22D7208118F1FD7C 
    2018-03-24 08:43:08.236 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel
    2018-03-24 08:43:08.236 UTC [main] main -> INFO 007 Exiting.....
    

    如果你想将Org3的第二个节点加入,设置TLSADDRESS环境变量,然后再次执行peer channel join command

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls/ca.crt && export CORE_PEER_ADDRESS=peer1.org3.example.com:7051
    
    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b mychannel.block
    

    升级和调用链码(Upgrade and Invoke Chaincode)

    披萨的最后一片(=。=),是升级链码的版本号,并且让Org3也可以进行背书。既然我们知道将要升级,就不再进行安装版本号为1的链码的练习了。我们只关心使Org3在新版本中成为背书者,因此我们直接将链码版本升级到2。

    在Org3 CLI中:

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
    

    输出如下:

    2018-03-24 09:45:29.010 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 09:45:29.010 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 09:45:29.010 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    2018-03-24 09:45:29.010 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    2018-03-24 09:45:29.010 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
    2018-03-24 09:45:29.052 UTC [golang-platform] getCodeFromFS -> DEBU 006 getCodeFromFS github.com/chaincode/chaincode_example02/go/
    2018-03-24 09:45:29.189 UTC [golang-platform] func1 -> DEBU 007 Discarding GOROOT package fmt
    2018-03-24 09:45:29.189 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim
    2018-03-24 09:45:29.189 UTC [golang-platform] func1 -> DEBU 009 Discarding provided package github.com/hyperledger/fabric/protos/peer
    2018-03-24 09:45:29.189 UTC [golang-platform] func1 -> DEBU 00a Discarding GOROOT package strconv
    2018-03-24 09:45:29.190 UTC [golang-platform] GetDeploymentPayload -> DEBU 00b done
    2018-03-24 09:45:29.191 UTC [container] WriteFileToPackage -> DEBU 00c Writing file to tarball: src/github.com/chaincode/chaincode_example02/go/chaincode_example02.go
    2018-03-24 09:45:29.193 UTC [msp/identity] Sign -> DEBU 00d Sign: plaintext: 0AB3070A5B08031A0B08B9BCD8D50510...CAF857000000FFFF354C5FFC001C0000 
    2018-03-24 09:45:29.194 UTC [msp/identity] Sign -> DEBU 00e Sign: digest: 33B05896D5A3BFDE9F8AF953307D0AA2A89C54017FC3713D034586A9755354C2 
    2018-03-24 09:45:29.196 UTC [chaincodeCmd] install -> DEBU 00f Installed remotely response:<status:200 payload:"OK" > 
    2018-03-24 09:45:29.196 UTC [main] main -> INFO 010 Exiting.....
    

    Modify the environment variables accordingly and reissue the command if you want to install the chaincode on the second peer of Org3. Note that a second installation is not mandated, as you only need to install chaincode on peers that are going to serve as endorsers or otherwise interface with the ledger (i.e. query only). Peers will still run the validation logic and serve as committers without a running chaincode container.

    修改环境变量也可以为Org3的第二个节点安装链码。注意不需要执行第二次初始化,你只需要在节点上安装链码,它们会作为背书或者其他与账本的接口(只是查询)的服务者。节点们仍会在没有运行链码容器的情况下,运行着确定的逻辑或者作为提交者服务。(好难翻译)

    现在跳回到最开始的CLI容器,在Org1和Org2节点上安装新版本的链码。之前我们提交更新的时候,是使用的Org2管理员身份,所以当前容器的身份仍然为peer0.org2

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
    

    输出内容:

    2018-03-24 10:04:38.133 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 10:04:38.133 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 10:04:38.133 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    2018-03-24 10:04:38.133 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    2018-03-24 10:04:38.133 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
    2018-03-24 10:04:38.173 UTC [golang-platform] getCodeFromFS -> DEBU 006 getCodeFromFS github.com/chaincode/chaincode_example02/go/
    2018-03-24 10:04:38.353 UTC [golang-platform] func1 -> DEBU 007 Discarding GOROOT package fmt
    2018-03-24 10:04:38.354 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim
    2018-03-24 10:04:38.354 UTC [golang-platform] func1 -> DEBU 009 Discarding provided package github.com/hyperledger/fabric/protos/peer
    2018-03-24 10:04:38.354 UTC [golang-platform] func1 -> DEBU 00a Discarding GOROOT package strconv
    2018-03-24 10:04:38.358 UTC [golang-platform] GetDeploymentPayload -> DEBU 00b done
    2018-03-24 10:04:38.359 UTC [container] WriteFileToPackage -> DEBU 00c Writing file to tarball: src/github.com/chaincode/chaincode_example02/go/chaincode_example02.go
    2018-03-24 10:04:38.362 UTC [msp/identity] Sign -> DEBU 00d Sign: plaintext: 0AB4070A5C08031A0C08B6C5D8D50510...CAF857000000FFFF354C5FFC001C0000 
    2018-03-24 10:04:38.362 UTC [msp/identity] Sign -> DEBU 00e Sign: digest: E268B1912CA9A7B8C4E61FE65A2621D6DBEB3B6B8A8C023DEED9530AD3076834 
    2018-03-24 10:04:38.365 UTC [chaincodeCmd] install -> DEBU 00f Installed remotely response:<status:200 payload:"OK" > 
    2018-03-24 10:04:38.365 UTC [main] main -> INFO 010 Exiting.....
    

    切换到peer0.org1的身份:

    export CORE_PEER_LOCALMSPID="Org1MSP"
    
    export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    
    export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    
    export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    

    再一次安装:

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
    

    输出内容:

    2018-03-24 10:06:21.986 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 10:06:21.986 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 10:06:21.986 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    2018-03-24 10:06:21.986 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    2018-03-24 10:06:21.986 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
    2018-03-24 10:06:22.025 UTC [golang-platform] getCodeFromFS -> DEBU 006 getCodeFromFS github.com/chaincode/chaincode_example02/go/
    2018-03-24 10:06:22.195 UTC [golang-platform] func1 -> DEBU 007 Discarding GOROOT package fmt
    2018-03-24 10:06:22.195 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim
    2018-03-24 10:06:22.195 UTC [golang-platform] func1 -> DEBU 009 Discarding provided package github.com/hyperledger/fabric/protos/peer
    2018-03-24 10:06:22.195 UTC [golang-platform] func1 -> DEBU 00a Discarding GOROOT package strconv
    2018-03-24 10:06:22.197 UTC [golang-platform] GetDeploymentPayload -> DEBU 00b done
    2018-03-24 10:06:22.197 UTC [container] WriteFileToPackage -> DEBU 00c Writing file to tarball: src/github.com/chaincode/chaincode_example02/go/chaincode_example02.go
    2018-03-24 10:06:22.201 UTC [msp/identity] Sign -> DEBU 00d Sign: plaintext: 0AB3070A5B08031A0B089EC6D8D50510...CAF857000000FFFF354C5FFC001C0000 
    2018-03-24 10:06:22.201 UTC [msp/identity] Sign -> DEBU 00e Sign: digest: DCA841372C48DF443A743733ED40B0B3AC228F1106A35C511025F49716BF8032 
    2018-03-24 10:06:22.203 UTC [chaincodeCmd] install -> DEBU 00f Installed remotely response:<status:200 payload:"OK" > 
    2018-03-24 10:06:22.203 UTC [main] main -> INFO 010 Exiting.....
    

    现在我们准备好更新链码了。链码本身的内容其实并没有修改,我们只需在mychannel上为链码mycc,将Org3添加为背书者。

    任何满足链码实例化规则的身份都可以执行升级操作。默认情况下,这些身份为channel管理员。

    发送指令:

    root@389b71000f2d:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
    

    输出内容:

    2018-03-24 10:16:21.598 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 10:16:21.598 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 10:16:21.615 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    2018-03-24 10:16:21.615 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    2018-03-24 10:16:21.616 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
    2018-03-24 10:16:21.616 UTC [chaincodeCmd] upgrade -> DEBU 006 Get upgrade proposal for chaincode <name:"mycc" version:"2.0" >
    2018-03-24 10:16:21.616 UTC [msp/identity] Sign -> DEBU 007 Sign: plaintext: 0ABF070A6708031A0C08F5CAD8D50510...535010030A04657363630A0476736363 
    2018-03-24 10:16:21.616 UTC [msp/identity] Sign -> DEBU 008 Sign: digest: 0B6E66367139749C4C4A261C7A6C4DA4C554AA5C948DF3BCEB58201392D85F2E 
    2018-03-24 10:16:32.730 UTC [chaincodeCmd] upgrade -> DEBU 009 endorse upgrade proposal, get response <status:200 message:"OK" payload:"\n\004mycc\022\0032.0\032\004escc\"\004vscc*?\022\020\022\016\010\001\022\002\010\000\022\002\010\001\022\002\010\002\032\r\022\013\n\007Org1MSP\020\003\032\r\022\013\n\007Org2MSP\020\003\032\r\022\013\n\007Org3MSP\020\0032D\n \222G\373\202N!\320\207\017\376y<\360`$\346^\206\361\340\345\213d\351\014[\031On74\000\022 g\357,\324!\221P`u\035X\006\327\257\037\324\334\003\003\251\2628\321\345\262$\360\r\351\220^\\: \235\322J\005\214V\273\257\340\244\273$y\325\215iP\365\211\266'\267<p)\340\020\364`\247\307\323B?\022\020\022\016\010\001\022\002\010\000\022\002\010\001\022\002\010\002\032\r\022\013\n\007Org1MSP\020\001\032\r\022\013\n\007Org2MSP\020\001\032\r\022\013\n\007Org3MSP\020\001" >
    2018-03-24 10:16:32.730 UTC [msp/identity] Sign -> DEBU 00a Sign: plaintext: 0ABF070A6708031A0C08F5CAD8D50510...1718EEF1B39BB6D9D9165C937B0693E6 
    2018-03-24 10:16:32.730 UTC [msp/identity] Sign -> DEBU 00b Sign: digest: F715D0B2D37AA7CB55A5274264B38C9F140D7BB35774E58FBB2FF62626F028AB 
    2018-03-24 10:16:32.731 UTC [chaincodeCmd] upgrade -> DEBU 00c Get Signed envelope
    2018-03-24 10:16:32.731 UTC [chaincodeCmd] chaincodeUpgrade -> DEBU 00d Send signed envelope to orderer
    2018-03-24 10:16:32.734 UTC [main] main -> INFO 00e Exiting.....
    

    通过上面的代码,可以看到我们使用v标志来对新版本进行指定。也可以看到我们已经将背书政策修改为-P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')",将Org3添加为背书者。使用c标志来指定构造函数请求。

    作为一个初始化请求,链码的升级使用init方法。如果你的链码需要在init方法里传入参数,那你需要在这里完成。

    升级指令将添加一个新的区块block6到账本中,并且允许Org3的节点在背书阶段执行交易。回到Org3的CLI容器,对值a进行一个查询交易。这会花一些时间,因为将会为目标节点构建一个链码镜像,然后容器需要启动:

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
    

    输出内容:

    2018-03-24 10:34:12.646 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 10:34:12.646 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 10:34:12.646 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    2018-03-24 10:34:12.647 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    2018-03-24 10:34:12.647 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
    2018-03-24 10:34:12.647 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABF070A6708031A0C08A4D3D8D50510...6D7963631A0A0A0571756572790A0161 
    2018-03-24 10:34:12.647 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: D7B13BC02DD8EABDD49EAA8899786577AC35DF73922F200037956806D3078482 
    Query Result: 90
    2018-03-24 10:34:23.884 UTC [main] main -> INFO 008 Exiting.....
    

    返回的结果包含Query Result: 90

    现在从ab10

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
    

    输出内容:

    2018-03-24 10:37:32.652 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 10:37:32.652 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 10:37:32.665 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    2018-03-24 10:37:32.666 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    2018-03-24 10:37:32.667 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
    2018-03-24 10:37:32.667 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABF070A6708031A0C08ECD4D8D50510...696E766F6B650A01610A01620A023130 
    2018-03-24 10:37:32.668 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 2578BFA34BDC375AF8A6E66F9B861618C5DCA782EA7F4BC908172EAF8E89D09A 
    2018-03-24 10:37:32.673 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0ABF070A6708031A0C08ECD4D8D50510...00923B1463D09D071A9A1E15A664D712 
    2018-03-24 10:37:32.673 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 508480A9817D7726DB4FAFD91835E1C459F746FB5B7D8190655A1F98E137E552 
    2018-03-24 10:37:32.674 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response:<status:200 message:"OK" > payload:"\n S]\033\324\234\366>G6\255\013\032oC\016\354{\345\325\232\302\036\233\324\236C u\252\004?\035\022Y\nE\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\010\006\022-\n\004mycc\022%\n\007\n\001a\022\002\010\006\n\007\n\001b\022\002\010\006\032\007\n\001a\032\00280\032\010\n\001b\032\003220\032\003\010\310\001\"\013\022\004mycc\032\0032.0" endorsement:<endorser:"\n\007Org3MSP\022\252\006-----BEGIN CERTIFICATE-----\nMIICKTCCAc+gAwIBAgIRAJdxCqdH/KGtFgjjn76Y1fIwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzMuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzMuZXhhbXBsZS5jb20wHhcNMTgwMzIzMDI1NTIxWhcNMjgwMzIwMDI1NTIx\nWjBqMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzENMAsGA1UECxMEcGVlcjEfMB0GA1UEAxMWcGVlcjEub3Jn\nMy5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABBGeJ396meqF\n7NrVFZxGwH20dWeZJdM3P7OMnk94Q2jUVLByCX7KZeo1Knj8V5WewLTX9KL1o9Q0\nwqpYWVwEufijTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1Ud\nIwQkMCKAIDSvqYMzytt6xz90/MKTwgA3GBnwM5L2hZX/MNJL3CkzMAoGCCqGSM49\nBAMCA0gAMEUCIQDRS6vnHOcwX9+PVSj8qV1hn+hgP8M4ZI26r8SwmYiZqgIgRp+Q\nutOLaPQls/yb6TimqhzmuOmPtqw4fGw5eqVEH4w=\n-----END CERTIFICATE-----\n" signature:"0E\002!\000\274 \256\373\276\3735F\006\010H\356\273E\364A\375t8TZ\261\313\305\272\026}\003\003\325\017\"\002 Q Pp\353\364i\017\003\030\226\264\276\361\217v\000\222;\024c\320\235\007\032\232\036\025\246d\327\022" > 
    2018-03-24 10:37:32.675 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200 
    2018-03-24 10:37:32.675 UTC [main] main -> INFO 00c Exiting.....
    

    最后再查询一次:

    root@5d2fcdcd5629:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
    

    输出内容:

    2018-03-24 10:38:40.225 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
    2018-03-24 10:38:40.225 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
    2018-03-24 10:38:40.225 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    2018-03-24 10:38:40.225 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    2018-03-24 10:38:40.225 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
    2018-03-24 10:38:40.225 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABE070A6608031A0B08B0D5D8D50510...6D7963631A0A0A0571756572790A0161 
    2018-03-24 10:38:40.225 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: FB2F0737D896F44B1DA22F63A7FF4E15E4615F604885F62FAD2413776339F27A 
    Query Result: 80
    2018-03-24 10:38:40.230 UTC [main] main -> INFO 008 Exiting.....
    

    可以看到返回值为Query Result: 80。准确反应了当前链码的世界状态。

    结论(Conclusion)

    channel的配置升级的确相当复杂,但每一个步骤都很合乎逻辑。

    configtxlatorjq工具,随着peer channel命令一起,为我们提供了完成这个任务的方法。

    相关文章

      网友评论

      • 3f4f7d0f98bd:写的太好了,非常受教,希望有空能继续写几个hyperledger的实战教程:yum:
        yuyangray:感谢,后面如果有机会的话会写

      本文标题:Hyperledger Fabric(四) 官方教程:添加一个O

      本文链接:https://www.haomeiwen.com/subject/tkogqftx.html