简介
此项目是一个模拟公民身份信息链的区块链项目
github 地址: https://github.com/akkagao/citizens
使用fabric-go-sdk 搭建的一个测试环境。能完成sdk安装、初始化、调用、查询chainCode的所有功能
模拟业务场景:
1:模拟政府管理全国公民身份信息。
2:由FBI 代劳录入信息,也可以查询用户信息
解决问题
1: 各个政府部门之间信息不同步,导致公民在政府办理各种事物需要提供各种证明。比如买房要提供无犯罪证明、单身证明、本地无房产证明,社保、公积金、等等一堆证明……...
2:业务代办理证明你妈是你妈(不知道这个梗可以搜索“你妈是你妈”)。这只有生活在我天朝上国的人才能体验到的尊贵服务。
3:小孩出生录入指纹、DNA、虹膜等生物识别信息。如果小孩走失,长大后只要根据自己生物识别信息就可以找到自己的亲身父母。
启动体验
# 创建目录
mkdir$GOPATH/src/github.com/akkagao/
# 进入目录
cd$GOPATH/src/github.com/akkagao/
# 下载项目
gitclone git@github.com:akkagao/citizens.git
# 在fabric-service目录下执行
cdfabric-service
# 启动fabric服务,所有日志都会输出到 all.log 中
./start.sh
# 然后进入web-service 目录
cdweb-service
# 使用 go run main.go命令启动gosdk项目 执行链码的安装、初始化、执行、查询等操作
go run main.go
部署流程
1. 安装软件环境
此项目在macPro环境下部署
安装git
安装golang
安装docker
安装docker-compose
以上软件安装自行google吧,教程很多。
2. 编译工具
把fabric源码下载到 $GOPATH/src/github.com/hyperledger 目录下
git clone git@github.com:hyperledger/fabric.git
切换到1.1版本(本项目使用fabirc1.1作为演示)
git checkout -b release-1.1 origin/release-1.1
生成工具包
在fabric目录$GOPATH/src/github.com/hyperledger/fabric目录下执行
make configtxgen
make cryptogen
在build/bin目录下生成 configtxgen cryptogen 文件
把上面编译好的文件放到本项目 fabric-service/bin 目录下
➜ fabric-service git:(master) ✗ tree -lbin
bin
├── configtxgen
└── cryptogen
编写配置文件
约定
本项目暂定1个组织FBI,组织有2个节点,2个用户
根域名使用 citizens.com
crypto-config.yaml 文件
使用下面命令生成 文件模版
./bin/cryptogen showtemplate > crypto-config.yaml
根据实际定义修改内容,最终结果为
OrdererOrgs:
- Name: Orderer
Domain: citizens.com
Specs:
- Hostname: orderer
PeerOrgs:
- Name: FBI
Domain: fbi.citizens.com
EnableNodeOUs: false
Template:
Count: 2
Users:
Count: 2
在fabric-service目录下生成证书目录
➜ fabric-service git:(master) ✗ ./bin/cryptogen generate --config=crypto-config.yaml
fbi.citizens.com
configtx.yaml 文件
从fabric配置文件例子中获取模版
➜ fabric-service git:(master) ✗
cp$GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/configtx.yaml ./
修改后的内容
---
Profiles:
CitizensGenesis:
Capabilities:
<<: *ChannelCapabilities
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Consortiums:
SampleConsortium:
Organizations:
- *FBI
CitizensChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *FBI
Capabilities:
<<: *ApplicationCapabilities
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: crypto-config/ordererOrganizations/citizens.com/msp
- &FBI
Name: FBIMSP
ID: FBIMSP
MSPDir: crypto-config/peerOrganizations/fbi.citizens.com/msp
AnchorPeers:
- Host: peer0.fbi.citizens.com
Port: 7051
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.citizens.com:7050
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 98 MB
PreferredMaxBytes: 512 KB
Organizations:
Application: &ApplicationDefaults
Organizations:
Capabilities:
Global: &ChannelCapabilities
V1_1: true
Orderer: &OrdererCapabilities
V1_1: true
Application: &ApplicationCapabilities
V1_1: true
生成order创世区块锚节点配置文件
mkdirartifacts
//生成order创世区块
./bin/configtxgen --profileCitizensGenesis -outputBlock./artifacts/orderer.genesis.block
// 生成channel初始块
./bin/configtxgen --profileCitizensChannel -outputCreateChannelTx./artifacts/citizens.tx -channelIDcitizens
//创建锚节点更新文件
./bin/configtxgen --profileCitizensChannel -outputAnchorPeersUpdate./artifacts/FBImspanchors.tx -channelIDcitizens -asOrgFBIMSP
生成channel初始块
channel 名字为 citizens
命令:
./bin/configtxgen --profileCitizensChain -outputCreateChannelTx./artifacts/citizens.tx -channelIDcitizens
---------------------------------执行结果----------------------------------------------
➜ fabric-service git:(master) ✗ ./bin/configtxgen --profileCitizensChain -outputCreateChannelTx./artifacts/citizens.tx -channelIDcitizens
2018-08-1116:06:07.685 CST [common/tools/configtxgen] main -> INFO 001Loading configuration
2018-08-1116:06:07.691 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 002Generating new channel configtx
2018-08-1116:06:07.712 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 003Writing new channel tx
以上命令执行完毕后查看生成的结果,如果以下文件都生成成功说明以上操作都没有问题
fabric-service git:(master) ✗ tree -lartifacts
artifacts
├── appleorgmspanchors.tx
├── citizens.tx
├── fbiorgmspanchors.tx
└── orderer.genesis.block
docker-compose.yaml 文件
复制模版文件
基于go模版文件修改
cp$GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/dockerenv/docker-compose.yaml ./
cp$GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/dockerenv/.env ./
修改后的结果
version: '2'
services:
orderer:
image: ${FABRIC_DOCKER_REGISTRY}${FABRIC_ORDERER_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_ORDERER_FIXTURE_TAG}
environment:
- ORDERER_GENERAL_LOGLEVEL=info
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/etc/hyperledger/tls/orderer/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/etc/hyperledger/tls/orderer/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/etc/hyperledger/tls/orderer/ca.crt]
- ORDERER_GENERAL_TLS_CLIENTAUTHENABLED
- ORDERER_GENERAL_TLS_CLIENTROOTCAS
#comment out logging.driver in order to render the debug logs
# logging:
# driver: none
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
command: orderer
ports:
- 7050:7050
volumes:
- ./artifacts:/etc/hyperledger/configtx
- ./crypto-config/ordererOrganizations/citizens.com/orderers/orderer.citizens.com/msp:/etc/hyperledger/msp/orderer
- ./crypto-config/ordererOrganizations/citizens.com/orderers/orderer.citizens.com/tls:/etc/hyperledger/tls/orderer
- ./crypto-config/peerOrganizations/fbi.citizens.com/tlsca:/etc/hyperledger/tlsca
networks:
default:
aliases:
- orderer.citizens.com
FBIpeer1:
image: ${FABRIC_DOCKER_REGISTRY}${FABRIC_PEER_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_PEER_FIXTURE_TAG}
environment:
- CORE_VM_ENDPOINT
- CORE_PEER_ID=peer0.fbi.citizens.com
- CORE_LOGGING_PEER=info
# - CORE_LOGGING_GRPC=debug
# - CORE_LOGGING_GOSSIP=debug
# - CORE_CHAINCODE_STARTUPTIMEOUT=30s
- CORE_CHAINCODE_LOGGING_SHIM=debug
- CORE_CHAINCODE_LOGGING_LEVEL=debug
- CORE_CHAINCODE_BUILDER=${FABRIC_DOCKER_REGISTRY}${FABRIC_BUILDER_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_BUILDER_FIXTURE_TAG}
- CORE_CHAINCODE_GOLANG_RUNTIME=${FABRIC_BASE_DOCKER_REGISTRY}${FABRIC_BASEOS_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_BASEOS_FIXTURE_TAG}
- CORE_CHAINCODE_EXECUTETIMEOUT=120s
- CORE_VM_DOCKER_ATTACHSTDOUT=false
- CORE_PEER_LOCALMSPID=FBIMSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_GOSSIP_BOOTSTRAP=127.0.0.1:7051
- CORE_PEER_ADDRESS=peer0.fbi.citizens.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.fbi.citizens.com:7051
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/tls/peer/server.key
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/tls/peer/server.crt
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/tls/peer/ca.crt
- CORE_PEER_TLS_CLIENTAUTHREQUIRED
- CORE_PEER_TLS_CLIENTROOTCAS_FILES
# # the following setting starts chaincode containers on the same
# # bridge network as the peers
# # https://docs.docker.com/compose/networking/
- CORE_PEER_NETWORKID=${CORE_PEER_NETWORKID}
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${CORE_PEER_NETWORKID}_default
#comment out logging.driver in order to render the debug logs
# logging:
# driver: none
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start
ports:
- "7051:7051"
expose:
- "7051"
- "7052"
volumes:
- /var/run/:/var/run/
- ./crypto-config/peerOrganizations/fbi.citizens.com/peers/peer0.fbi.citizens.com/msp:/etc/hyperledger/msp/peer
- ./crypto-config/peerOrganizations/fbi.citizens.com/peers/peer0.fbi.citizens.com/tls:/etc/hyperledger/tls/peer
- ./crypto-config/peerOrganizations/fbi.citizens.com/tlsca:/etc/hyperledger/orgs/fbi.citizens.com/tlsca
networks:
default:
aliases:
- peer0.fbi.citizens.com
depends_on:
- orderer
FBIpeer2:
image: ${FABRIC_DOCKER_REGISTRY}${FABRIC_PEER_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_PEER_FIXTURE_TAG}
environment:
- CORE_VM_ENDPOINT
- CORE_PEER_ID=peer1.fbi.citizens.com
- CORE_LOGGING_PEER=info
# - CORE_LOGGING_GRPC=debug
# - CORE_LOGGING_GOSSIP=debug
# - CORE_CHAINCODE_STARTUPTIMEOUT=30s
- CORE_CHAINCODE_LOGGING_SHIM=debug
- CORE_CHAINCODE_LOGGING_LEVEL=debug
- CORE_CHAINCODE_BUILDER=${FABRIC_DOCKER_REGISTRY}${FABRIC_BUILDER_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_BUILDER_FIXTURE_TAG}
- CORE_CHAINCODE_GOLANG_RUNTIME=${FABRIC_BASE_DOCKER_REGISTRY}${FABRIC_BASEOS_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_BASEOS_FIXTURE_TAG}
- CORE_CHAINCODE_EXECUTETIMEOUT=120s
- CORE_VM_DOCKER_ATTACHSTDOUT=false
- CORE_PEER_LOCALMSPID=FBIMSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer
- CORE_PEER_LISTENADDRESS=0.0.0.0:7151
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7152
- CORE_PEER_ADDRESS=peer1.fbi.citizens.com:7151
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.fbi.citizens.com:7151
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.fbi.citizens.com:7051
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/tls/peer/server.key
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/tls/peer/server.crt
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/tls/peer/ca.crt
- CORE_PEER_TLS_CLIENTAUTHREQUIRED
- CORE_PEER_TLS_CLIENTROOTCAS_FILES
# # the following setting starts chaincode containers on the same
# # bridge network as the peers
# # https://docs.docker.com/compose/networking/
- CORE_PEER_NETWORKID=${CORE_PEER_NETWORKID}
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${CORE_PEER_NETWORKID}_default
#comment out logging.driver in order to render the debug logs
# logging:
# driver: none
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start
ports:
- "7151:7151"
expose:
- "7151"
- "7152"
volumes:
- /var/run/:/var/run/
- ./crypto-config/peerOrganizations/fbi.citizens.com/peers/peer1.fbi.citizens.com/msp:/etc/hyperledger/msp/peer
- ./crypto-config/peerOrganizations/fbi.citizens.com/peers/peer1.fbi.citizens.com/tls:/etc/hyperledger/tls/peer
- ./crypto-config/peerOrganizations/fbi.citizens.com/tlsca:/etc/hyperledger/orgs/fbi.citizens.com/tlsca
networks:
default:
aliases:
- peer1.fbi.citizens.com
depends_on:
- orderer
networks:
default:
修改hosts 把以下内容加入/etc/hosts文件
127.0.0.1 peer0.fbi.citizens.com
127.0.0.1 peer1.fbi.citizens.com
127.0.0.1 apple.citizens.com
127.0.0.1 fbi.citizens.com
127.0.0.1 orderer.citizens.com
127.0.0.1 citizens.com
编写config.yaml 文件
进入web-service目录
cp $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/config/config_e2e.yaml ./config.yaml
修改后的结果
version: 1.0.0
client:
organization: FBI
logging:
level: info
cryptoconfig:
path: ${GOPATH}/src/github.com/akkagao/citizens/fabric-service/crypto-config
credentialStore:
path: "/tmp/state-store"
cryptoStore:
path: /tmp/msp
BCCSP:
security:
enabled: true
default:
provider: "SW"
hashAlgorithm: "SHA2"
softVerify: true
level: 256
tlsCerts:
# [Optional]. Use system certificate pool when connecting to peers, orderers (for negotiating TLS) Default: false
systemCertPool: false
# [Optional]. Client key and cert for TLS handshake with peers and orderers
client:
key:
path:
cert:
path:
channels:
citizens:
peers:
peer0.fbi.citizens.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
organizations:
FBI:
mspid: FBIMSP
# This org's MSP store (absolute path or relative to client.cryptoconfig)
cryptoPath: peerOrganizations/fbi.citizens.com/users/{username}@fbi.citizens.com/msp
peers:
- peer0.fbi.citizens.com
- peer1.fbi.citizens.com
certificateAuthorities:
- ca.fbi.citizens.com
#
orderers:
orderer.citizens.com:
url: localhost:7050
# these are standard properties defined by the gRPC library
# they will be passed in as-is to gRPC client constructor
grpcOptions:
ssl-target-name-override: orderer.citizens.com
# These parameters should be set in coordination with the keepalive policy on the server,
# as incompatible settings can result in closing of connection.
# When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled
keep-alive-time: 0s
keep-alive-timeout: 20s
keep-alive-permit: false
fail-fast: false
# allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs
allow-insecure: false
tlsCACerts:
# Certificate location absolute path
path: ${GOPATH}/src/github.com/akkagao/citizens/fabric-service/crypto-config/ordererOrganizations/citizens.com/tlsca/tlsca.citizens.com-cert.pem
#
# List of peers to send various requests to, including endorsement, query
# and event listener registration.
#
peers:
peer0.fbi.citizens.com:
# this URL is used to send endorsement and query requests
url: peer0.fbi.citizens.com:7051
grpcOptions:
ssl-target-name-override: peer0.fbi.citizens.com
# These parameters should be set in coordination with the keepalive policy on the server,
# as incompatible settings can result in closing of connection.
# When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled
keep-alive-time: 0s
keep-alive-timeout: 20s
keep-alive-permit: false
fail-fast: false
# allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs
allow-insecure: false
tlsCACerts:
# Certificate location absolute path
path: ${GOPATH}/src/github.com/akkagao/citizens/fabric-service/crypto-config/peerOrganizations/fbi.citizens.com/tlsca/tlsca.fbi.citizens.com-cert.pem
peer1.fbi.citizens.com:
# this URL is used to send endorsement and query requests
url: peer1.fbi.citizens.com:7151
grpcOptions:
ssl-target-name-override: peer1.fbi.citizens.com
# These parameters should be set in coordination with the keepalive policy on the server,
# as incompatible settings can result in closing of connection.
# When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled
keep-alive-time: 0s
keep-alive-timeout: 20s
keep-alive-permit: false
fail-fast: false
# allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs
allow-insecure: false
tlsCACerts:
# Certificate location absolute path
path: ${GOPATH}/src/github.com/akkagao/citizens/fabric-service/crypto-config/peerOrganizations/fbi.citizens.com/tlsca/tlsca.fbi.citizens.com-cert.pem
certificateAuthorities:
ca.fbi.citizens.com:
url: https://ca.fbi.citizens.com:7054
tlsCACerts:
# Comma-Separated list of paths
path: ${GOPATH}/src/github.com/akkagao/citizens/fabric-service/crypto-config/peerOrganizations/fbi.citizens.com/tlsca/tlsca.fbi.citizens.com-cert.pem
# Client key and cert for SSL handshake with Fabric CA
client:
key:
path: ${GOPATH}/src/github.com/akkagao/citizens/fabric-service/crypto-config/peerOrganizations/fbi.citizens.com/users/User1@fbi.citizens.com/tls/client.key
cert:
path: ${GOPATH}/src/github.com/akkagao/citizens/fabric-service/crypto-config/peerOrganizations/fbi.citizens.com/users/User1@fbi.citizens.com/tls/client.crt
# Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is
# needed to enroll and invoke new users.
registrar:
enrollId: admin
enrollSecret: adminpw
# [Optional] The optional name of the CA.
caName: ca.fbi.citizens.com
以上就是所有配置的基本流程,也可以参考fabric-service目录下的bulid.sh脚本内容
然后编写chainCode 和 调用链码的代码就可以测试了,具体参考chainCode和web-service目录中的go代码
启动体验
在fabric-service目录下执行
./start.sh 启动fabric服务,所有日志都会输出到 all.log 中
然后进入web-service 目录
使用 go run main.go命令启动gosdk项目 执行链码的安装、初始化、执行、查询等操作
以下是配置调试过程中遇到的一些错误处理方法
清理docker 网络
➜ fabric-service git:(master) ✗ docker network ls
NETWORK ID NAME DRIVER SCOPE
c1f91c6c5086 bridge bridge local
aced91a76322 host host local
57502ba90162 none null local
➜ fabric-service git:(master) ✗ docker rm57502ba90162
使用start脚本启动
脚本会清理之前操作残留的docker 以免对当前开发环境产生影响
如果没有报错说明启动成功,然后docker ps查看所有定义的容器是否都存在
生成channel初始块 报错
➜ fabric-service git:(master) ✗ ./bin/configtxgen --profileCitizensChain -outputCreateChannelTx./artifacts/citizens.tx -channelIDcitizens
2018-08-1116:02:53.269 CST [common/tools/configtxgen] main -> INFO 001Loading configuration
2018-08-1116:02:53.276 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 002Generating new channel configtx
2018-08-1116:02:53.277 CST [common/tools/configtxgen] main -> CRIT 003Error on outputChannelCreateTx: config update generation failure: cannot define a new channel with no Application section
➜ fabric-service git:(master) ✗
问题原因 configtx.yaml 文件中
# Profiles 节点下缺少一下内容
Application:
<<: *ApplicationDefaults
Organizations:
- *FBIOrg
Consortium: SampleConsortium
启动docker 报错
问题原因 docker-compose.yaml 文件 每个peer下面的CORE_PEER_LOCALMSPID 值必须正确
CORE_PEER_LOCALMSPID=FBIOrg
peer1.apple.citizens.com | 2018-08-1109:46:45.454 UTC [gossip/comm] authenticateRemotePeer -> WARN 1be Identity store rejected 192.168.0.4:7051 : failed classifying identity: Unable to extract msp.Identity from peer Identity: Peer Identity [0a 084170706c 654f 7267129e 062d 2d 2d 2d 2d 424547494e 2043455254494649434154452d 2d 2d 2d 2d 0a 4d 494943487a 43434163576741774942416749514d 763845324b 6761426261445a 617159616877327844414b 42676771686b 6a 4f 50515144416a 42334d 5173770a 435159445651514745774a 56557a 45544d 4245474131554543424d 4b 5132467361575a 76636d 3570595445574d 4251474131554542784d 4e 5532467549455a 790a 5957356a 61584e 6a 627a 45624d 426b 474131554543684d 53595842776247557559326c 306158706c 626e 4d 75593239744d 52347748415944565151444578566a 0a 59533568634842735a 53356a 61585270656d 56756379356a 623230774868634e 4d 5467774f 4445784d 4455304e 4455785768634e 4d 6a 67774f 4441344d 4455300a 4e 445578576a 42644d 517377435159445651514745774a 56557a 45544d 4245474131554543424d 4b 5132467361575a 76636d 3570595445574d 425147413155450a 42784d 4e 5532467549455a 795957356a 61584e 6a 627a 45684d 4238474131554541784d 596347566c 636a 4175595842776247557559326c 306158706c 626e 4d 750a 593239744d 466b 77457759484b 6f 5a 497a 6a 3043415159494b 6f 5a 497a 6a 30444151634451674145397a 327970374c 366b 33583776624367706a 415a 44766d 570a 444649614b 70334d 3639726761714438516c 752b 3368314f 716c 32594c 71786b 626a 4d 667678525a 74734f 657157774147426c 66435a 78506c 58517a 76714e 4e 0a 4d 45737744675944565230504151482f 42415144416765414d 41774741315564457745422f 7751434d 4141774b 7759445652306a 42435177496f 4167357059310a 5336456f 73307570487341446475776d 45754c 5158614172646b 424f 6568774844384b 4e 496d 3477436759494b 6f 5a 497a 6a 30454177494453414177525149680a 4149714b 726164332f 746147384a 653638597a 38497853375449366f 622f 37553661726d 4e 48526e 474b 704f 4169424d 34327073484a 6a 5673414d 67346353430a 36393847514661737448567068736e 6f 66384a 44564c 536756773d 3d 0a 2d 2d 2d 2d 2d 454e 442043455254494649434154452d 2d 2d 2d 2d 0a] cannot be validated. No MSP found able to dothat.
peer1.apple.citizens.com | 2018-08-1109:46:45.454 UTC [gossip/comm] Handshake -> WARN 1bf Authentication failed: failed classifying identity: Unable to extract msp.Identity from peer Identity: Peer Identity [0a 084170706c 654f 7267129e 062d 2d 2d 2d 2d 424547494e 2043455254494649434154452d 2d 2d 2d 2d 0a 4d 494943487a 43434163576741774942416749514d 763845324b 6761426261445a 617159616877327844414b 42676771686b 6a 4f 50515144416a 42334d 5173770a 435159445651514745774a 56557a 45544d 4245474131554543424d 4b 5132467361575a 76636d 3570595445574d 4251474131554542784d 4e 5532467549455a 790a 5957356a 61584e 6a 627a 45624d 426b 474131554543684d 53595842776247557559326c 306158706c 626e 4d 75593239744d 52347748415944565151444578566a 0a 59533568634842735a 53356a 61585270656d 56756379356a 623230774868634e 4d 5467774f 4445784d 4455304e 4455785768634e 4d 6a 67774f 4441344d 4455300a 4e 445578576a 42644d 517377435159445651514745774a 56557a 45544d 4245474131554543424d 4b 5132467361575a 76636d 3570595445574d 425147413155450a 42784d 4e 5532467549455a 795957356a 61584e 6a 627a 45684d 4238474131554541784d 596347566c 636a 4175595842776247557559326c 306158706c 626e 4d 750a 593239744d 466b 77457759484b 6f 5a 497a 6a 3043415159494b 6f 5a 497a 6a 30444151634451674145397a 327970374c 366b 33583776624367706a 415a 44766d 570a 444649614b 70334d 3639726761714438516c 752b 3368314f 716c 32594c 71786b 626a 4d 667678525a 74734f 657157774147426c 66435a 78506c 58517a 76714e 4e 0a 4d 45737744675944565230504151482f 42415144416765414d 41774741315564457745422f 7751434d 4141774b 7759445652306a 42435177496f 4167357059310a 5336456f 73307570487341446475776d 45754c 5158614172646b 424f 6568774844384b 4e 496d 3477436759494b 6f 5a 497a 6a 30454177494453414177525149680a 4149714b 726164332f 746147384a 653638597a 38497853375449366f 622f 37553661726d 4e 48526e 474b 704f 4169424d 34327073484a 6a 5673414d 67346353430a 36393847514661737448567068736e 6f 66384a 44564c 536756773d 3d 0a 2d 2d 2d 2d 2d 454e 442043455254494649434154452d 2d 2d 2d 2d 0a] cannot be validated. No MSP found able to dothat.
peer1.apple.citizens.com | 2018-08-1109:46:45.454 UTC [gossip/discovery] func1 -> WARN 1c0 Could not connect to {peer0.apple.citizens.com:7051 [] [] peer0.apple.citizens.com:7051 } : failed classifying identity: Unable to extract msp.Identity from peer Identity: Peer Identity [0a 084170706c 654f 7267129e 062d 2d 2d 2d 2d 424547494e 2043455254494649434154452d 2d 2d 2d 2d 0a 4d 494943487a 43434163576741774942416749514d 763845324b 6761426261445a 617159616877327844414b 42676771686b 6a 4f 50515144416a 42334d 5173770a 435159445651514745774a 56557a 45544d 4245474131554543424d 4b 5132467361575a 76636d 3570595445574d 4251474131554542784d 4e 5532467549455a 790a 5957356a 61584e 6a 627a 45624d 426b 474131554543684d 53595842776247557559326c 306158706c 626e 4d 75593239744d 52347748415944565151444578566a 0a 59533568634842735a 53356a 61585270656d 56756379356a 623230774868634e 4d 5467774f 4445784d 4455304e 4455785768634e 4d 6a 67774f 4441344d 4455300a 4e 445578576a 42644d 517377435159445651514745774a 56557a 45544d 4245474131554543424d 4b 5132467361575a 76636d 3570595445574d 425147413155450a 42784d 4e 5532467549455a 795957356a 61584e 6a 627a 45684d 4238474131554541784d 596347566c 636a 4175595842776247557559326c 306158706c 626e 4d 750a 593239744d 466b 77457759484b 6f 5a 497a 6a 3043415159494b 6f 5a 497a 6a 30444151634451674145397a 327970374c 366b 33583776624367706a 415a 44766d 570a 444649614b 70334d 3639726761714438516c 752b 3368314f 716c 32594c 71786b 626a 4d 667678525a 74734f 657157774147426c 66435a 78506c 58517a 76714e 4e 0a 4d 45737744675944565230504151482f 42415144416765414d 41774741315564457745422f 7751434d 4141774b 7759445652306a 42435177496f 4167357059310a 5336456f 73307570487341446475776d 45754c 5158614172646b 424f 6568774844384b 4e 496d 3477436759494b 6f 5a 497a 6a 30454177494453414177525149680a 4149714b 726164332f 746147384a 653638597a 38497853375449366f 622f 37553661726d 4e 48526e 474b 704f 4169424d 34327073484a 6a 5673414d 67346353430a 36393847514661737448567068736e 6f 66384a 44564c 536756773d 3d 0a 2d 2d 2d 2d 2d 454e 442043455254494649434154452d 2d 2d 2d 2d 0a] cannot be validated. No MSP found able to dothat.
3: orderer 启动失败(发现一下日志)
orderer.genesis.block
实际创世区块名称和docker-compose-base 文件中的配置不一致导致
- ../artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../artifacts/orderer.genesis.block:/var/hyperledger/orderer/orderer.genesis.block
orderer.ebbyte.com | panic: Unable to bootstrap orderer. Error reading genesis block file: read /var/hyperledger/orderer/orderer.genesis.block: is a directory
orderer.ebbyte.com |
orderer.ebbyte.com | goroutine 1[running]:
orderer.ebbyte.com | github.com/hyperledger/fabric/orderer/common/bootstrap/file.(*fileBootstrapper).GenesisBlock(0xc42013c430, 0xc42013c430)
orderer.ebbyte.com | /opt/gopath/src/github.com/hyperledger/fabric/orderer/common/bootstrap/file/bootstrap.go:44 +0x1e4
orderer.ebbyte.com | github.com/hyperledger/fabric/orderer/common/server.initializeBootstrapChannel(0xc4202a2a00, 0x1393300, 0xc420164000)
orderer.ebbyte.com | /opt/gopath/src/github.com/hyperledger/fabric/orderer/common/server/main.go:205 +0x5bd
orderer.ebbyte.com | github.com/hyperledger/fabric/orderer/common/server.initializeMultichannelRegistrar(0xc4202a2a00, 0x138fd80, 0x13f3e20, 0xc42013e798, 0x1, 0x1, 0xc420371e60)
orderer.ebbyte.com | /opt/gopath/src/github.com/hyperledger/fabric/orderer/common/server/main.go:253 +0xa0
orderer.ebbyte.com | github.com/hyperledger/fabric/orderer/common/server.Start(0xcfa0bc, 0x5, 0xc4202a2a00)
orderer.ebbyte.com | /opt/gopath/src/github.com/hyperledger/fabric/orderer/common/server/main.go:103 +0x24c
orderer.ebbyte.com | github.com/hyperledger/fabric/orderer/common/server.Main()
orderer.ebbyte.com | /opt/gopath/src/github.com/hyperledger/fabric/orderer/common/server/main.go:82 +0x20f
orderer.ebbyte.com | main.main()
orderer.ebbyte.com | /opt/gopath/src/github.com/hyperledger/fabric/orderer/main.go:15 +0x20
peer1.akka.ebbyte.com | 2018-08-2013:52:37.557 UTC [accessControl] newCertKeyPair -> DEBU 028Classified peer1.akka.ebbyte.com as a hostname, adding it as a DNS SAN
4: ca启动失败
FABRIC_CA_SERVER_TLS_KEYFILE 配置没有修改完全 _sk 文件没有替换完
ca_peerakka | Error: Failed to findprivate key forcertificate in'/etc/hyperledger/fabric-ca-server-config/ca.akka.ebbyte.com-cert.pem': Could not findmatching private key forSKI: Failed
getting key forSKI [[40 2186255133181113229155112163181942131351693621197215195341182251422410501982241220]]: Key with SKI 2802baff85b571e59b70a3b55ed587a924d361d7c32276e10e
e06900c6e00c14 not found in/etc/hyperledger/fabric-ca-server/msp/keystore
5: go build 报错
fabric-sdk-go 版本不对 切换成 v1.0.0-alpha4 版本
../../../hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/orderer/configuration.pb.go:56:35: undefined: proto.InternalMessageInfo
6: go启动失败
OrgName 必须和configtx.yaml文件中的 Organizations定义的peer节点名称一致
Unable to initialize the Fabric SDK: failed to create channel management client from Admin identity: failed to create resmgmt client due to context error: invalid options to create identity, invalid org name
7: go 启动失败
config.yaml 修改为(url 值),修改后需要重启docker
orderers:
orderer.ebbyte.com:
url: 127.0.0.1:7050
报错信息:
Unable to initialize the Fabric SDK: failed to save channel: create channel failed: SendEnvelope failed: calling orderer 'orderer.ebbyte.com:7050'failed: Orderer Server Status Code: (400) BAD_REQUEST. Description: error authorizing update: error validating ReadSet: readset expected key [Group] /Channel/Application at version 0, but got version 1
8:go启动失败
config.yaml 文件中8151 端口写错了应该是8050
go程序中所有写了 resmgmt.WithTargetEndpoints("peer0.akka.ebbyte.com")) 的地方确认域名是否是 org pee0的域名
Unable to initialize the Fabric SDK: failed to save channel: create channel failed: SendEnvelope failed: calling orderer '127.0.0.1:7050'failed: Orderer Server Status Code: (400) BAD_REQUEST. Description: error authorizing update: error validating ReadSet: readset expected key [Group] /Channel/Application at version 0, but got version 1
Unable to initialize the Fabric SDK: failed to makeadmin join channel: join channel failed: SendProposal failed: Transaction processing forendorser [peer1.akka.ebbyte.com:8151]: Endorser Client Status Code: (2) CONNECTION_FAILED. Description: dialing connection timed out [peer1.akka.ebbyte.com:8151]
9 实例化ChainCode失败
docker网络问题
[fabsdk/fab] 2018/08/21 13:33:34 UTC -peer.(*peerEndorser).sendProposal -> ERRO process proposal failed [rpc error: code =Unknown desc =error starting container: API error (404): {"message":"network e2ecli_default not found"}
]
Unable to install and instantiate the chaincode: failed to instantiate the chaincode: sending deploy transaction proposal failed: Transaction processing forendorser [127.0.0.1:7051]: gRPC Transport Status Code: (2) Unknown. Description: error starting container: API error (404): {"message":"network e2ecli_default not found"}
重新生成证书
docker images 查看所有的iamge 如果有 network-peer0-org-domain 这样的容器用docker rmi 删除一次
确认chaincode 代码所在目录名称为chaincode 并且代码package 为main go build 是否可以直接编译出二进制文件
[fabsdk/fab] 2018/08/21 13:46:12 UTC -peer.(*peerEndorser).sendProposal -> ERRO process proposal failed [rpc error: code =Unknown desc =error starting container: API error (400): {"message":"OCI runtime create failed: container_linux.go:348: starting container process caused \"exec: \\\"chaincode\\\": executable file not found in $PATH\": unknown"}
]
Unable to install and instantiate the chaincode: failed to instantiate the chaincode: sending deploy transaction proposal failed: Transaction processing forendorser [127.0.0.1:7051]: gRPC Transport Status Code: (2) Unknown. Description: error starting container: API error (400): {"message":"OCI runtime create failed: container_linux.go:348: starting container process caused \"exec: \\\"chaincode\\\": executable file not found in $PATH\": unknown"}
go:启动失败channel Name 不能有大写字母
Unable to initialize the Fabric SDK: failed to save channel: create channel failed: SendEnvelope failed: calling orderer 'localhost:7050' failed: Orderer Server Status Code: (400) BAD_REQUEST. Description: initializing configtx manager failed: bad channel ID: channel ID 'GoldChainChannel' contains illegal characters
有疑问加站长微信联系(非本文作者)