打包链代码后,安装命令给出错误读取为 gzip 流:gzip:无效 header
After packaging chaincode, install command giving error reading as gzip stream: gzip: invalid header
Hyperledger-Fabric V2.3.x
Peer V2.3.3
Go V1.16
完整错误:
Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not parse as a chaincode install package: error reading as gzip stream: gzip: invalid header
我的设置:
CORE_PEER_TLS_ROOTCERT_FILE=./crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=./crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
ORDERER_CA=./crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
之前调用的命令(成功):
peer chaincode package mycc.tar.gz -p . -n mycc --lang golang -v 1.0
命令(我收到错误):
peer lifecycle chaincode install mycc.tar.gz
*如果需要任何其他信息,请评论
go.mod(用于安装依赖)
module github.com/chaincode
go 1.16
require (
github.com/golang/protobuf v1.3.2 // indirect
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200424173110-d7076418f212 // indirect
github.com/hyperledger/fabric-contract-api-go v1.1.0
github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e // indirect
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/tools v0.1.7 // indirect
)
chaincode.go(几行)
package chaincode
import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
)
// SmartContract provides functions for managing an Asset
type SmartContract struct {
contractapi.Contract
}
// Asset describes basic details of what makes up a simple asset
//Insert struct field in alphabetic order => to achieve determinism accross languages
// golang keeps the order when marshal to json but doesn't order automatically
type Asset struct {
AppraisedValue int `json:"AppraisedValue"`
Color string `json:"Color"`
ID string `json:"ID"`
Owner string `json:"Owner"`
Size int `json:"Size"`
}
问题出在我使用命令安装的软件包上:
GO111MODULE=on go mod vendor
我在“go.mod”而不是 1.16 中定义了错误的 go 1.14 版本,因为安装的 go 版本是“1.16”。
(安装了不兼容的包,所以生成的包文件不是正确的gzip文件)
解决方案:
- 删除供应商文件夹
- 使用正确的 go 版本写入 go.mod 或使用 go init (https://golang.org/doc/tutorial/create-module)
- 运行
GO111MODULE=on go mod vendor
- 运行 对等生命周期包命令
- 运行 对等生命周期安装命令
Hyperledger-Fabric V2.3.x
Peer V2.3.3
Go V1.16
完整错误:
Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not parse as a chaincode install package: error reading as gzip stream: gzip: invalid header
我的设置:
CORE_PEER_TLS_ROOTCERT_FILE=./crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=./crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
ORDERER_CA=./crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
之前调用的命令(成功):
peer chaincode package mycc.tar.gz -p . -n mycc --lang golang -v 1.0
命令(我收到错误):
peer lifecycle chaincode install mycc.tar.gz
*如果需要任何其他信息,请评论
go.mod(用于安装依赖)
module github.com/chaincode
go 1.16
require (
github.com/golang/protobuf v1.3.2 // indirect
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200424173110-d7076418f212 // indirect
github.com/hyperledger/fabric-contract-api-go v1.1.0
github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e // indirect
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/tools v0.1.7 // indirect
)
chaincode.go(几行)
package chaincode
import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
)
// SmartContract provides functions for managing an Asset
type SmartContract struct {
contractapi.Contract
}
// Asset describes basic details of what makes up a simple asset
//Insert struct field in alphabetic order => to achieve determinism accross languages
// golang keeps the order when marshal to json but doesn't order automatically
type Asset struct {
AppraisedValue int `json:"AppraisedValue"`
Color string `json:"Color"`
ID string `json:"ID"`
Owner string `json:"Owner"`
Size int `json:"Size"`
}
问题出在我使用命令安装的软件包上:
GO111MODULE=on go mod vendor
我在“go.mod”而不是 1.16 中定义了错误的 go 1.14 版本,因为安装的 go 版本是“1.16”。
(安装了不兼容的包,所以生成的包文件不是正确的gzip文件)
解决方案:
- 删除供应商文件夹
- 使用正确的 go 版本写入 go.mod 或使用 go init (https://golang.org/doc/tutorial/create-module)
- 运行
GO111MODULE=on go mod vendor
- 运行 对等生命周期包命令
- 运行 对等生命周期安装命令