Error when installing chaincode - failed to calculate dependencies: incomplete package - hyperledger-fabric

I am try to installing Chaincode, follow the tutorial of hyperledger. But when I try to run the command
peer chaincode install -p chaincodedev/chaincode/sacc -n mycc -v 0
The terminal gives error message
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/shim
I see some other people got similar issue, but there is no answer yet. I am new to these stuffs, so any suggestions can be helpful.

I solved it today:
After loging into CLI contaier execute the following command (import the shim package). This will import the package into cli container where the chaincode will be compiled.
go get github.com/hyperledger/fabric-chaincode-go/shim
then execute
peer chaincode install -p chaincodedev/chaincode/sacc -n mycc -v 0
It will work cheers.

You don't say what version of Fabric and samples you are using, but this looks like a change that was made for Fabric 2.0 and described in the release notes "The shim package and dependencies for go chaincode are no longer included in
the chaincode build environment."
There is more detail in the associated Jira entry.

Try downloading the shim package to the GOPATH
go get github.com/hyperledger/fabric-chaincode-go/shim
This downloads the shim package to /src/github.com/hyperledger/fabric-chaincode-go/shim inside your GOPATH . Then provide the path to this shim package inside import in your chaincode.
It should be like below:
import (
"github.com/hyperledger/fabric-chaincode-go/shim"
)

In my case the reason was incorrect path. CLI container work dir has already chaincodedev part of the path
cli:
...
working_dir: /opt/gopath/src/chaincodedev
You can do following to validate if this is true in your case
docker exec -it cli bash
pwd
You have to see /opt/gopath/src/chaincodedev.
So all I needed to do is just remove chaincodedev from command path
peer chaincode install -p chaincode/sacc -n mycc -v 0

Related

Error deploying chaincode in Hyperledger Fabric 2

I'm trying to deploy the chaincode:
Hyperledger Fabric 2
Ubuntu 20.04
go version go1.13.8 linux/amd64
And I always getting this ERROR:
alex#alex:~/fabric-samples/test-network$ ./network.sh deployCC
deploying chaincode on channel 'mychannel'
executing with the following
- CHANNEL_NAME: mychannel
- CC_NAME: basic
- CC_SRC_PATH: NA
- CC_SRC_LANGUAGE: go
- CC_VERSION: 1.0
- CC_SEQUENCE: 1
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
Determining the path to the chaincode
asset-transfer-basic
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go/
~/fabric-samples/asset-transfer-basic/chaincode-go ~/fabric-samples/test-network
~/fabric-samples/test-network
Finished vendoring Go dependencies
+ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1.0
+ res=0
Chaincode is packaged
Installing chaincode on peer0.org1...
Using organization 1
+ peer lifecycle chaincode install basic.tar.gz
+ res=1
Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not build chaincode: docker build failed: docker image build failed: docker build failed: Error returned from build: 1 "go: inconsistent vendoring in /chaincode/input/src:
github.com/golang/protobuf#v1.3.2: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/hyperledger/fabric-chaincode-go#v0.0.0-20200424173110-d7076418f212: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/hyperledger/fabric-contract-api-go#v1.1.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/hyperledger/fabric-protos-go#v0.0.0-20200424173316-dd554ba3746e: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/stretchr/testify#v1.5.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
run 'go mod vendor' to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory
"
Chaincode installation on peer0.org1 has failed
Deploying chaincode failed
I don't know why is happening this issue. I have been reading in internet, and there is not a clear solution...
Any idea?
Thanks
I left it as a comment, but the version is problem.
In particular, unlike 1.13, the vendering behavior is different from version 1.14 (>higher), and this seems to be a problem due to this process. – myeongkil kim
It doesn't make sense that there was a problem with the installation method.
You said in the question that you have go version go1.13.8 linux/amd64 installed.
If the environment variables are well set and official go works normally, it makes no sense that the execution varies depending on the installation method.
Add to,
I don't think the problem was Go version, but the way of installing Go (at least in Ubuntu). – AlexAcc
If you think the version is not the problem, I wonder why.
You can check it very simply. this is a method of changing only the version in the same environment.
so I actually ran it and I was able to confirm that the version problem is correct like this:
go 1.13.8
# same environment
wget https://golang.org/dl/go1.13.8.linux-amd64.tar.gz
sudo tar -xvf go1.13.8.linux-amd64.tar.gz
sudo mv go /usr/local
go env
cd $GOPATH/src/github.com/hyperledger/fabric-samples/test-network
./network.sh down
./network.sh up
./network.sh deployCC
Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not build chaincode: docker build failed: docker image build failed: docker build failed: Error returned from build: 1 "go: inconsistent vendoring in /chaincode/input/src:
github.com/golang/protobuf#v1.3.2: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/hyperledger/fabric-chaincode-go#v0.0.0-20200424173110-d7076418f212: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/hyperledger/fabric-contract-api-go#v1.1.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/hyperledger/fabric-protos-go#v0.0.0-20200424173316-dd554ba3746e: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
github.com/stretchr/testify#v1.5.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
run 'go mod vendor' to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory
"
Chaincode installation on peer0.org1 has failed
go 1.15.6
# same environment
wget https://golang.org/dl/go1.15.6.linux-amd64.tar.gz
sudo tar -xvf go1.15.6.linux-amd64.tar.gz
sudo mv go /usr/local
go env
cd $GOPATH/src/github.com/hyperledger/fabric-samples/test-network
./network.sh down
./network.sh up
./network.sh deployCC
2020-12-11 10:45:12.229 KST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nJbasic_1.0:4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad\022\tbasic_1.0" >
2020-12-11 10:45:12.229 KST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad
Chaincode is installed on peer0.org1
I solved the issue by removing containers and volumes :
-Stop the container(s) using the following command: docker-compose down.
-Delete all containers using the following command: docker rm -f $(docker ps -a -q)
-Delete all volumes using the following command: docker volume rm $(docker volume ls -q)
Caution: the commands above would remove all your containers/Volumes, not only those created by Fabric
The problem was that I was using go, installed with:
apt get
and later with:
apt install
But it didn't work until I tried to download go, from oficial source using wget:
wget https://golang.org/dl/go1.15.6.linux-amd64.tar.gz
sudo tar -xvf go1.15.6.linux-amd64.tar.gz
sudo mv go /usr/local
sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
This link helped:
https://medium.com/#kaigo/installing-golang-on-ubuntu-20-04-68137ea931
After installing newer version of golang and running the command:
sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
for updating the $PATH variable, I had to close and re-open wsl command prompt.
After that chaincode was successfully deployed.

Error: error getting chaincode bytes: listing deps for package chaincode_example02 failed: exit status 2

After executing this command to generate chaincode(written in go) package:
peer lifecycle chaincode package $CC_PACKAGE_FILE -p chaincode_example02 --label $CC_LABEL
where
CC_LABEL=gocc.1.0-1.0
CC_PACKAGE_FILE=$HOME/packages/$CC_LABEL.tar.gz
I am getting the following error:
Error: error getting chaincode bytes: listing deps for package chaincode_example02 failed: exit status 2
I am using Hyperledger Fabric version 2.1.
$ echo $GOAPTH
/home/divyas/Downloads/HF/gopath
$ cd $GOPATH
bin pkg src
chaincode_example02 folder exists inside src
Please help.
Have you tried GO111MODULE=on go mod vendor inside your chaincode directory?
If the above solution didn't work then you can follow this answer.

peer chain code install problem directory not found

I have started a fabric network with three orgs one pear for each org and one orderer. Created one channel and added the peers to the channel.But when i try to install the chaincode it says directory not found. I also mounted the volume inside my cli config.
i am entering cli bash before entering the command also checked using peer channel list command to see if my peer is joined in a channel.
my cli config
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/fabric-samples/food-network/chaincode
- ./crypto-config:/opt/gopath/fabric-samples/food-network/crypto-config/
my peer command
peer chaincode install -n chain chain -v 1.0
error
Error: open /opt/gopath/fabric-samples/food-network/chaincode/chain: no such file or directory
my chain code is named chain.go. Its a go file and it has been built.
also when i try this command:
peer chaincode install -n chain -p chain -v 1.0
it gives this error:
error getting chaincode code chain: path to chaincode does not exist: /opt/gopath/src/chain
In order to install chaincode, you need to build a chaincode package. You can either run
peer chaincode package ...
followed by
peer chaincode install ...
or you can use the -p option with peer chaincode install to package and install together.
When using the peer cli to package chaincode, it will look for your Go chaincode under $GOPATH/src. The cli container has its GOPATH set to /opt/gopath.
I'm not sure where your actual chaincode is located, but assuming your your Go code is located in ./../chaincode on your host, you would need to change your volume mount to
- ./../chaincode/:/opt/gopath/src/chaincode
and then you can run
peer chaincode install -n chain -p chaincode -v 1.0

Command missing when running through Hyperledger tutorial—cannot package chaincode

When working through the Hyperledger tutorial docs, there is a snippet that says to type:
peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label mycc_1
in the CLI. However, when trying to run it, I get an error that says:
Error: unknown command "lifecycle" for "peer"
When typing peer -h in the CLI, the results show that the "lifecycle" command isn't available for "peer".
Am I running a wrong version of the docker container? What is going on?
I ended up figuring this out, posting solution here for future reference: turns out I downloaded the wrong docker images. I had hyperledger 1.4.1 images and I needed the 2.0 alphas. To check versions I just ran "docker images" in the cli.

HLF 1.0.2 - deserialize a SerializedIdentity provided by stub.GetCreator()

The process is quite well described here.
Unfortunately when I'm trying to import msp package (github.com/hyperledger/fabric/protos/msp) in my chaincode I'm receiving an error during install phase:
Error: Error getting chaincode code chaincode: Error getting chaincode package bytes: Error obtaining dependencies for github.com/hyperledger/fabric/protos/msp: <go, [list -f {{ join .Deps "\n"}} github.com/hyperledger/fabric/protos/msp]>: failed with error: "exit status 1"
can't load package: package github.com/hyperledger/fabric/protos/msp: cannot find package "github.com/hyperledger/fabric/protos/msp" in any of:
/opt/go/src/github.com/hyperledger/fabric/protos/msp (from $GOROOT)
/opt/gopath/src/github.com/hyperledger/fabric/protos/msp (from $GOPATH)
Q: Does it mean that I can use the limited, predefined set of imports in the chaincode?
I'm using the newest fabric docker images available on dockerhub (1.0.2) to install cc with following command:
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" cli peer chaincode install -n testcc -v 1.0 -p github.com/testcc
EDIT: Artem is right, the error goes from Install command - I've updated the description.
First of all I think that the error you have experienced occurs in install stage rather than instantiate, since it seems to be a compilation error:
Error: Error getting chaincode code chaincode: Error getting chaincode package bytes: Error obtaining dependencies for github.com/hyperledger/fabric/protos/msp: : failed with error: "exit status 1"
can't load package: package github.com/hyperledger/fabric/protos/msp: cannot find package "github.com/hyperledger/fabric/protos/msp" in any of:
/opt/go/src/github.com/hyperledger/fabric/protos/msp (from $GOROOT)
/opt/gopath/src/github.com/hyperledger/fabric/protos/msp (from $GOPATH)
In order to solve this problem you need to vendor missing package into your chaincode, e.g.:
govendor init
and
govendor fetch github.com/hyperledger/fabric/protos/msp
most likely you will need also to vendor additional dependencies.

Resources