Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
LOCAL_VERSION=1.2.0
DOCKER_IMAGE_VERSION=1.2.0
/root/gowork/src/fabric-samples/first-network/../bin/cryptogen
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x
读取相应的版本内容,通过cryptogen
读取crypto-config.yaml
文件的配置,生成证书相关的内容。
/root/gowork/src/fabric-samples/first-network/../bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
+ configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
2018-08-06 10:33:08.419 CST [common/tools/configtxgen] main -> WARN 001 Omitting the channel ID for configtxgen is deprecated. Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'.
2018-08-06 10:33:08.419 CST [common/tools/configtxgen] main -> INFO 002 Loading configuration
2018-08-06 10:33:08.428 CST [common/tools/configtxgen/encoder] NewChannelGroup -> WARN 003 Default policy emission is deprecated, please include policy specificiations for the channel group in configtx.yaml
2018-08-06 10:33:08.428 CST [common/tools/configtxgen/encoder] NewOrdererGroup -> WARN 004 Default policy emission is deprecated, please include policy specificiations for the orderer group in configtx.yaml
2018-08-06 10:33:08.428 CST [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 005 Default policy emission is deprecated, please include policy specificiations for the orderer org group OrdererOrg in configtx.yaml
2018-08-06 10:33:08.429 CST [msp] getMspConfig -> INFO 006 Loading NodeOUs
2018-08-06 10:33:08.429 CST [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 007 Default policy emission is deprecated, please include policy specificiations for the orderer org group Org1MSP in configtx.yaml
2018-08-06 10:33:08.429 CST [msp] getMspConfig -> INFO 008 Loading NodeOUs
2018-08-06 10:33:08.429 CST [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 009 Default policy emission is deprecated, please include policy specificiations for the orderer org group Org2MSP in configtx.yaml
2018-08-06 10:33:08.429 CST [common/tools/configtxgen] doOutputBlock -> INFO 00a Generating genesis block
2018-08-06 10:33:08.429 CST [common/tools/configtxgen] doOutputBlock -> INFO 00b Writing genesis block
+ res=0
+ set +x
#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2018-08-06 10:33:08.465 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-08-06 10:33:08.472 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2018-08-06 10:33:08.472 CST [common/tools/configtxgen/encoder] NewApplicationGroup -> WARN 003 Default policy emission is deprecated, please include policy specificiations for the application group in configtx.yaml
2018-08-06 10:33:08.472 CST [msp] getMspConfig -> INFO 004 Loading NodeOUs
2018-08-06 10:33:08.473 CST [common/tools/configtxgen/encoder] NewApplicationOrgGroup -> WARN 005 Default policy emission is deprecated, please include policy specificiations for the application org group Org1MSP in configtx.yaml
2018-08-06 10:33:08.473 CST [msp] getMspConfig -> INFO 006 Loading NodeOUs
2018-08-06 10:33:08.473 CST [common/tools/configtxgen/encoder] NewApplicationOrgGroup -> WARN 007 Default policy emission is deprecated, please include policy specificiations for the application org group Org2MSP in configtx.yaml
2018-08-06 10:33:08.474 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 008 Writing new channel tx
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2018-08-06 10:33:08.508 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-08-06 10:33:08.514 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-08-06 10:33:08.515 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2018-08-06 10:33:08.549 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-08-06 10:33:08.555 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-08-06 10:33:08.555 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
+ res=0
+ set +x
通过configtxgen
工具来读取configtx.yaml
文件的配置:
orderer service
生成genesis.block
channel
相关的transaction
文件channel.tx
。Org1MSP
的anchor peer
Org2MSP
的anchor peer
channel
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
Build your first network (BYFN) end-to-end test
Channel name : mychannel
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --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
+ res=0
+ set +x
2018-08-06 02:33:11.058 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-08-06 02:33:11.079 UTC [cli/common] readBlock -> INFO 002 Got status: &{NOT_FOUND}
2018-08-06 02:33:11.083 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-08-06 02:33:11.285 UTC [cli/common] readBlock -> INFO 004 Received block: 0
===================== Channel 'mychannel' created =====================
根据配置的channel
名字,创建channel。创建channel的时候,需要指定orderer
地址、channel.tx
文件的位置、是否启用tls
以及orderer
证书的位置。
创建
channel
的命令:
peer channel create -o orderer的地址及端口号 -c channel名字 -f ./channel-artifacts/channel.tx --tls true --cafile orderer证书的位置
peer
加入channel
Having all peers join the channel...
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2018-08-06 02:33:11.351 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-08-06 02:33:11.389 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel 'mychannel' =====================
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2018-08-06 02:33:14.455 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-08-06 02:33:14.484 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel 'mychannel' =====================
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2018-08-06 02:33:17.551 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-08-06 02:33:17.579 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel 'mychannel' =====================
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2018-08-06 02:33:20.650 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-08-06 02:33:20.677 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org2 joined channel 'mychannel' =====================
命令:
peer channel join -b mychannel.block
anchor peer
Updating anchor peers for org1...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --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
+ res=0
+ set +x
2018-08-06 02:33:23.741 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-08-06 02:33:23.753 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' =====================
Updating anchor peers for org2...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --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
+ res=0
+ set +x
2018-08-06 02:33:26.819 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-08-06 02:33:26.830 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' =====================
更新anchor
节点时需要指定orderer
地址、channel
名字、Org1MSPanchors.tx
、tls
以及orderer cafile
。
命令:
peer channel update -o orderer的地址及端口号 -c channel名字 -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile
orderer证书的位置
Installing chaincode on peer0.org1...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2018-08-06 02:33:29.903 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-08-06 02:33:29.903 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2018-08-06 02:33:30.053 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:
===================== Chaincode is installed on peer0.org1 =====================
Install chaincode on peer0.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2018-08-06 02:33:30.119 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-08-06 02:33:30.119 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2018-08-06 02:33:30.269 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:
===================== Chaincode is installed on peer0.org2 =====================
安装chaincode时可以指定:
这里安装chaincode时需要安装到你指定的anchor peer
上。在安装过程中,系统链码会对你的chaincode
进行校验escc
、vscc
命令:
+ peer chaincode install -n chaincode的名字 -v chaincode的版本 -l 编写chaincode的语言 -p chaincode在cli容器中的路径
chaincode
Instantiating chaincode on peer0.org2...
+ peer chaincode instantiate -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 -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
+ res=0
+ set +x
2018-08-06 02:33:30.341 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-08-06 02:33:30.342 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' =====================
实例化chaincode
时,需要指定:
tls
。true/false
在实例化链码的时候,系统的escc
和vscc
链码会对你的链码进行验证。
命令:
peer chaincode instantiate -o 排序节点的地址 --tls 是否启用tls --cafile 排序节点的证书地址 -C 通道名称 -n 链码名称 -l 链码使用的语言 -v 链码的版本 -c 初始化时传入的参数 -P 背书策略
Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
100
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
查询链码时需要指定:
peer chaincode query -C 通道名字 -n 链码名字 -c 参数
Sending invoke transaction on peer0.org1 peer0.org2...
+ peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2018-08-06 02:34:01.345 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
调用链码时需要指定:
true/false
非必填命令:
peer chaincode invoke -o orderer节点的地址 --tls 是否启用 --cafile orderer节点的证书 -C 通道名称 -n 链码名称 --peerAddresses peer节点的地址 --tlsRootCertFiles peer节点对应的tls证书地址 -c 参数
在启动first-network
网络的过程中我们可以总结为以下几个过程
channel
peer channel create -o orderer的地址及端口号 -c channel名字 -f ./channel-artifacts/channel.tx --tls true --cafile orderer证书的位置
peer channel join -b 通道名称.block
anchor peer
peer channel update -o orderer的地址及端口号 -c channel名字 -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile
orderer证书的位置
peer chaincode install -n chaincode的名字 -v chaincode的版本 -l 编写chaincode的语言 -p chaincode在cli容器中的路径
peer chaincode instantiate -o 排序节点的地址 --tls 是否启用tls --cafile 排序节点的证书地址 -C 通道名称 -n 链码名称 -l 链码使用的语言 -v 链码的版本 -c 初始化时传入的参数 -P 背书策略
peer chaincode query -C 通道名字 -n 链码名字 -c 参数
peer chaincode invoke -o orderer节点的地址 --tls 是否启用 --cafile orderer节点的证书 -C 通道名称 -n 链码名称 --peerAddresses peer节点的地址 --tlsRootCertFiles peer节点对应的tls证书地址 -c 参数
作者:沙漠中的猴
链接:https://www.jianshu.com/p/817f7f3b2734
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。