Fabric 環境搭建遇到問題及解決

可達鴨丶發表於2020-09-26

Fabric 環境搭建遇到問題及解決

1、基本環境搭建

(1)下載原始碼

go get緩慢:直接通過git clone下載

mkdir ~/go/src/github.com/hyperledger/ -p

git clone https://github.com/hyperledger/fabric.git

(2)編譯fabric檔案

編譯fabric檔案make all時報錯


/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:56:6: too many errors0000
Makefile:199: recipe for target 'build/bin/orderer' failed
make: *** [build/bin/orderer] Error 2

舊版本go殘留,刪除原版本重新安裝

rm /usr/local/go -rf

(3)編譯fabric檔案

fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz

卡住

目前發現是高概率卡住,多重試幾次

卡住可以修改代理
export GO111MODULE=on
export GOPROXY=https://goproxy.cn

(4)編譯fabric檔案

Building github.com/client9/misspell/cmd/misspell -> misspell
go: github.com/AlekSi/gocov-xml@v0.0.0-20190121064608-3a14fb1c4737: Get "https://proxy.golang.org/github.com/%21alek%21si/gocov-xml/@v/v0.0.0-20190121064608-3a14fb1c4737.mod": dial tcp 216.58.200.241:443: i/o timeout
gotools.mk:39: recipe for target 'gotool.misspell' failed
make: *** [gotool.misspell] Error 1

(5)編譯fabric檔案

WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz: temporary error (try again later)
ERROR: unsatisfiable constraints:

在images下面的五個資料夾中的Dockerfile檔案 From下面一行新增

RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories

2、執行byfn

(1)generate出錯

2020-04-12 09:03:11.604 UTC [common.tools.configtxgen.localconfig] completeInitialization -> PANI 004 etcdraft configuration missing
2020-04-12 09:03:11.604 UTC [common.tools.configtxgen] func1 -> PANI 005 etcdraft configuration missing
panic: etcdraft configuration missing [recovered]
        panic: etcdraft configuration missing

goroutine 1 [running]:
github.com/hyperledger/fabric/vendor/go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc0000b3e40, 0x0, 0x0, 0x0)
        /root/go/src/github.com/hyperledger/fabric/vendor/go.uber.org/zap/zapcore/entry.go:230 +0x545

...

github.com/hyperledger/fabric/internal/configtxgen/genesisconfig.Load(0x7ffd11f3d5cd, 0x17, 0x0, 0x0, 0x0, 0x0)
        /root/go/src/github.com/hyperledger/fabric/internal/configtxgen/genesisconfig/config.go:247 +0x313
main.main()
        /root/go/src/github.com/hyperledger/fabric/cmd/configtxgen/main.go:268 +0xf56
+ res=2
+ set +x
Failed to generate orderer genesis block...

目前原因未知,是2.0之後出現的問題,下載別人編譯好的configtxgen檔案就可以正常執行了

(2)部署chaincode出錯

+ set +x
Error: error getting chaincode bytes: failed to calculate dependencies: incomplete package: github.com/hyperledger/fabric-contract-api-go/contractapi
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!
========= ERROR !!! FAILED to execute End-2-End Scenario ===========

ERROR !!!! Test failed

需要配置go國內代理

go env -w GOPROXY=https://goproxy.cn

export GOPROXY=https://goproxy.cn

export GO111MODULE=on

export GOPROXY=https://goproxy.cn

https://www.cnblogs.com/zoujiaojiao/p/12606909.html

(3)建立通道失敗

Error: got unexpected status: BAD_REQUEST -- error applying config update to existing channel 'mychannel': error authorizing update: error validating ReadSet: proposed update requires that key [Group]  /Channel/Application/Org2MSP be at version 0, but it is currently at version 1
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!

未清除掛載掛在資訊volume和networks

清空所有未使用的docker掛載資訊(慎用)

docker volume prune

清理沒有再被任何容器引用的networks

docker network prune

(4)install chaincode error

Error: error getting chaincode deployment spec for mycc: error getting chaincode package bytes: failed to calculate dependencies: incomplete package: github.com/hyperledger/fabric-chaincode-go/pkg/cid
!!!!!!!!!!!!!!! Chaincode installation on peer0.org1 has failed !!!!!!!!!!!!!!!!
========= ERROR !!! FAILED to execute End-2-End Scenario ===========

ERROR !!!! Test failed

相同的還有github.com/hyperledger/fabric-chaincode-go/shim錯誤

還有google.golang.org/protobuf/encoding/prototext

github.com/golang/protobuf/proto

github.com/hyperledger/fabric-protos-go/peer

google.golang.org/grpc

golang.org/x/net/trace

暫時的解決辦法

docker-compose.yaml中新增volumes

- /root/go/src/:/opt/gopath/src/

然後手動把所有依賴放入對應的本地伺服器位置上

``

git clone https://github.com/protocolbuffers/protobuf-go.git

git clone https://github.com/hyperledger/fabric-protos-go.git

git clone https://github.com/grpc/grpc-go.git

git clone https://github.com/golang/net.git

git clone https://github.com/googleapis/go-genproto.git

git clone https://github.com/golang/sys.git

真正的解決辦法:需要go.mod go.sum等檔案可以參考chaincode/sacc

(5)approveformyorg超時


+ peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledg                                                                                                         er/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts                                                                                                         /tlsca.example.com-cert.pem --channelID mychannel --name mycc --version 1 --init-required --package                                                                                                         -id mycc_1:40aec53f0ee0193b0bd6b63862425298d90e9c3496a840bb54366b2fd66bd18f --sequence 1 --waitForE                                                                                                         vent
+ set +x
2020-04-28 12:07:10.782 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channe                                                                                                         l (mychannel) orderer endpoint: orderer1.example.com:7050
Error: timed out waiting for txid on all peers
===================== Chaincode definition approved on peer0.org1 on channel 'mychannel' ==========                                                                                                         ===========

可能是configtx.yaml中的OrdererEndpoints填寫錯誤 找不到節點

相關文章