1

I am trying to customize tuna-app chaincode of the tuna-app example. I want to use cid package inside my chaincode to make ABAC decisions about who is allowed to run the chaincode. When I try to install chaincode, I get the following error:

Error: Error getting chaincode code chaincode: 
Error getting chaincode package bytes: Error obtaining dependencies for github.com/hyperledger/fabric/core/chaincode/lib/cid: 
<go, [list -f {{ join .Deps "\n"}} github.com/hyperledger/fabric/core/chaincode/lib/cid]>: failed with error: "exit status 1" 
cannot load package: package github.com/hyperledger/fabric/core/chaincode/lib/cid: cannot find package "github.com/hyperledger/fabric/core/chaincode/lib/cid" in any of:
/opt/go/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOROOT)
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOPATH)

I am usind Docker to run peer, orderer, ca, and cli containers. The Docker image which is used to build chaincode is hyperledger/fabric-ccenv. This image is created using Dockerfile; the interesting line I found was:

ADD payload/goshim.tar.bz2 $GOPATH/src/

which adds the tar.bz2 inside the $GOPATH/src folder (I believe). The .tar.bz2 file contains all Go packages used by chaincode. I tried to insert the cid package and to create a new .tar.bz2 file with the package inside. Then I rebuilt the image. The image now contains the cid package, but I still get the same error.

Why is it still missing the package?

das96
  • 33
  • 2
  • 4

2 Answers2

3

In the startFabric.sh from your tuna-app, you launch the cli container using:

docker-compose -f ./docker-compose.yml up -d cli

Have a look at the mounting declaration of the persistent volumes in your compose yaml file. You should see something like this because the tuna-app is based on fabcar from the fabric-samples:

./../chaincode/:/opt/gopath/src/github.com/

If you see this declaration, copy in your local machine the folder /hyperledger/fabric/core/chaincode/lib/cid into your chaincode folder. You should find it in chaincode/abac if you are using the last version of fabric samples (https://github.com/hyperledger/fabric-samples).

  • Thank you, your suggestion helped me a lot. Instead of copying only the hyperledger folder, as you mentioned, I copied also the two packages (golang and pkg) inside the chaincode folder. It now works. However, I am still missing something. I cannot understand: if the package is inside the ccenv image, the chaincode is not able to find it, while, if it is inside the cli image, it works... – das96 Apr 04 '18 at 06:43
  • I'm glad I was able to help you. Yes you need also golang and pkg because they contain dependencies of the cid package. I think it is the protobuf library and the error handling package. – Philippe Labalette Apr 04 '18 at 09:01
  • The ccenv container has no chaincode preinstalled which is being read for execution. The CLI is installs the chaincode on the ccenv: it creates a package of the chaincode and includes all dependencies => It is the reason why you got an error. This package can be optionnaly signed by the different chaincode owners. And then this package is being installed on the ccenv by running the command "peer install". – Philippe Labalette Apr 04 '18 at 09:11
  • You can also run directly chaincode install if you dont need to get it signed by different owners. – Philippe Labalette Apr 04 '18 at 09:13
  • http://hyperledger-fabric.readthedocs.io/en/release-1.0/chaincode4noah.html – Philippe Labalette Apr 04 '18 at 09:13
  • For your info, it seems you are running your fabric in developer mode: ccenv is executing the chaincode. In the "normal" case, the peers would execute the chaincode – Philippe Labalette Apr 04 '18 at 09:14
  • Ok thank you. So the missing pakages must be included in the CLI becuase it is from there that I install the chaincode, and not in the ccenv because it is only used during execution (if I understood what you are saying) – das96 Apr 05 '18 at 09:18
1

I think you should not create a new goshim.tar.bz2. If you think it is easier make sure cid is in the correct path within the archive, e.g. github.com/hyperledger/fabric/core/chaincode/lib/cid

To test this you can make a debug output:

ADD payload/goshim.tar.bz2 $GOPATH/src/
RUN ls $GOPATH/src/github.com/hyperledger/fabric/core/chaincode/lib/cid

I would recommend to download cid within the Dockerfile:

RUN go get -d github.com/hyperledger/fabric/core/chaincode/lib/cid
s.meissner
  • 506
  • 2
  • 5
  • 17
  • 2
    Thank you for the answer. I tried also to run the `go get` command, but I got as error `package github.com/hyperledger/fabric/core/chaincode/lib/cid/...: /opt/gopath/src/github.com/hyperledger/fabric exists but /opt/gopath/src/github.com/hyperledger/fabric/.git does not - stale checkout?`. I tried also to run the `git clone` command inside Dockerfile, but again, nothing works. Even if nothing is working, the package is inside the ccenv image, and it is in the correct location. – das96 Mar 30 '18 at 09:36