Hyperledger FabricでMulti Channelを作ってチェーンコードの動きを確認してみた

この記事は [BlockChain Advent Calendar 2017](https://qiita.com/advent-calendar/2017/blockchain2017) の6日目の記事です。

少し前に確認してみたことですが、カレンダーが空いていたので...
失礼しま〜す(笑)

Hyperledger Fabricの特徴の一つに[channel](https://hyperledger-fabric.readthedocs.io/en/release/channels.html?highlight=channel)という概念があります。
エンタープライズ向けの実用を想定しているため、channelごとにノードを分けて、そのchannelに属していないノードはチェーンコードを実行できず、台帳も見ることができないということですが...
githubにあるサンプルには複数のchannelを作る具体的な方法が書いてありません。
本当にchannelが違うとチェーンコードは実行できないのか...？

疑ってみて、自分で試して見るというのは大事なことだと思うので、今回はgithubの[fabric-samples/first-network](https://github.com/hyperledger/fabric-samples)を使用して実際に複数のchannelを作ることができるのか試してみました。

##1. hyperledger/fabricの公式ドキュメント「Building Your First Network」に従ってimageをダウンロードする

1. orgごとにclietを分けて、channelの作成を試すため、docker-compose-cli.yamlを以下のように修正する。

```
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

networks:
  byfn:

services:

  orderer.example.com:
    extends:
      file:   base/docker-compose-base.yaml

〜〜（省略）〜〜

  peer1.org2.example.com:
    container_name: peer1.org2.example.com
    extends:
      file:  base/docker-compose-base.yaml
      service: peer1.org2.example.com
    networks:
      - byfn

  cli.org1:
    container_name: cli.org1
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli.org1
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=true
      - 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_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_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_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    # command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - orderer.example.com
      - peer0.org1.example.com
      - peer1.org1.example.com
      - peer0.org2.example.com
      - peer1.org2.example.com
    networks:
      - byfn

  cli.org2:
    container_name: cli.org2
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli.org2
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
      - 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_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    # command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - orderer.example.com
      - peer0.org1.example.com
      - peer1.org1.example.com
      - peer0.org2.example.com
      - peer1.org2.example.com
    networks:
      - byfn
```

##2. ./byfn.sh -m generate -c mychannel1を実行する

```
./byfn.sh -m generate -c mychannel1
Generating certs and genesis block for with channel 'mychannel1' and CLI timeout of '10000'
Continue (y/n)? y
proceeding ...
/opt/gopath/src/github.com/hyperledger/fabric/examples/fabric-samples/first-network/../bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
org2.example.com

/opt/gopath/src/github.com/hyperledger/fabric/examples/fabric-samples/first-network/../bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
2017-08-29 18:13:45.571 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-29 18:13:45.605 JST [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
2017-08-29 18:13:45.607 JST [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2017-08-29 18:13:45.626 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-29 18:13:45.629 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2017-08-29 18:13:45.630 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
2017-08-29 18:13:45.653 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-29 18:13:45.658 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-08-29 18:13:45.658 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
2017-08-29 18:13:45.681 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-29 18:13:45.683 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-08-29 18:13:45.684 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
```

##3. ./byfn.sh -m upでdockerを起動する

Error response from daemon: No such container: cliが出るがテストが失敗しているだけなので問題ありません。

```
CONTAINER ID        IMAGE                                                                                                    COMMAND                  CREATED             STATUS              PORTS                                              NAMES
acfbc4ec03bc        dev-peer0.org2.example.com-fabcar-1.0-264b0a1cb5efbecaac5cf8990339c24474dc8435c6e10f10f2be565d555d0e94   "chaincode -peer.a..."   3 hours ago         Up 3 hours                                                             dev-peer0.org2.example.com-fabcar-1.0
c07f0f929f5d        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9     "chaincode -peer.a..."   4 hours ago         Up 4 hours                                                             dev-peer0.org1.example.com-mycc-1.0
7bcffb6b5de7        hyperledger/fabric-tools                                                                                 "/bin/bash"              4 hours ago         Up 4 hours                                                             cli.org2
9dbe8cc15d29        hyperledger/fabric-tools                                                                                 "/bin/bash"              4 hours ago         Up 4 hours                                                             cli.org1
470809cb8ea7        hyperledger/fabric-peer                                                                                  "peer node start"        4 hours ago         Up 4 hours          0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.example.com
615858faa7bc        hyperledger/fabric-orderer                                                                               "orderer"                4 hours ago         Up 4 hours          0.0.0.0:7050->7050/tcp                             orderer.example.com
34aae463caf8        hyperledger/fabric-peer                                                                                  "peer node start"        4 hours ago         Up 4 hours          0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
026ccc9db8e1        hyperledger/fabric-peer                                                                                  "peer node start"        4 hours ago         Up 4 hours          0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp     peer0.org2.example.com
4d819dc0c625        hyperledger/fabric-peer                                                                                  "peer node start"        4 hours ago         Up 4 hours          0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.example.com
```

clientがorgごとに起動していることが分かります。

##4. cli.org1でチェーンコードを実行する

1.　clientのコンテナに入る。

```
docker exec -it cli.org1 bash
```

2.　channel名を設定する。

```
export CHANNEL_NAME=mychannel1
```

3.　channelを作成する。

```
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

〜〜（省略）〜〜

2017-08-30 01:42:58.069 UTC [msp/identity] Sign -> DEBU 01f Sign: digest: 622226C6E22FAD2539D9CB0286F0541C670097727A184C156324C165807A6888
2017-08-30 01:42:58.074 UTC [channelCmd] readBlock -> DEBU 020 Received block: 0
2017-08-30 01:42:58.076 UTC [main] main -> INFO 021 Exiting.....
```

4.　channelにjoinする。

```
peer channel join -b mychannel1.block

〜〜（省略）〜〜

2017-08-30 01:43:11.253 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2017-08-30 01:43:11.253 UTC [main] main -> INFO 007 Exiting.....
```

5.　参加しているchannelを確認する。

```
peer channel list

〜〜（省略）〜〜

2017-08-30 01:43:16.736 UTC [channelCmd] list -> INFO 006 Channels peers has joined to:
2017-08-30 01:43:16.736 UTC [channelCmd] list -> INFO 007 mychannel1
2017-08-30 01:43:16.736 UTC [main] main -> INFO 008 Exiting.....
```

6.　チェーンコードをインストールする。

```
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

〜〜（省略）〜〜

2017-08-30 01:48:00.826 UTC [chaincodeCmd] install -> DEBU 00d Installed remotely response:<status:200 payload:"OK" >
2017-08-30 01:48:00.826 UTC [main] main -> INFO 00e Exiting.....
```

7.　チェーンコードを初期化する。

```
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"

〜〜（省略）〜〜

2017-08-30 01:49:10.309 UTC [msp/identity] Sign -> DEBU 007 Sign: plaintext: 0A92070A6808031A0C0887B398CD0510...F84692B115099D256B0C9EF19F3C9622
2017-08-30 01:49:10.309 UTC [msp/identity] Sign -> DEBU 008 Sign: digest: 4261BFAB76FF0BEE903F9AFDA2C1D09D4B65F82F37E98D8022E3EFEACD38E2F2
2017-08-30 01:49:10.313 UTC [main] main -> INFO 009 Exiting.....
```

8.　チェーンコードを実行する。

```
peer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'

〜〜（省略）〜〜

2017-08-30 01:49:38.381 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00a Chaincode invoke successful. result: status:200
2017-08-30 01:49:38.382 UTC [main] main -> INFO 00b Exiting.....
```

9.　クエリを実行して、結果を確認する。

```
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'

2017-08-30 01:50:05.335 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 01:50:05.336 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 01:50:05.336 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 01:50:05.336 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 01:50:05.337 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A92070A6808031A0C08CDB398CD0510...6D7963631A0A0A0571756572790A0161
2017-08-30 01:50:05.337 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 4E2986CE9A9F51CB2FF0E9B1EB279A470CC38915D3861C781761F31AC3F5CF56
Query Result: 90
```

"a"の値が100から90になっている。

##5. org2でmychannel2を作ってチェーンコードを実行する

1.　mychannel2を作るためにbyfn.shを修正する。
function generateCerts ()をコメントアウトします。
（コメントアウトしないと新たにmspが生成され、コンテナ内でコマンドを実行した時にエラーとなるため）

2.　./byfn.sh -m generate -c mychannel2を実行する。

```
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
2017-08-30 10:45:15.990 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-30 10:45:16.031 JST [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
2017-08-30 10:45:16.032 JST [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2017-08-30 10:45:16.064 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-30 10:45:16.068 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2017-08-30 10:45:16.073 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
2017-08-30 10:45:16.102 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-30 10:45:16.108 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-08-30 10:45:16.108 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
2017-08-30 10:45:16.134 JST [common/configtx/tool] main -> INFO 001 Loading configuration
2017-08-30 10:45:16.146 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-08-30 10:45:16.146 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
```

3.　'docker exec -it cli.org2 bash'でcli.org2のコンテナに入る。

4.　mychannel1で行ったことをmychannel2で繰り返す。

```
root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# export CHANNEL_NAME=mychannel2

root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2017-08-30 01:46:48.720 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 01:46:48.720 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 01:46:48.730 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2017-08-30 01:46:48.733 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2017-08-30 01:46:48.733 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2017-08-30 01:46:48.733 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP
2017-08-30 01:46:48.733 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity
2017-08-30 01:46:48.733 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0A8C060A074F7267324D53501280062D...53616D706C65436F6E736F727469756D
2017-08-30 01:46:48.733 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: FC609D8FA1F49F99EDF67B10C9F2951BB7E6898CD33234CFE7BEC4DA53704C44
2017-08-30 01:46:48.733 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP
2017-08-30 01:46:48.733 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity
2017-08-30 01:46:48.734 UTC [msp] GetLocalMSP -> DEBU 00c Returning existing local MSP
2017-08-30 01:46:48.734 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity
2017-08-30 01:46:48.734 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC4060A1608021A060888B298CD0522...38245C92E77457FBF872FBD6F67BAA32
2017-08-30 01:46:48.734 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: 75F8153DDECDE6341C724CC590A1D5D85CCFCE469ABBBEF8E28CC672AFD8AA99
2017-08-30 01:46:48.814 UTC [msp] GetLocalMSP -> DEBU 010 Returning existing local MSP
2017-08-30 01:46:48.814 UTC [msp] GetDefaultSigningIdentity -> DEBU 011 Obtaining default signing identity
2017-08-30 01:46:48.814 UTC [msp] GetLocalMSP -> DEBU 012 Returning existing local MSP
2017-08-30 01:46:48.814 UTC [msp] GetDefaultSigningIdentity -> DEBU 013 Obtaining default signing identity
2017-08-30 01:46:48.814 UTC [msp/identity] Sign -> DEBU 014 Sign: plaintext: 0AC4060A1608021A060888B298CD0522...A4E619F8C08712080A021A0012021A00
2017-08-30 01:46:48.814 UTC [msp/identity] Sign -> DEBU 015 Sign: digest: 6E963EAA9FDEF61B3842BD4869E3F21BBD9C7D9DA4DEA082128837E688B2EDB0
2017-08-30 01:46:48.814 UTC [channelCmd] readBlock -> DEBU 016 Got status: &{NOT_FOUND}
2017-08-30 01:46:48.814 UTC [msp] GetLocalMSP -> DEBU 017 Returning existing local MSP
2017-08-30 01:46:48.814 UTC [msp] GetDefaultSigningIdentity -> DEBU 018 Obtaining default signing identity
2017-08-30 01:46:48.840 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized
2017-08-30 01:46:49.042 UTC [msp] GetLocalMSP -> DEBU 01a Returning existing local MSP
2017-08-30 01:46:49.043 UTC [msp] GetDefaultSigningIdentity -> DEBU 01b Obtaining default signing identity
2017-08-30 01:46:49.044 UTC [msp] GetLocalMSP -> DEBU 01c Returning existing local MSP
2017-08-30 01:46:49.044 UTC [msp] GetDefaultSigningIdentity -> DEBU 01d Obtaining default signing identity
2017-08-30 01:46:49.046 UTC [msp/identity] Sign -> DEBU 01e Sign: plaintext: 0AC4060A1608021A060889B298CD0522...E44A1D4CC97D12080A021A0012021A00
2017-08-30 01:46:49.046 UTC [msp/identity] Sign -> DEBU 01f Sign: digest: C9FF43D3130B3DCE279E2B7C29C531B4E93EBC8AD0F3CEBE8B0800655FAA318D
2017-08-30 01:46:49.049 UTC [channelCmd] readBlock -> DEBU 020 Received block: 0
2017-08-30 01:46:49.051 UTC [main] main -> INFO 021 Exiting.....

root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b mychannel2.block
2017-08-30 01:47:24.108 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 01:47:24.108 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 01:47:24.117 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2017-08-30 01:47:24.118 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A89070A5B08011A0B08ACB298CD0510...6B2E2FCE9FCE1A080A000A000A000A00
2017-08-30 01:47:24.118 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: F976F4E48BD576588B5E7066637CA6A1E4FC30A986DDCD03C4AAEBC278785730
2017-08-30 01:47:24.173 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2017-08-30 01:47:24.173 UTC [main] main -> INFO 007 Exiting.....
```

peer channel listでmychannel2にjoinしていることがわかります。

```
2017-08-30 01:51:12.230 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 01:51:12.237 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2017-08-30 01:51:12.237 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A89070A5B08031A0B0890B498CD0510...631A0D0A0B4765744368616E6E656C73
2017-08-30 01:51:12.237 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: 224B912B18F2D54B3DFC4CAA034A707E4EA17ACE5B3131889D56BB024A1C6A4A
2017-08-30 01:51:12.241 UTC [channelCmd] list -> INFO 006 Channels peers has joined to:
2017-08-30 01:51:12.241 UTC [channelCmd] list -> INFO 007 mychannel2
2017-08-30 01:51:12.241 UTC [main] main -> INFO 008 Exiting.....
```

5.　mychannel2でmychannel1で作ったチェーンコードに対してqueryを投げてみる。

```
root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel2 -n mycc -c '{"Args":["query","a"]}'
2017-08-30 01:53:06.526 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 01:53:06.526 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 01:53:06.526 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 01:53:06.526 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 01:53:06.526 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A96070A6808031A0C0882B598CD0510...6D7963631A0A0A0571756572790A0161
2017-08-30 01:53:06.527 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 4AD8E0A84B9C95518B76BD8D5573E78FAEF30541FA8C08DEA6B891F14C794779
Error: Error endorsing query: rpc error: code = Unknown desc = could not find chaincode with name 'mycc' - make sure the chaincode mycc has been successfully instantiated and try again - <nil>
```

エラーになった！

6.　cli.org2でfabcarのchaincodeをインストールする。
mychannel2では別のチェーンコードを実行してみます。今回は同じくfabric-samplesにあるfabcarのチェーンコードを使いました。

```
root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n fabcar -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/fabcar
2017-08-30 01:55:07.104 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 01:55:07.104 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 01:55:07.105 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 01:55:07.105 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 01:55:07.167 UTC [golang-platform] getCodeFromFS -> DEBU 005 getCodeFromFS github.com/hyperledger/fabric/examples/chaincode/go/fabcar
2017-08-30 01:55:07.348 UTC [golang-platform] func1 -> DEBU 006 Discarding GOROOT package bytes
2017-08-30 01:55:07.349 UTC [golang-platform] func1 -> DEBU 007 Discarding GOROOT package encoding/json
2017-08-30 01:55:07.349 UTC [golang-platform] func1 -> DEBU 008 Discarding GOROOT package fmt
2017-08-30 01:55:07.349 UTC [golang-platform] func1 -> DEBU 009 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim
2017-08-30 01:55:07.349 UTC [golang-platform] func1 -> DEBU 00a Discarding provided package github.com/hyperledger/fabric/protos/peer
2017-08-30 01:55:07.350 UTC [golang-platform] func1 -> DEBU 00b Discarding GOROOT package strconv
2017-08-30 01:55:07.352 UTC [golang-platform] GetDeploymentPayload -> DEBU 00c done
2017-08-30 01:55:07.359 UTC [msp/identity] Sign -> DEBU 00d Sign: plaintext: 0A8A070A5C08031A0C08FBB598CD0510...C5CF7F020000FFFF5927419400200000
2017-08-30 01:55:07.359 UTC [msp/identity] Sign -> DEBU 00e Sign: digest: A839BCE9BE4DF447F711C4A2238C8A8868C55FF4B8066B1004ECA46665876732
2017-08-30 01:55:07.366 UTC [chaincodeCmd] install -> DEBU 00f Installed remotely response:<status:200 payload:"OK" >
2017-08-30 01:55:07.366 UTC [main] main -> INFO 010 Exiting.....
```

7.　mychannel2でチェーンコードを初期化する。

```
root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n fabcar -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
2017-08-30 01:59:39.852 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 01:59:39.852 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 01:59:39.865 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 01:59:39.865 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 01:59:39.868 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A96070A6808031A0C088BB898CD0510...324D53500A04657363630A0476736363
2017-08-30 01:59:39.868 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 1A9F10D8956FAC6DAE7ADE43821F57487C099D1C1981C57E21D8866CB051B3F4
2017-08-30 01:59:54.454 UTC [msp/identity] Sign -> DEBU 007 Sign: plaintext: 0A96070A6808031A0C088BB898CD0510...BEFEBB33536F067AF855B08A45FC56F3
2017-08-30 01:59:54.454 UTC [msp/identity] Sign -> DEBU 008 Sign: digest: 66E6BB45130D55D7709B3A9E435EB230E2A58B8C6AEAC8905F3A250C35940556
2017-08-30 01:59:54.461 UTC [main] main -> INFO 009 Exiting.....
```

8.　fabcarでinitLedgerのinvokeを実行する。

```
root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n fabcar -c '{"Args":["initLedger"]}'
2017-08-30 02:02:11.245 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 02:02:11.245 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity

〜〜（省略）〜〜

2017-08-30 02:02:11.290 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00a Chaincode invoke successful. result: status:200
2017-08-30 02:02:11.291 UTC [main] main -> INFO 00b Exiting.....
```

実行できた！！

9.　queryを実行する。

```
root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C $CHANNEL_NAME -n fabcar -c '{"Args":["queryAllCars"]}'
2017-08-30 02:03:20.190 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 02:03:20.190 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 02:03:20.190 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 02:03:20.190 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 02:03:20.192 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A97070A6908031A0B08E8B998CD0510...1A0E0A0C7175657279416C6C43617273
2017-08-30 02:03:20.192 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 13DF809A66E28B8BCCB2163446201C1C9B0E4B3C509E8AE0F4F719905A5A5A39
Query Result: [{"Key":"CAR0", "Record":{"make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{"Key":"CAR2", "Record":{"make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{"Key":"CAR3", "Record":{"make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{"Key":"CAR4", "Record":{"make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{"Key":"CAR5", "Record":{"make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{"Key":"CAR6", "Record":{"make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{"Key":"CAR7", "Record":{"make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{"Key":"CAR8", "Record":{"make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{"Key":"CAR9", "Record":{"make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}]
2017-08-30 02:03:20.210 UTC [main] main -> INFO 007 Exiting.....
```

10.　cli.org1のコンテナに入って、queryAllCarsが実行できないことを確認する。

```
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C $CHANNEL_NAME -n fabcar -c '{"Args":["queryAllCars"]}'
2017-08-30 02:04:14.884 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 02:04:14.884 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 02:04:14.884 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 02:04:14.885 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 02:04:14.885 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A94070A6A08031A0C089EBA98CD0510...1A0E0A0C7175657279416C6C43617273
2017-08-30 02:04:14.885 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 73C4C39EA82CE0E61A1EE052FCE452E90FE3FA5984CD325BA9657277A41876A9
Error: Error endorsing query: rpc error: code = Unknown desc = could not find chaincode with name 'fabcar' - make sure the chaincode fabcar has been successfully instantiated and try again - <nil>
```

エラーになった！

11.　CHANNEL_NAMEをmychannel2に指定してもエラーとなることを確認する。

```
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel2 -n fabcar -c '{"Args":["queryAllCars"]}'
2017-08-30 02:04:46.291 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 02:04:46.291 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 02:04:46.291 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 02:04:46.291 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 02:04:46.292 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A94070A6A08031A0C08BEBA98CD0510...1A0E0A0C7175657279416C6C43617273
2017-08-30 02:04:46.292 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 3B8BEEF9E8C5E396E1FCAF43B8E380C718C547AEB4868F6226DADFB0F939B47D
Error: Error endorsing query: rpc error: code = Unknown desc = Failed to deserialize creator identity, err MSP Org1MSP is unknown - <nil>
```

エラーになります。いい調子！！

12.　cli.org1をmychannel2にjoinさせる。
org1をmychannel2にjoinさせて、fabcarのチェーンコードを実行できるか試してみます。
（cli.org2で生成されたmychannel2.blockをcli.org1のpeerディレクトリ直下にコピーしてmychannel2にjoinする。）

```
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b mychannel2.block
2017-08-30 05:29:33.231 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 05:29:33.231 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 05:29:33.241 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2017-08-30 05:29:33.242 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A85070A5B08011A0B08BD9A99CD0510...6B2E2FCE9FCE1A080A000A000A000A00
2017-08-30 05:29:33.242 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: C775FE8C8698938EBE216710D359BB657B4CCB41F727C819D485D2C8469D711B
2017-08-30 05:29:33.317 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2017-08-30 05:29:33.317 UTC [main] main -> INFO 007 Exiting.....
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel list
2017-08-30 05:29:42.617 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 05:29:42.617 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 05:29:42.637 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2017-08-30 05:29:42.638 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A86070A5C08031A0C08C69A99CD0510...631A0D0A0B4765744368616E6E656C73
2017-08-30 05:29:42.638 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: D3091E3E79D7FB1EACD0C5AFED58E6250369764AFE8CEA4E3C7716D61F9A641D
2017-08-30 05:29:42.648 UTC [channelCmd] list -> INFO 006 Channels peers has joined to:
2017-08-30 05:29:42.648 UTC [channelCmd] list -> INFO 007 mychannel1
2017-08-30 05:29:42.648 UTC [channelCmd] list -> INFO 008 mychannel2
2017-08-30 05:29:42.648 UTC [main] main -> INFO 009 Exiting.....
```

13.　mychannel2でインストールしたfabcarのchaincodeをクエリできるか試す。

```
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel2 -n fabcar -c '{"Args":["queryAllCars"]}'
2017-08-30 05:30:10.936 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 05:30:10.936 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 05:30:10.936 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 05:30:10.937 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 05:30:10.942 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A94070A6A08031A0C08E29A99CD0510...1A0E0A0C7175657279416C6C43617273
2017-08-30 05:30:10.942 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 3A5A1CF3B4730C12C49AF85A622010D5D80C87D67B771287468D8E94BCA54903
Error: Error endorsing query: rpc error: code = Unknown desc = cannot retrieve package for chaincode fabcar/1.0, error open /var/hyperledger/production/chaincodes/fabcar.1.0: no such file or directory - <nil>
```

あれ、エラーになったぞ...

14.　cli.org2でインストールしたchiancodeをcli.org1でもインストールする。

```
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n fabcar -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/fabcar
2017-08-30 05:50:56.282 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 05:50:56.282 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 05:50:56.283 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 05:50:56.283 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 05:50:56.392 UTC [golang-platform] getCodeFromFS -> DEBU 005 getCodeFromFS github.com/hyperledger/fabric/examples/chaincode/go/fabcar
2017-08-30 05:50:56.622 UTC [golang-platform] func1 -> DEBU 006 Discarding GOROOT package bytes
2017-08-30 05:50:56.623 UTC [golang-platform] func1 -> DEBU 007 Discarding GOROOT package encoding/json
2017-08-30 05:50:56.623 UTC [golang-platform] func1 -> DEBU 008 Discarding GOROOT package fmt
2017-08-30 05:50:56.624 UTC [golang-platform] func1 -> DEBU 009 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim
2017-08-30 05:50:56.624 UTC [golang-platform] func1 -> DEBU 00a Discarding provided package github.com/hyperledger/fabric/protos/peer
2017-08-30 05:50:56.625 UTC [golang-platform] func1 -> DEBU 00b Discarding GOROOT package strconv
2017-08-30 05:50:56.627 UTC [golang-platform] GetDeploymentPayload -> DEBU 00c done
2017-08-30 05:50:56.634 UTC [msp/identity] Sign -> DEBU 00d Sign: plaintext: 0A86070A5C08031A0C08C0A499CD0510...C5CF7F020000FFFF5927419400200000
2017-08-30 05:50:56.638 UTC [msp/identity] Sign -> DEBU 00e Sign: digest: A2707FA1E55F43587BE45C19660EBC2B5043BC6BB6C3CDB2981D9B83DC666301
2017-08-30 05:50:56.643 UTC [chaincodeCmd] install -> DEBU 00f Installed remotely response:<status:200 payload:"OK" >
2017-08-30 05:50:56.643 UTC [main] main -> INFO 010 Exiting.....
```

おっ！うまくいった！

15.　改めて、mychannel2でinstallしたfabcarのchaincodeをorg1でクエリできるか試す。

```
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel2 -n fabcar -c '{"Args":["queryAllCars"]}'
2017-08-30 05:51:00.486 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 05:51:00.486 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 05:51:00.486 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 05:51:00.486 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 05:51:00.487 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A94070A6A08031A0C08C4A499CD0510...1A0E0A0C7175657279416C6C43617273
2017-08-30 05:51:00.487 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 3C62321A35963391BE4144058F7CFF1F73F43EC1AB22E71022DDEA75D09160F4
Query Result: [{"Key":"CAR0", "Record":{"make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{"Key":"CAR2", "Record":{"make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{"Key":"CAR3", "Record":{"make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{"Key":"CAR4", "Record":{"make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{"Key":"CAR5", "Record":{"make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{"Key":"CAR6", "Record":{"make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{"Key":"CAR7", "Record":{"make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{"Key":"CAR8", "Record":{"make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{"Key":"CAR9", "Record":{"make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}]
2017-08-30 05:51:15.783 UTC [main] main -> INFO 007 Exiting.....
```

できた！！

16.　cli.org1でcreateCarを実行してみる。

```
root@9dbe8cc15d29:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --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 mychannel2 -n fabcar -c '{"Args":["createCar","CAR10", "Tesla", "SS", "silver", "shiki"]}'
2017-08-30 06:08:14.328 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 06:08:14.329 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity

〜〜（省略）〜〜

2017-08-30 06:08:14.369 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00a Chaincode invoke successful. result: status:200
2017-08-30 06:08:14.369 UTC [main] main -> INFO 00b Exiting.....
```

cli.org1でcreateCarできた！

17.　cli.org2でCAR10の情報がqueryできるか確認する。
org1のclientで作ったCAR10の情報がorg2のクライアントでクエリできれば...

```
root@7bcffb6b5de7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel2 -n fabcar -c '{"Args":["queryCar", "CAR10"]}'
2017-08-30 06:10:06.913 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 06:10:06.913 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 06:10:06.913 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2017-08-30 06:10:06.913 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2017-08-30 06:10:06.914 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A98070A6A08031A0C08BEAD99CD0510...0871756572794361720A054341523130
2017-08-30 06:10:06.914 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 0ED7C50F160492ABAF23954F5ED6E7172CAF147588820472F78B27FBDC47D97B
Query Result: {"make":"Tesla","model":"SS","colour":"silver","owner":"shiki"}
2017-08-30 06:10:06.934 UTC [main] main -> INFO 007 Exiting.....
```

素晴らしいっ！！！

##6. まとめ

ということで、無事複数のchannelを作成して、チェーンコードの実行、クエリが別々にできることを確認することができました。
IBMの言っていたことは嘘ではないということですな、よかった、よかった。（笑）
channelを複数使ってorgごとに台帳を管理できるというのは複数の組織でプライベートに閉じた状態で使うブロックチェーンとしてはFabricのセキュリティ性能はかなり高いと思います。

##7. ちなみに...

一応できたけど、genesis blockをコンテナからコピーして使うっていうのはなんだかな〜と思ってたら！
↓によるとCORE_PEER_ADDRESSをpeer channel joinの前に設定してやるとclientを2つ作らなくても複数のchannelができる見たい。
http://hyperledger-fabric.readthedocs.io/en/latest/install_instantiate.html?highlight=peer%20channel%20join

ということで、元の設定に戻して最初からやり直し。

cli内のCORE_PEERに関する環境変数を以下のように変更。

```
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
      - 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_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
```

するとcliからchannelにjoinすることができました！

```
root@965af38c1c27:/opt/gopath/src/github.com/hyperledger/fabric/peer# CORE_PEER_ADDRESS=peer0.org2.example.com:7051 peer channel join -b mychannel2.block
2017-08-30 09:05:01.585 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 09:05:01.585 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 09:05:01.596 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2017-08-30 09:05:01.598 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C08BDFF99CD0510...BE65865658481A080A000A000A000A00
2017-08-30 09:05:01.598 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: 7C5FF5A7E77C5274412FDB187B193514A3EF6880A75E3283DDCC005B84A8E410
2017-08-30 09:05:01.651 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2017-08-30 09:05:01.655 UTC [main] main -> INFO 007 Exiting.....
```

↓peer0.org2.example.comのコンテナに入り、確認。

```
root@49b3fc5eb4eb:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel list
2017-08-30 09:05:48.773 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2017-08-30 09:05:48.773 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2017-08-30 09:05:48.780 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2017-08-30 09:05:48.781 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08031A0C08ECFF99CD0510...631A0D0A0B4765744368616E6E656C73
2017-08-30 09:05:48.781 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: 9E3B54A97D9693D23124F3C783555888ECE29B93C503B61C2CD5BDF0A9A83C93
2017-08-30 09:05:48.796 UTC [channelCmd] list -> INFO 006 Channels peers has joined to:
2017-08-30 09:05:48.796 UTC [channelCmd] list -> INFO 007 mychannel2
2017-08-30 09:05:48.796 UTC [main] main -> INFO 008 Exiting.....
```