搭建Hyperledger Fabric时遇到了很多问题,很多坑,这里汇总一下,有些可能没保存图片,还有些问题没及时记录起来:
1、生成orderer区块文件时,如下图所示:
必须要指定channelID修改命令如下即可:
configtxgen -profile TestTwoOrgsOrdererGenesis -channelID qkltestchannel -outputBlock ./order.genesis.block
2、创建orderer区块文件时,如下图所示:
原因:OrdererDefaults引用不到,百度了一下,参考文章:https://blog.csdn.net/damonren/article/details/90753164,说是configtx.yaml配置文件的Profiles部分要放到最后面才行,修改下configtx.yaml的内容即可。
3、创建orderer区块文件时,如下图所示:
原因:configtx.yaml文件缺少了策略配置,增加对应的policies即可,可参考fabric源码的test-network目录下的configtx.yaml,我的是在这个目录:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/configtx
4、创建orderer区块文件时,如下图所示:
原因:权限拒绝,因为要写入一个order.genesis.block文件,所以需要权限,输入命令:
sudo configtxgen -profile TestTwoOrgsOrdererGenesis -channelID qkltestchannel -outputBlock ./order.genesis.block
5、生成锚点更新文件时,即执行下面命令时:
sudo configtxgen -profile TestTwoOrgsChannel -outputAnchorPeersUpdate ./Org1MSPanchors.tx -channelID qkltestchannel -asOrg Org1MSP
sudo configtxgen -profile TestTwoOrgsChannel -outputAnchorPeersUpdate ./Org2MSPanchors.tx -channelID qkltestchannel -asOrg Org2MSP
如果出现Error on inspectChannelCreateTx:org 'Org1MSP' does not have any anchor peers这种报错的话,原因:configtx.yaml底下的Org1,即peer节点的配置少了下面的属性:
AnchorPeers:
- Host: peer0.org1.qkltest.com
Port: 7051
6、启动orderer节点时,即输入命令:orderer start时,如下图所示:
原因:权限问题,输入命令时,加个sudo orderer start即可
7、启动orderer节点时,如下图所示:
原因:configtx.yaml文件没配置capabilities的原因,因此我们重新改下configtx.yaml文件,增加了Capabilities,不过要重新生成对应的一些区块问题,通道配置文件,锚点更新文件
8、创建通道时,如下图所示:
原因:出现这种情况时,是因为找不到对应的配置文件,所以要切换到peer目录
9、创建通道时,如下图所示:
原因:连接不到orderer.qkltest.com:7050,可能网络配置问题,又或者orderer配置问题,又或者orderer没有启动
10、创建通道时,如下图所示:
原因:就是创建orderer区块文件时的channelID与创建通道配置文件channelID相同导致的
11、创建通道时,如下图所示:
原因:找不到对应的证书路径,可以加上--cafile指定orderer的证书路径,我的路径:/opt/hyperledger/fabricconfig/crypto-config/ordererOrganizations/qkltest.com/orderers/orderer.qkltest.com/msp/tlscacerts/tlsca.qkltest.com-cert.pem
又或者,没有设置相关的变量:
export set CORE_PEER_LOCALMSPID=Org1MSP
export set CORE_PEER_ADDRESS=peer0.org1.qkltest.com:7051
export set CORE_PEER_MSPCONFIGPATH=/opt/hyperledger/fabricconfig/crypto-config/peerOrganizations/org1.qkltest.com/users/[email protected]/msp
13、用docker-compose启动网络时,orderer节点启动失败,如下图所示:
原因:通常出现这种情况,就是证书路径配置错了,检查一下docker-compose-test-qkl.yaml路径,发现没有错呀,也可能是docker-compose-test-qkl.yaml文件底下orderer配置的路径下msp没有signcerts目录:
上面这种的解决就是再搭建Fabric第一步时配置出问题了,我是把一个orderer其中的属性Specs写成小写的specs,导致一些目录和证书缺少,没生成。需要重新修改crypto-config.yaml,再重新执行命令:
sudo cryptogen generate --config=crypto-config.yaml
14、用docker-compose启动网络时,如下图所示:
原因:网络延迟问题
15、在cli容器里,将当前节点加入应用通道时,报下图的错误:
原因:配置文件配置问题
增加下面几行即可:
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.qkltest.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/hyperledger/peer/peerOrganizations/org1.qkltest.com/peers/peer0.org1.qkltest.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/hyperledger/peer/peerOrganizations/org1.qkltest.com/peers/peer0.org1.qkltest.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/hyperledger/peer/peerOrganizations/org1.qkltest.com/peers/peer0.org1.qkltest.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/hyperledger/peer/peerOrganizations/org1.qkltest.com/users/[email protected]/msp
注意,别加错位置了
16、打包链码时,报Error: failed to normalize chaincode path: failed to determine module root: exec: "go": executable file not found in $PATH错误,如下图所示:
原因:因为sudo的原因会重置环境变量导致查找不到可执行的go程序
解决办法,输入命令:
sudo vim ~/.bash_rc
sudo vim ~/.profile
并依次加上下面这一行:
alias sudo='sudo env PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH'
接着使环境变量生效,输入命令:
source ~/.bash_rc
source ~/.profile
17、打包链码时,报错如下图所示:
Error: failed to normalize chaincode path: 'go list' failed with: go: github.com/hyperledger/[email protected]: Get "https://proxy.golang.org/github.com/hyperledger/fabric-contract-api-go/@v/v1.1.0.mod": dial tcp 108.177.125.141:443: connect: connection refused: exit status 1
解决办法,设置go代理,记得前面要加sudo:
sudo go env -w GO111MODULE=on
sudo go env -w GOPROXY=https://goproxy.cn,direct
18、切换到peer0.org2.qkltest.com环境变量,并批准链码时,报Error: timed out waiting for txid on all peers这个错误,如下图所示:
原因:配置文件问题,可能哪个地方写错了配置,我这边是因为configtx.yaml底下的策略配置出现了问题。
原来的配置:
Organizations:
- &OrdererOrg
Name: OrdererMSP
ID: OrdererMSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/ordererOrganizations/qkltest.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Writers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Admins:
Type: Signature
Rule: "OR('OrdererMSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('OrdererMSP.member')"
OrdererEndpoints:
- orderer.qkltest.com:7050
- &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/peerOrganizations/org1.qkltest.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
Writers:
Type: Signature
Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
Admins:
Type: Signature
Rule: "OR('Org1MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org1MSP.peer')"
AnchorPeers:
- Host: peer0.org1.qkltest.com
Port: 7051
- &Org2
Name: Org2MSP
ID: Org2MSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/peerOrganizations/org2.qkltest.com/msp
AdminPrincipal: Role.ADMIN
Policies:
Readers:
Type: Signature
Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
Writers:
Type: Signature
Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
Admins:
Type: Signature
Rule: "OR('Org2MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org2MSP.peer')"
AnchorPeers:
- Host: peer0.org2.qkltest.com
Port: 7051
修改后的配置:
Organizations:
# SampleOrg defines an MSP using the sampleconfig. It should never be used
# in production but may be used as a template for other definitions
- &OrdererOrg
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: OrdererOrg
# ID to load the MSP definition as
ID: OrdererMSP
# MSPDir is the filesystem path which contains the MSP configuration
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/ordererOrganizations/qkltest.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Writers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Admins:
Type: Signature
Rule: "OR('OrdererMSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('OrdererMSP.member')"
OrdererEndpoints:
- orderer.qkltest.com:7050
- &Org1
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org1MSP
# ID to load the MSP definition as
ID: Org1MSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/peerOrganizations/org1.qkltest.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
Rule: "OR('Org1MSP.member')"
Writers:
Type: Signature
Rule: "OR('Org1MSP.member')"
Admins:
Type: Signature
Rule: "OR('Org1MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org1MSP.member')"
OrdererEndpoints:
- orderer.qkltest.com:7050
AnchorPeers:
- Host: peer0.org1.qkltest.com
Port: 7051
- &Org2
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org2MSP
# ID to load the MSP definition as
ID: Org2MSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/peerOrganizations/org2.qkltest.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
Rule: "OR('Org2MSP.member')"
Writers:
Type: Signature
Rule: "OR('Org2MSP.member')"
Admins:
Type: Signature
Rule: "OR('Org2MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org2MSP.member')"
OrdererEndpoints:
- orderer.qkltest.com:7050
AnchorPeers:
- Host: peer0.org2.qkltest.com
Port: 7051
注:需修改后,重新生成区块文件,通道文件,锚点更新文件,重新启动网络,重新按顺序操作
19、查看peer日志时,输入命令:docker logs peer0.org1.qkltest.com、或者docker logs peer0.org2.qkltest.com时报以下的错误:
eer {"CN":"peer1.org2.qkltest.com","Issuer-CN":"ca.org2.qkltest.com","Issuer-L-ST-C":"[San Francisco]-[]-[US]","Issuer-OU":null,"L-ST-C":"[San Francisco]-[]-[US]","MSP":"Org2MSP","OU":null} isn't eligible for channel qkltestchannel : implicit policy evaluation failed - 0 sub-policies were satisfied, but this policy requires 1 of the 'Readers' sub-policies to be satisfied
ERRO 04c VSCC error: stateBasedValidator.Validate failed, err validation of endorsement policy for collection _implicit_org_Org2MSP chaincode _lifecycle in tx 2:0 failed: signature set did not satisfy policy
原因:也是configtx.yaml配置策略出现问题,需修改后,重新生成区块文件,通道文件,锚点更新文件,重新启动网络,重新按顺序操作
20、批准链码时,如下图所示:
原因:网络关闭了,docker清理了缓存,生成的链码镜像删除了,需要重新生成配置文件configtx.yaml指定的区块文件和通道文件,再重新开始。
可能还有很多问题,可以参考这篇文章:https://studygolang.com/articles/20611
我这边也会持续更新,有问题可以在下方提出,大家一起讨论学习,谢谢!