fabric-go-sdk 初體驗

簡介

此項目是一個模擬公民身份信息鏈的區(qū)塊鏈項目

github 地址: https://github.com/akkagao/citizens

使用fabric-go-sdk? 搭建的一個測試環(huán)境萄焦。能完成sdk安裝猴凹、初始化盐肃、調(diào)用帆竹、查詢chainCode的所有功能

模擬業(yè)務(wù)場景:

1:模擬政府管理全國公民身份信息。

2:由FBI 代勞錄入信息言缤,也可以查詢用戶信息

解決問題

1: 各個政府部門之間信息不同步薯蝎,導(dǎo)致公民在政府辦理各種事物需要提供各種證明。比如買房要提供無犯罪證明献雅、單身證明碉考、本地無房產(chǎn)證明,社保挺身、公積金侯谁、等等一堆證明……...

2:業(yè)務(wù)代辦理證明你媽是你媽(不知道這個梗可以搜索“你媽是你媽”)章钾。這只有生活在我天朝上國的人才能體驗到的尊貴服務(wù)墙贱。

3:小孩出生錄入指紋、DNA贱傀、虹膜等生物識別信息惨撇。如果小孩走失,長大后只要根據(jù)自己生物識別信息就可以找到自己的親身父母府寒。

啟動體驗

# 創(chuàng)建目錄

mkdir$GOPATH/src/github.com/akkagao/

# 進入目錄

cd$GOPATH/src/github.com/akkagao/

# 下載項目

gitclone?git@github.com:akkagao/citizens.git

# 在fabric-service目錄下執(zhí)行

cdfabric-service

# 啟動fabric服務(wù)魁衙,所有日志都會輸出到 all.log 中

./start.sh ?

# 然后進入web-service 目錄

cdweb-service

# 使用 go run main.go命令啟動gosdk項目 執(zhí)行鏈碼的安裝报腔、初始化、執(zhí)行剖淀、查詢等操作

go run main.go

部署流程

1. 安裝軟件環(huán)境

此項目在macPro環(huán)境下部署

安裝git

安裝golang

安裝docker

安裝docker-compose

以上軟件安裝自行g(shù)oogle吧榄笙,教程很多。

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目錄下執(zhí)行

make configtxgen

make cryptogen

在build/bin目錄下生成 configtxgen cryptogen 文件

把上面編譯好的文件放到本項目 fabric-service/bin 目錄下

? fabric-service?git:(master) ? tree?-lbin

bin

├── configtxgen

└── cryptogen

編寫配置文件

約定

本項目暫定1個組織FBI祷蝌,組織有2個節(jié)點茅撞,2個用戶

根域名使用 citizens.com

crypto-config.yaml 文件

使用下面命令生成 文件模版

./bin/cryptogen showtemplate > crypto-config.yaml

根據(jù)實際定義修改內(nèi)容,最終結(jié)果為

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 ./

修改后的內(nèi)容

---

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創(chuàng)世區(qū)塊錨節(jié)點配置文件

mkdirartifacts

//生成order創(chuàng)世區(qū)塊

./bin/configtxgen?--profileCitizensGenesis?-outputBlock./artifacts/orderer.genesis.block

// 生成channel初始塊

./bin/configtxgen?--profileCitizensChannel?-outputCreateChannelTx./artifacts/citizens.tx?-channelIDcitizens

//創(chuàng)建錨節(jié)點更新文件

./bin/configtxgen?--profileCitizensChannel?-outputAnchorPeersUpdate./artifacts/FBImspanchors.tx?-channelIDcitizens?-asOrgFBIMSP

生成channel初始塊

channel 名字為 citizens

命令:

./bin/configtxgen?--profileCitizensChain?-outputCreateChannelTx./artifacts/citizens.tx?-channelIDcitizens

---------------------------------執(zhí)行結(jié)果----------------------------------------------

? 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

以上命令執(zhí)行完畢后查看生成的結(jié)果,如果以下文件都生成成功說明以上操作都沒有問題

fabric-service?git:(master) ? tree?-lartifacts

artifacts

├── appleorgmspanchors.tx

├── citizens.tx

├── fbiorgmspanchors.tx

└── orderer.genesis.block

docker-compose.yaml 文件

復(fù)制模版文件

基于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 ./

修改后的結(jié)果

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 把以下內(nèi)容加入/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

修改后的結(jié)果

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腳本內(nèi)容

然后編寫chainCode 和 調(diào)用鏈碼的代碼就可以測試了巨朦,具體參考chainCode和web-service目錄中的go代碼

啟動體驗

在fabric-service目錄下執(zhí)行

./start.sh? 啟動fabric服務(wù)米丘,所有日志都會輸出到 all.log 中

然后進入web-service 目錄

使用? go run main.go命令啟動gosdk項目 執(zhí)行鏈碼的安裝、初始化糊啡、執(zhí)行拄查、查詢等操作

以下是配置調(diào)試過程中遇到的一些錯誤處理方法

清理docker 網(wǎng)絡(luò)

? 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 以免對當前開發(fā)環(huán)境產(chǎn)生影響

如果沒有報錯說明啟動成功,然后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 節(jié)點下缺少一下內(nèi)容

? ? ? 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 啟動失敗(發(fā)現(xiàn)一下日志)

orderer.genesis.block

實際創(chuàng)世區(qū)塊名稱和docker-compose-base 文件中的配置不一致導(dǎo)致

- ../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節(jié)點名稱一致

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 端口寫錯了應(yīng)該是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網(wǎng)絡(luò)問題

[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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末堕扶,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子梭依,更是在濱河造成了極大的恐慌稍算,老刑警劉巖,帶你破解...
    沈念sama閱讀 207,113評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件役拴,死亡現(xiàn)場離奇詭異糊探,居然都是意外死亡,警方通過查閱死者的電腦和手機河闰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,644評論 2 381
  • 文/潘曉璐 我一進店門科平,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人姜性,你說我怎么就攤上這事瞪慧。” “怎么了部念?”我有些...
    開封第一講書人閱讀 153,340評論 0 344
  • 文/不壞的土叔 我叫張陵弃酌,是天一觀的道長。 經(jīng)常有香客問我印机,道長矢腻,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,449評論 1 279
  • 正文 為了忘掉前任射赛,我火速辦了婚禮多柑,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘楣责。我一直安慰自己竣灌,他們只是感情好聂沙,可當我...
    茶點故事閱讀 64,445評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著初嘹,像睡著了一般及汉。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上屯烦,一...
    開封第一講書人閱讀 49,166評論 1 284
  • 那天坷随,我揣著相機與錄音,去河邊找鬼驻龟。 笑死温眉,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的翁狐。 我是一名探鬼主播类溢,決...
    沈念sama閱讀 38,442評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼露懒!你這毒婦竟也來了闯冷?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,105評論 0 261
  • 序言:老撾萬榮一對情侶失蹤懈词,失蹤者是張志新(化名)和其女友劉穎蛇耀,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體钦睡,經(jīng)...
    沈念sama閱讀 43,601評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡蒂窒,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,066評論 2 325
  • 正文 我和宋清朗相戀三年躁倒,在試婚紗的時候發(fā)現(xiàn)自己被綠了荞怒。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,161評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡秧秉,死狀恐怖褐桌,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情象迎,我是刑警寧澤荧嵌,帶...
    沈念sama閱讀 33,792評論 4 323
  • 正文 年R本政府宣布,位于F島的核電站砾淌,受9級特大地震影響啦撮,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜汪厨,卻給世界環(huán)境...
    茶點故事閱讀 39,351評論 3 307
  • 文/蒙蒙 一赃春、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧劫乱,春花似錦织中、人聲如沸锥涕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,352評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽层坠。三九已至,卻和暖如春刁笙,著一層夾襖步出監(jiān)牢的瞬間破花,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,584評論 1 261
  • 我被黑心中介騙來泰國打工疲吸, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留旧乞,地道東北人。 一個月前我還...
    沈念sama閱讀 45,618評論 2 355
  • 正文 我出身青樓磅氨,卻偏偏與公主長得像尺栖,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子烦租,可洞房花燭夜當晚...
    茶點故事閱讀 42,916評論 2 344

推薦閱讀更多精彩內(nèi)容