2. 创建Channel
参考:创建一个新的channel
创建通道:
运行下面的程序来为coreandfirstchannel
通道创建一个“创建通道的交易”
1 configtxgen -profile CoreAndFirstChannel -outputCreateChannelTx ./channel-artifacts/coreandfirstchannel.tx -channelID coreandfirstchannel
执行结果如下:
1 2 3 4 2020-12-24 14:29:40.728 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2020-12-24 14:29:40.739 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /Users/apple/code/open-source/blockchain/hyperledger/supply-finance/configtx/configtx.yaml 2020-12-24 14:29:40.739 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx 2020-12-24 14:29:40.750 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
设置环境变量,以核心企业(core.supply.com )管理员身份操作peer
CLI;然后使用下面的命令把交易发给order服务创建通道:
1 peer channel create -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c coreandfirstchannel -f ./channel-artifacts/coreandfirstchannel.tx --outputBlock ./channel-artifacts/coreandfirstchannel.block --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
正确执行之后的日志:
1 2 3 4 5 6 7 8 9 10 11 12 2020-12-24 15:59:28.470 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 2020-12-24 15:59:28.490 CST [cli.common] readBlock -> INFO 002 Expect block, but got status: &{NOT_FOUND} 2020-12-24 15:59:28.497 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-12-24 15:59:28.701 CST [cli.common] readBlock -> INFO 004 Expect block, but got status: &{SERVICE_UNAVAILABLE} 2020-12-24 15:59:28.708 CST [channelCmd] InitCmdFactory -> INFO 005 Endorser and orderer connections initialized 2020-12-24 15:59:28.917 CST [cli.common] readBlock -> INFO 006 Expect block, but got status: &{SERVICE_UNAVAILABLE} 2020-12-24 15:59:28.924 CST [channelCmd] InitCmdFactory -> INFO 007 Endorser and orderer connections initialized 2020-12-24 15:59:29.134 CST [cli.common] readBlock -> INFO 008 Expect block, but got status: &{SERVICE_UNAVAILABLE} 2020-12-24 15:59:29.141 CST [channelCmd] InitCmdFactory -> INFO 009 Endorser and orderer connections initialized 2020-12-24 15:59:29.349 CST [cli.common] readBlock -> INFO 00a Expect block, but got status: &{SERVICE_UNAVAILABLE} 2020-12-24 15:59:29.357 CST [channelCmd] InitCmdFactory -> INFO 00b Endorser and orderer connections initialized 2020-12-24 15:59:29.566 CST [cli.common] readBlock -> INFO 00c Received block: 0
报错信息记录:
1 2 3 4 5 (base) apple@WHOAMIdeMacBook-Pro:~/code/open-source/blockchain/hyperledger/supply-finance$ peer channel create -o localhost:8051 --ordererTLSHostnameOverride orderer.supply.com -c coreandfirstchannel -f ./channel-artifacts/coreandfirstchannel.tx --outputBlock ./channel-artifacts/coreandfirstchannel.block --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem 2020-12-24 15:56:56.602 CST [comm.tls] ClientHandshake -> ERRO 001 Client TLS handshake failed after 5.225381ms with error: x509: certificate is valid for peer0.core.supply.com, peer0, not orderer.supply.com remoteaddress=[::1]:8051 2020-12-24 15:56:57.611 CST [comm.tls] ClientHandshake -> ERRO 002 Client TLS handshake failed after 3.907471ms with error: x509: certificate is valid for peer0.core.supply.com, peer0, not orderer.supply.com remoteaddress=[::1]:8051 2020-12-24 15:56:59.315 CST [comm.tls] ClientHandshake -> ERRO 003 Client TLS handshake failed after 4.52302ms with error: x509: certificate is valid for peer0.core.supply.com, peer0, not orderer.supply.com remoteaddress=[::1]:8051 Error: failed to create deliver client for orderer: orderer client failed to connect to localhost:8051: failed to create new connection: context deadline exceeded
错误原因: peer channel create -o localhost:8051
命令-o
应该传入order服务的地址和端口。
把核心企业和一级供应商的peer加入通道
核心企业的peer加入通道
使用下面的命令将核心企业的peer加入通道(确认已经设置了核心企业的环境变量):
1 peer channel join -b ./channel-artifacts/coreandfirstchannel.block
成功信息如下:
1 2 2020-12-24 16:46:40.206 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 2020-12-24 16:46:40.235 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
报错信息记录:
1 2 3 4 5 (base) apple@WHOAMIdeMacBook-Pro:~/code/open-source/blockchain/hyperledger/supply-finance$ peer channel join -b ./channel-artifacts/coreandfirstchannel.block 2020-12-24 16:18:23.258 CST [comm.tls] ClientHandshake -> ERRO 001 Client TLS handshake failed after 2.895228ms with error: x509: certificate is valid for peer0.core.supply.com, peer0, not localhost remoteaddress=[::1]:8051 2020-12-24 16:18:24.266 CST [comm.tls] ClientHandshake -> ERRO 002 Client TLS handshake failed after 4.537447ms with error: x509: certificate is valid for peer0.core.supply.com, peer0, not localhost remoteaddress=[::1]:8051 2020-12-24 16:18:25.659 CST [comm.tls] ClientHandshake -> ERRO 003 Client TLS handshake failed after 4.16728ms with error: x509: certificate is valid for peer0.core.supply.com, peer0, not localhost remoteaddress=[::1]:8051 Error: error getting endorser client for channel: endorser client failed to connect to localhost:8051: failed to create new connection: context deadline exceeded
**错误原因:**未知。
**解决方式:**把Profiles里面的Organizations信息统一修改,与环境变量保持一致
1 2 3 4 5 6 Organizations: - *GylCoreOrg1MSP - *GylFOrg1MSP - *GylSOrg1MSP - *GylSOrg2MSP
然后把上面步骤中生成的加密材料信息、区块信息都删除,容器和volume全部删除;重新执行一遍。
通过获取通道信息确认加入成功
获取通道信息
1 peer channel getinfo -c coreandfirstchannel
可以看到如下信息:
1 2 2020-12-24 16:53:01.633 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized Blockchain info: {"height":1,"currentBlockHash":"kXOOwW8prt0XPvgEGMDrzdt1nNH8T7qlObL9eT8FZ7c="}
一级供应商加入通道
设置环境变量,然后拉取通道的创世纪区块(因为是测试本次忽略):
1 peer channel fetch 0 ./channel-artifacts/coreandfirstchannel.block -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c coreandfirstchannel --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
加入通道:
1 peer channel join -b ./channel-artifacts/coreandfirstchannel.block
成功信息如下:
1 2 2020-12-24 17:06:30.499 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 2020-12-24 17:06:30.527 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
报错信息如下:
1 2 (base) apple@WHOAMIdeMacBook-Pro:~/code/open-source/blockchain/hyperledger/supply-finance$ peer channel join -b ./channel-artifacts/coreandfirstchannel.block 2020-12-24 17:01:05.904 CST [main] InitCmd -> ERRO 001 Cannot run peer because cannot init crypto, specified path "/Users/apple/code/open-source/blockchain/hyperledger/supply-finance/organizations/peerOrganizations/f1.supply.com/users/Admin@f1.supply.com/msp/organizations/peerOrganizations/f1.supply.com/users/Admin@f1.supply.com/msp" does not exist or cannot be accessed: stat /Users/apple/code/open-source/blockchain/hyperledger/supply-finance/organizations/peerOrganizations/f1.supply.com/users/Admin@f1.supply.com/msp/organizations/peerOrganizations/f1.supply.com/users/Admin@f1.supply.com/msp: no such file or directory
**错误原因:**因为在设置环境变量时不是在supply-finance
目录下设置的,所以设置的环境变量有问题,重新设置一下。
设置锚节点
为GylFOrg1MSP设置锚节点
因为上面已经设置了一级供应商(GylFOrg1MSP)的环境变量,所以先设置GylFOrg1MSP的锚节点:
拉取最新的channel配置区块
1 peer channel fetch config channel-artifacts/coreandfirstchannel_config_block.pb -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c coreandfirstchannel --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
成功信息如下:
1 2 3 4 2020-12-24 17:56:48.435 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 2020-12-24 17:56:48.439 CST [cli.common] readBlock -> INFO 002 Received block: 0 2020-12-24 17:56:48.439 CST [channelCmd] fetch -> INFO 003 Retrieving last config block: 0 2020-12-24 17:56:48.442 CST [cli.common] readBlock -> INFO 004 Received block: 0
修改通道配置区块
切换到channel-artifacts
然后把区块内容转换成json格式:
1 2 3 4 5 cd channel-artifacts configtxlator proto_decode --input coreandfirstchannel_config_block.pb --type common.Block --output coreandfirstchannel_config_block.json jq .data.data[0].payload.data.config coreandfirstchannel_config_block.json > coreandfirstchannel_config.json # copy一份 cp coreandfirstchannel_config.json coreandfirstchannel_config_copy.json
使用jq
工具来添加GylFOrg1MSP组织的锚节点到通道配置。
1 jq '.channel_group.groups.Application.groups.GylFOrg1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.f1.supply.com","port": 8053}]},"version": "0"}}' coreandfirstchannel_config_copy.json > modified_coreandfirstchannel_config.json
将原始的和修改后的通道配置都转换回protobuf格式,并计算它们之间的差异。
1 2 3 configtxlator proto_encode --input coreandfirstchannel_config.json --type common.Config --output coreandfirstchannel_config.pb configtxlator proto_encode --input modified_coreandfirstchannel_config.json --type common.Config --output modified_coreandfirstchannel_config.pb configtxlator compute_update --channel_id coreandfirstchannel --original coreandfirstchannel_config.pb --updated modified_coreandfirstchannel_config.pb --output coreandfirstchannel_config_update.pb
把更新后的交易打包成一个更新通道配置的交易:
1 2 3 configtxlator proto_decode --input coreandfirstchannel_config_update.pb --type common.ConfigUpdate --output coreandfirstchannel_config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"coreandfirstchannel", "type":2}},"data":{"config_update":'$(cat coreandfirstchannel_config_update.json)'}}}' | jq . > coreandfirstchannel_config_update_in_envelope.json configtxlator proto_encode --input coreandfirstchannel_config_update_in_envelope.json --type common.Envelope --output coreandfirstchannel_config_update_in_envelope.pb
提交“更新通道配置的交易”
进到上一级目录cd ..
,之后运行命令将交易提交给排序服务进行通道配置的更新:
1 2 cd .. peer channel update -f channel-artifacts/coreandfirstchannel_config_update_in_envelope.pb -c coreandfirstchannel -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
执行成功的结果:
1 2 2020-12-24 18:13:59.246 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 2020-12-24 18:13:59.265 CST [channelCmd] update -> INFO 002 Successfully submitted channel update
错误信息记录:
1 2 2020-12-24 18:12:49.469 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized Error: got unexpected status: BAD_REQUEST -- error applying config update to existing channel 'coreandfirstchannel': error authorizing update: ConfigUpdate for channel 'channel1' but envelope for channel 'coreandfirstchannel'
**错误原因:**在修改配置的时候指定channel名称错误,修正重新执行一遍。
验证,获取通道信息:peer channel getinfo -c coreandfirstchannel
1 2 3 supply-finance$ peer channel getinfo -c coreandfirstchannel 2020-12-24 18:19:31.275 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized Blockchain info: {"height":2,"currentBlockHash":"h5CY6RfVNNg8kYWPZ+tZqdMIrGoXeoDSQFd0YfiBhRk=","previousBlockHash":"kXOOwW8prt0XPvgEGMDrzdt1nNH8T7qlObL9eT8FZ7c="}
为核心企业GylCoreOrg1MSP设置锚节点
修改环境变量,然后拉取最新的channel配置区块
1 peer channel fetch config channel-artifacts/coreandfirstchannel_config_block.pb -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c coreandfirstchannel --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
修改通道配置区块
切换到channel-artifacts
然后把区块内容转换成json格式:
1 2 3 4 5 cd channel-artifacts configtxlator proto_decode --input coreandfirstchannel_config_block.pb --type common.Block --output coreandfirstchannel_config_block.json jq .data.data[0].payload.data.config coreandfirstchannel_config_block.json > coreandfirstchannel_config.json # copy一份 cp coreandfirstchannel_config.json coreandfirstchannel_config_copy.json
使用jq
工具来添加GylCoreOrg1MSP组织的锚节点到通道配置。
1 jq '.channel_group.groups.Application.groups.GylCoreOrg1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.core.supply.com","port": 8051}]},"version": "0"}}' coreandfirstchannel_config_copy.json > modified_coreandfirstchannel_config.json
将原始的和修改后的通道配置都转换回protobuf格式,并计算它们之间的差异。
1 2 3 configtxlator proto_encode --input coreandfirstchannel_config.json --type common.Config --output coreandfirstchannel_config.pb configtxlator proto_encode --input modified_coreandfirstchannel_config.json --type common.Config --output modified_coreandfirstchannel_config.pb configtxlator compute_update --channel_id coreandfirstchannel --original coreandfirstchannel_config.pb --updated modified_coreandfirstchannel_config.pb --output coreandfirstchannel_config_update.pb
把更新后的交易打包成一个更新通道配置的交易:
1 2 3 configtxlator proto_decode --input coreandfirstchannel_config_update.pb --type common.ConfigUpdate --output coreandfirstchannel_config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"coreandfirstchannel", "type":2}},"data":{"config_update":'$(cat coreandfirstchannel_config_update.json)'}}}' | jq . > coreandfirstchannel_config_update_in_envelope.json configtxlator proto_encode --input coreandfirstchannel_config_update_in_envelope.json --type common.Envelope --output coreandfirstchannel_config_update_in_envelope.pb
提交“更新通道配置的交易”
进到上一级目录cd ..
,之后运行命令将交易提交给排序服务进行通道配置的更新:
1 2 cd .. peer channel update -f channel-artifacts/coreandfirstchannel_config_update_in_envelope.pb -c coreandfirstchannel -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
执行成功的结果:
1 2 2020-12-24 18:13:59.246 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 2020-12-24 18:13:59.265 CST [channelCmd] update -> INFO 002 Successfully submitted channel update
验证,获取通道信息
1 2 3 $ peer channel getinfo -c coreandfirstchannel 2020-12-24 18:24:51.015 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized Blockchain info: {"height":3,"currentBlockHash":"e52oT2HAiTxyeh4a30kTx32xLJAKIWa7rm6PVOn8eoA=","previousBlockHash":"h5CY6RfVNNg8kYWPZ+tZqdMIrGoXeoDSQFd0YfiBhRk="}
部署测试chaincode来确认
打包
1 peer lifecycle chaincode package basic.tar.gz --path /Users/apple/code/open-source/blockchain/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go/ --lang golang --label basic_1.0
运行完上面的命令,查看当前目录会发现多了basic.tar.gz
包,说明打包成功。
安装链码包
一级供应商和核心企业都要安装:
核心企业:
1 peer lifecycle chaincode install basic.tar.gz --peerAddresses localhost:8051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/core.supply.com/peers/peer0.core.supply.com/tls/ca.crt
一级供应商:
1 peer lifecycle chaincode install basic.tar.gz --peerAddresses localhost:8053 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/f1.supply.com/peers/peer0.f1.supply.com/tls/ca.crt
安装成功输出结果如下:
1 2 2020-12-24 18:51:45.793 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nJbasic_1.0:4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad\022\tbasic_1.0" > 2020-12-24 18:51:45.793 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad
批准链码定义
查看已经安装的chaincode
1 peer lifecycle chaincode queryinstalled
成功结果如下:
1 2 Installed chaincodes on peer: Package ID: basic_1.0:4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad, Label: basic_1.0
将链码的信息保存为一个变量
1 export CC_PACKAGE_ID=basic_1.0:4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad
批准链码定义
核心企业和一级供应商都需要执行此命令:
1 peer lifecycle chaincode approveformyorg -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --channelID coreandfirstchannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
成功结果如下:
1 2020-12-24 19:02:47.351 CST [chaincodeCmd] ClientWait -> INFO 001 txid [d7e2224f63a1516ffeeed26ec5c8f69872141f5864b3602a1409679472692840] committed with status (VALID) at localhost:8051
将链码定义提交到通道
检查channel上的成员是否已经批准了链码定义:
1 peer lifecycle chaincode checkcommitreadiness --channelID coreandfirstchannel --name basic --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem --output json
成功结果如下:
1 2 3 4 5 6 { "approvals" : { "GylCoreOrg1MSP" : true , "GylFOrg1MSP" : true } }
在两个组织都批准之后,执行下面的命令将链码定义提交到通道:
1 peer lifecycle chaincode commit -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --channelID coreandfirstchannel --name basic --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem --peerAddresses localhost:8051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/core.supply.com/peers/peer0.core.supply.com/tls/ca.crt --peerAddresses localhost:8053 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/f1.supply.com/peers/peer0.f1.supply.com/tls/ca.crt
成功结果如下:
1 2 2020-12-24 19:10:18.071 CST [chaincodeCmd] ClientWait -> INFO 001 txid [5b363e2e419dbb1307726fe44428e23ae1b0e5feaf86cb577383b6e8a68464d6] committed with status (VALID) at localhost:8053 2020-12-24 19:10:18.094 CST [chaincodeCmd] ClientWait -> INFO 002 txid [5b363e2e419dbb1307726fe44428e23ae1b0e5feaf86cb577383b6e8a68464d6] committed with status (VALID) at localhost:8051
使用 peer lifecycle chaincode querycommitted 命令来确认链码定义已经提交到通道。
1 peer lifecycle chaincode querycommitted --channelID coreandfirstchannel --name basic --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
成功结果如下:
1 2 Committed chaincode definition for chaincode 'basic' on channel 'coreandfirstchannel': Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [GylCoreOrg1MSP: true, GylFOrg1MSP: true]
调用链码
1 peer chaincode invoke -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem -C coreandfirstchannel -n basic --peerAddresses localhost:8051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/core.supply.com/peers/peer0.core.supply.com/tls/ca.crt --peerAddresses localhost:8053 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/f1.supply.com/peers/peer0.f1.supply.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'
成功信息:
1 2020-12-25 17:26:22.583 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
查询调用后的结果
1 peer chaincode query -C coreandfirstchannel -n basic -c '{"Args":["GetAllAssets"]}'
成功结果如下,说明channel部署成功:
1 [{"ID":"asset1","color":"blue","size":5,"owner":"Tomoko","appraisedValue":300},{"ID":"asset2","color":"red","size":5,"owner":"Brad","appraisedValue":400},{"ID":"asset3","color":"green","size":10,"owner":"Jin Soo","appraisedValue":500},{"ID":"asset4","color":"yellow","size":10,"owner":"Max","appraisedValue":600},{"ID":"asset5","color":"black","size":15,"owner":"Adriana","appraisedValue":700},{"ID":"asset6","color":"white","size":15,"owner":"Michel","appraisedValue":800}]
错误信息如下:
1 Error: endorsement failure during invoke. response: status:500 message:"error in simulation: failed to execute transaction 207cf99d289ffe9deca6a320aba59cc155fae02d19d51c9cfebc9943ffc7794d: could not launch chaincode basic_1.0:4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad: error starting container: error starting container: API error (404): network _test not found"
**错误原因:**因为chaincode的容器没有启动成功,直接指定容器启动报错如下:
1 2 3 /supply-finance$ docker start bc47970e58a5 Error response from daemon: network _test not found Error: failed to start containers: bc47970e58a5
问题解决:
因为在docker-compose.yml
文件中配置了下面的环境变量,在启动chaincode容器时会链接到这个网络。
之前的配置是:
1 - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_test
修改后重新启动,问题解决。
1 - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_test
为什么修改成docker_test呢,可以查看使用docker-compose
命令启动容器时的日志:
1 Creating network "docker_test" with the default driver
核心企业、一级和二级供应商加入同一个channel
创建通道:
运行下面的程序来为alljoinchannel
通道创建一个“创建通道的交易”
1 2 3 configtxgen -profile AllPlayChannel -outputCreateChannelTx ./channel-artifacts/alljoinchannel.tx -channelID alljoinchannel # 使用下面的命令把交易发给order服务创建通道: peer channel create -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c alljoinchannel -f ./channel-artifacts/alljoinchannel.tx --outputBlock ./channel-artifacts/alljoinchannel.block --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem
加入通道
使用下面的命令将peer加入通道,所有节点都需要执行:
1 2 3 peer channel join -b ./channel-artifacts/alljoinchannel.block # 通过获取通道信息确认加入成功 peer channel getinfo -c alljoinchannel
为各个组织设置锚节点
GylCoreOrg1MSP
1 2 3 4 5 6 7 8 peer channel fetch config channel-artifacts/alljoinchannel_config_block.pb -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c alljoinchannel --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 切换到`channel-artifacts`然后把区块内容转换成json格式: cd channel-artifacts configtxlator proto_decode --input alljoinchannel_config_block.pb --type common.Block --output alljoinchannel_config_block.json jq .data.data[0].payload.data.config alljoinchannel_config_block.json > alljoinchannel_config.json cp alljoinchannel_config.json alljoinchannel_config_copy.json # 使用`jq`工具添加各个组织的锚节点配置 jq '.channel_group.groups.Application.groups.GylCoreOrg1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.core.supply.com","port": 8051}]},"version": "0"}}' alljoinchannel_config_copy.json > modified_alljoinchannel_config.json
1 2 3 4 5 6 7 8 # 将原始的和修改后的通道配置都转换回protobuf格式,并计算它们之间的差异。 configtxlator proto_encode --input alljoinchannel_config.json --type common.Config --output alljoinchannel_config.pb configtxlator proto_encode --input modified_alljoinchannel_config.json --type common.Config --output modified_alljoinchannel_config.pb configtxlator compute_update --channel_id alljoinchannel --original alljoinchannel_config.pb --updated modified_alljoinchannel_config.pb --output alljoinchannel_config_update.pb # 把更新后的交易打包成一个更新通道配置的交易: configtxlator proto_decode --input alljoinchannel_config_update.pb --type common.ConfigUpdate --output alljoinchannel_config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"alljoinchannel", "type":2}},"data":{"config_update":'$(cat alljoinchannel_config_update.json)'}}}' | jq . > alljoinchannel_config_update_in_envelope.json configtxlator proto_encode --input alljoinchannel_config_update_in_envelope.json --type common.Envelope --output alljoinchannel_config_update_in_envelope.pb
1 2 3 4 5 # 进到上一级目录`cd ..`,之后运行命令将交易提交给排序服务进行通道配置的更新: cd .. peer channel update -f channel-artifacts/alljoinchannel_config_update_in_envelope.pb -c alljoinchannel -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 验证,获取通道信息: peer channel getinfo -c alljoinchannel
GylFOrg1MSP
1 2 3 4 5 6 7 8 peer channel fetch config channel-artifacts/alljoinchannel_config_block.pb -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c alljoinchannel --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 切换到`channel-artifacts`然后把区块内容转换成json格式: cd channel-artifacts configtxlator proto_decode --input alljoinchannel_config_block.pb --type common.Block --output alljoinchannel_config_block.json jq .data.data[0].payload.data.config alljoinchannel_config_block.json > alljoinchannel_config.json cp alljoinchannel_config.json alljoinchannel_config_copy.json # 使用`jq`工具添加各个组织的锚节点配置 jq '.channel_group.groups.Application.groups.GylFOrg1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.f1.supply.com","port": 8053}]},"version": "0"}}' alljoinchannel_config_copy.json > modified_alljoinchannel_config.json
1 2 3 4 5 6 7 8 # 将原始的和修改后的通道配置都转换回protobuf格式,并计算它们之间的差异。 configtxlator proto_encode --input alljoinchannel_config.json --type common.Config --output alljoinchannel_config.pb configtxlator proto_encode --input modified_alljoinchannel_config.json --type common.Config --output modified_alljoinchannel_config.pb configtxlator compute_update --channel_id alljoinchannel --original alljoinchannel_config.pb --updated modified_alljoinchannel_config.pb --output alljoinchannel_config_update.pb # 把更新后的交易打包成一个更新通道配置的交易: configtxlator proto_decode --input alljoinchannel_config_update.pb --type common.ConfigUpdate --output alljoinchannel_config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"alljoinchannel", "type":2}},"data":{"config_update":'$(cat alljoinchannel_config_update.json)'}}}' | jq . > alljoinchannel_config_update_in_envelope.json configtxlator proto_encode --input alljoinchannel_config_update_in_envelope.json --type common.Envelope --output alljoinchannel_config_update_in_envelope.pb
1 2 3 4 5 # 进到上一级目录`cd ..`,之后运行命令将交易提交给排序服务进行通道配置的更新: cd .. peer channel update -f channel-artifacts/alljoinchannel_config_update_in_envelope.pb -c alljoinchannel -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 验证,获取通道信息: peer channel getinfo -c alljoinchannel
GylSOrg1MSP
1 2 3 4 5 6 7 8 peer channel fetch config channel-artifacts/alljoinchannel_config_block.pb -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c alljoinchannel --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 切换到`channel-artifacts`然后把区块内容转换成json格式: cd channel-artifacts configtxlator proto_decode --input alljoinchannel_config_block.pb --type common.Block --output alljoinchannel_config_block.json jq .data.data[0].payload.data.config alljoinchannel_config_block.json > alljoinchannel_config.json cp alljoinchannel_config.json alljoinchannel_config_copy.json # 使用`jq`工具添加各个组织的锚节点配置 jq '.channel_group.groups.Application.groups.GylSOrg1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.s1.supply.com","port": 8055}]},"version": "0"}}' alljoinchannel_config_copy.json > modified_alljoinchannel_config.json
1 2 3 4 5 6 7 8 # 将原始的和修改后的通道配置都转换回protobuf格式,并计算它们之间的差异。 configtxlator proto_encode --input alljoinchannel_config.json --type common.Config --output alljoinchannel_config.pb configtxlator proto_encode --input modified_alljoinchannel_config.json --type common.Config --output modified_alljoinchannel_config.pb configtxlator compute_update --channel_id alljoinchannel --original alljoinchannel_config.pb --updated modified_alljoinchannel_config.pb --output alljoinchannel_config_update.pb # 把更新后的交易打包成一个更新通道配置的交易: configtxlator proto_decode --input alljoinchannel_config_update.pb --type common.ConfigUpdate --output alljoinchannel_config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"alljoinchannel", "type":2}},"data":{"config_update":'$(cat alljoinchannel_config_update.json)'}}}' | jq . > alljoinchannel_config_update_in_envelope.json configtxlator proto_encode --input alljoinchannel_config_update_in_envelope.json --type common.Envelope --output alljoinchannel_config_update_in_envelope.pb
1 2 3 4 5 # 进到上一级目录`cd ..`,之后运行命令将交易提交给排序服务进行通道配置的更新: cd .. peer channel update -f channel-artifacts/alljoinchannel_config_update_in_envelope.pb -c alljoinchannel -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 验证,获取通道信息: peer channel getinfo -c alljoinchannel
GylSOrg1MSP
1 2 3 4 5 6 7 8 peer channel fetch config channel-artifacts/alljoinchannel_config_block.pb -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com -c alljoinchannel --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 切换到`channel-artifacts`然后把区块内容转换成json格式: cd channel-artifacts configtxlator proto_decode --input alljoinchannel_config_block.pb --type common.Block --output alljoinchannel_config_block.json jq .data.data[0].payload.data.config alljoinchannel_config_block.json > alljoinchannel_config.json cp alljoinchannel_config.json alljoinchannel_config_copy.json # 使用`jq`工具添加各个组织的锚节点配置 jq '.channel_group.groups.Application.groups.GylSOrg2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.s2.supply.com","port": 8151}]},"version": "0"}}' alljoinchannel_config_copy.json > modified_alljoinchannel_config.json
1 2 3 4 5 6 7 8 # 将原始的和修改后的通道配置都转换回protobuf格式,并计算它们之间的差异。 configtxlator proto_encode --input alljoinchannel_config.json --type common.Config --output alljoinchannel_config.pb configtxlator proto_encode --input modified_alljoinchannel_config.json --type common.Config --output modified_alljoinchannel_config.pb configtxlator compute_update --channel_id alljoinchannel --original alljoinchannel_config.pb --updated modified_alljoinchannel_config.pb --output alljoinchannel_config_update.pb # 把更新后的交易打包成一个更新通道配置的交易: configtxlator proto_decode --input alljoinchannel_config_update.pb --type common.ConfigUpdate --output alljoinchannel_config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"alljoinchannel", "type":2}},"data":{"config_update":'$(cat alljoinchannel_config_update.json)'}}}' | jq . > alljoinchannel_config_update_in_envelope.json configtxlator proto_encode --input alljoinchannel_config_update_in_envelope.json --type common.Envelope --output alljoinchannel_config_update_in_envelope.pb
1 2 3 4 5 # 进到上一级目录`cd ..`,之后运行命令将交易提交给排序服务进行通道配置的更新: cd .. peer channel update -f channel-artifacts/alljoinchannel_config_update_in_envelope.pb -c alljoinchannel -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem # 验证,获取通道信息: peer channel getinfo -c alljoinchannel