1

I'm trying to deploy a Java Smart Contract on Hyperledger Fabric, and I'm having timeout issues executing the command peer lifecycle chaincode install cp.tar.gz.

The error at the terminal is:

Error: chaincode install failed with status: 500 - error in simulation: failed to execute transaction baeacb6b68dac2872098105d20cb0398e5ce5b744afd37bf75ab65b0ffc7a754: error sending: timeout expired while executing transaction

Monitoring the network, the error occurs like this:

lucid_ganguly|Downloading https://services.gradle.org/distributions/gradle-5.6.2-bin.zip peer0.org1.example.com|2020-05-30 03:15:08.175 UTC [endorser] callChaincode -> INFO 04d finished chaincode: _lifecycle duration: 300000ms channel= txID=baeacb6b peer0.org1.example.com|2020-05-30 03:15:08.176 UTC [endorser] SimulateProposal -> ERRO 04e failed to invoke chaincode _lifecycle, error: timeout expired while executing transaction

It seems to me that downloading that gradle file is taking too much time. My internet is not so fast, but yesterday it worked fine several times. If I re-execute the command, then the contract is installed correctly, I think because the file is already downloaded into the peer.

Modifying the timeout limit may be avoid the error, but it will still taking a lot of time installing the Smart Contract.

I don't know much about docker. There is some way that the gradle file is not downloaded everytime I restart the network? There is other way to make the install faster?

EDIT: Is it possible that having Kazam open (not recording) make my PC works slower (and perhaps causing timeout)????

Eduardo Pascual Aseff
  • 1,149
  • 2
  • 13
  • 26

1 Answers1

3

This is how hyper ledger works. 1) Your Java code would be gradle project., and when you trigger 'install' in 'cli' container, then the code is simply copied to designated location. 2) Next step would be instantiate. In this step, it is 'gradle build' that actually kicks off and starts downloading all dependencies.

In order to expedite this, first get the 'gradle build' work on your machine. This would result into all depeandancies to be downloaded to your '~/.gradle' folder. Now, 'COPY' this folder to 'hyperledger/fabric-javaenv' docker image, i.e. we are copying all dependencies from your local disk into image. This way, a download from within the docker container would be avoided.

EDIT: Hope you've cloned the 'fabric samples' code. Once done, go the following location. It is this code that gets installed and instantiated from within the 'cli' container into the peers.

C:\sw\hlf146-2\fabric-samples\fabcar\java

Now perform gradle build. Assuming you have internet accessa and no proxy related harrassment, your build should succeed.

C:\sw\hlf146-2\fabric-samples\fabcar\java>gradle build
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.3/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing

> Task :buildEnvironment

------------------------------------------------------------
Root project
------------------------------------------------------------

classpath
No dependencies

A web-based, searchable dependency report is available by adding the --scan option.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 16s
1 actionable task: 1 executed

Once successful, the gradle build would have downloaded all of the dependancies into following folder

c:\users\your-user-name\.gradle

Hope you have already downloaded fabric images too onto your machine. Dont worry about the sizes of the fabric images in my output below. I was monkeying around and so you see certain images to be 'huge' like 4.58 GB. Also ignore 'dev-peerX.orgX' images below. You'd have them created by the time you get the network UP.

C:\sw\hlf146-2\fabric-samples\fabcar\java>docker image ls
REPOSITORY                                                                                               TAG                 IMAGE ID            CREATED             SIZE
dev-peer0.org2.example.com-fabcar-1.0-264b0a1cb5efbecaac5cf8990339c24474dc8435c6e10f10f2be565d555d0e94   latest              32aca2e8365e        4 hours ago         4.58GB
dev-peer0.org1.example.com-fabcar-1.0-5c906e402ed29f20260ae42283216aa75549c571e2e380f3615826365d8269ba   latest              89f8611e67f7        4 hours ago         4.58GB
hyperledger/fabric-javaenv                                                                               1.4                 190c5452a677        22 hours ago        4.56GB
hyperledger/fabric-ccenv                                                                                 1.4                 774f228847d4        36 hours ago        1.79GB
openjdk                                                                                                  latest              0ce6496aae74        6 weeks ago         497MB
hyperledger/fabric-ca                                                                                    1.4                 3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-ca                                                                                    1.4.6               3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-ca                                                                                    latest              3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-tools                                                                                 1.4.6               0f9743ac0662        3 months ago        1.49GB
hyperledger/fabric-tools                                                                                 latest              0f9743ac0662        3 months ago        1.49GB
hyperledger/fabric-orderer                                                                               1.4                 84eaba5388e7        3 months ago        120MB
hyperledger/fabric-orderer                                                                               1.4.6               84eaba5388e7        3 months ago        120MB
hyperledger/fabric-orderer                                                                               latest              84eaba5388e7        3 months ago        120MB
hyperledger/fabric-peer                                                                                  1.4                 5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-peer                                                                                  1.4.6               5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-peer                                                                                  latest              5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-zookeeper                                                                             0.4                 ede9389347db        7 months ago        276MB
hyperledger/fabric-zookeeper                                                                             0.4.18              ede9389347db        7 months ago        276MB
hyperledger/fabric-zookeeper                                                                             latest              ede9389347db        7 months ago        276MB
hyperledger/fabric-kafka                                                                                 0.4                 caaae0474ef2        7 months ago        270MB
hyperledger/fabric-kafka                                                                                 0.4.18              caaae0474ef2        7 months ago        270MB
hyperledger/fabric-kafka                                                                                 latest              caaae0474ef2        7 months ago        270MB
hyperledger/fabric-couchdb                                                                               0.4                 d369d4eaa0fd        7 months ago        261MB
hyperledger/fabric-couchdb                                                                               0.4.18              d369d4eaa0fd        7 months ago        261MB
hyperledger/fabric-couchdb                                                                               latest              d369d4eaa0fd        7 months ago        261MB

Now in the above image list it is 'hyperledger/fabric-javaenv' image that would be used by HLF to compile your chain code from within the 'cli' container. It is this image that we'd like to enrich with 'c:\users\your-user-name.gradle' dependancies from your machine. Also, at the time of this writing, the 'hyperledger/fabric-javaenv' image was using gradle 4.5 version, and I wanted to use latest gradle version. So, I also copied gradle 6.3 (although Gradle 6.4 was the latest at the time of this writing) too to the 'hyperledger/fabric-javaenv' image.

So for this, in a new folder put a file named 'Dockerfile' (with no file extension) in it with the following contents (from here on I'm assuming you'll have some knowledge on docker, otherwise, you should stop here. Learn some basics of Docker and resume from here).

FROM hyperledger/fabric-javaenv:1.4
RUN rm -rf /root/.gradle
RUN rm -rf /opt/gradle

ADD ./gradle.zip /opt/
RUN unzip -o /opt/gradle.zip -d /opt/

ADD ./.gradle.zip /root/.gradle/
RUN unzip -o /root/.gradle/.gradle.zip -d /root/.gradle
ENV PATH="/opt/gradle/gradle-6.3/bin:${PATH}"
ENV GRADLE_HOME="opt/gradle/gradle-6.3"
RUN chmod 777 /opt/gradle/gradle-6.3/bin/*
ENV JAVA_HOME="/opt/java/openjdk"

Now zip c:\users\your-user-name.gradle folder contents (not the folder itself) as '.gradle.zip' and place it in the above folder. Next also place gradle.zip (this would be gradle software downloaded, and when you unzip this gradle.zip, it should have gradle-6.3 in it, and that would have all of Gradle software. You can edit above 'Dockerfile' to have right accordingly otherwise).

As I'm running all of this on windows, I have 'docker desktop' installed on my machine and selected 'switch to linux containers' too. If you do not have this software, you need to get this installed. Again assuming you are not behind a proxy, you'll not have all of that proxy related harrasment and things should be seamless for Docker installation.

Next we need to 'build' docker image using above 'Dockerfile'.

Microsoft Windows [Version 10.0.17763.1217]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\sw\hlf-scripts\javaenv-image-2>dir
 Volume in drive C is Windows
 Volume Serial Number is AE8A-E101

 Directory of C:\sw\hlf-scripts\javaenv-image-2

02-06-2020  00:20    <DIR>          .
02-06-2020  00:20    <DIR>          ..
02-06-2020  00:19        68,813,513 .gradle.zip
01-06-2020  21:21               412 Dockerfile
01-06-2020  17:15       101,876,236 gradle.zip

C:\sw\hlf-scripts\javaenv-image-2>docker build .
Sending build context to Docker daemon  170.7MB
Step 1/11 : FROM hyperledger/fabric-javaenv:1.4
 ---> 190c5452a677
Step 2/11 : RUN rm -rf /root/.gradle
 ---> Running in 1bee6799c989
Removing intermediate container 1bee6799c989
 ---> e80c78e7f151
Step 3/11 : RUN rm -rf /opt/gradle
 ---> Running in 8b92d2062a0e
Removing intermediate container 8b92d2062a0e
 ---> 9a8b7ebfd19a
Step 4/11 : ADD ./gradle.zip /opt/
 ---> 6c32d08ac3d6
Step 5/11 : RUN unzip -o /opt/gradle.zip -d /opt/
 ---> Running in db8bbf7af51c
Archive:  /opt/gradle.zip
   creating: /opt/gradle/
   creating: /opt/gradle/gradle-6.3/
   creating: /opt/gradle/gradle-6.3/bin/
  inflating: /opt/gradle/gradle-6.3/bin/gradle
  inflating: /opt/gradle/gradle-6.3/bin/gradle.bat

    ...

  inflating: /opt/gradle/gradle-6.3/lib/xml-apis-1.4.01.jar
  inflating: /opt/gradle/gradle-6.3/LICENSE
  inflating: /opt/gradle/gradle-6.3/NOTICE
  inflating: /opt/gradle/gradle-6.3/README
Removing intermediate container db8bbf7af51c
 ---> 00b1723e518d
Step 6/11 : ADD ./.gradle.zip /root/.gradle/
 ---> 19cab7daafba
Step 7/11 : RUN unzip -o /root/.gradle/.gradle.zip -d /root/.gradle
 ---> Running in cda0aad70e6f
Archive:  /root/.gradle/.gradle.zip
   creating: /root/.gradle/6.3/
   creating: /root/.gradle/6.3/fileChanges/
 extracting: /root/.gradle/6.3/fileChanges/last-build.bin
   creating: /root/.gradle/6.3/fileHashes/

    ...

 extracting: /root/.gradle/vcs-1/gc.properties
   creating: /root/.gradle/workers/
Removing intermediate container cda0aad70e6f
 ---> bd42d756dcf7
Step 8/11 : ENV PATH="/opt/gradle/gradle-6.3/bin:${PATH}"
 ---> Running in 3d84e00c5b82
Removing intermediate container 3d84e00c5b82
 ---> ef445b162906
Step 9/11 : ENV GRADLE_HOME="opt/gradle/gradle-6.3"
 ---> Running in 41c1a2017e9f
Removing intermediate container 41c1a2017e9f
 ---> c77880c756fd
Step 10/11 : RUN chmod 777 /opt/gradle/gradle-6.3/bin/*
 ---> Running in 77eb321c94ce
Removing intermediate container 77eb321c94ce
 ---> 3e4e65c47c61
Step 11/11 : ENV JAVA_HOME="/opt/java/openjdk"
 ---> Running in 4bc72d56e33d
Removing intermediate container 4bc72d56e33d
 ---> eba22c19da02
Successfully built eba22c19da02
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

C:\sw\hlf-scripts\javaenv-image-2>

Check docker image list, and you should find the newly crated image in there. In the below list, see the first one, that is the one created now. It has REPOSITORY and TAG as . Observe that the IMAGEID for this newly created image is 'eba22c19da02'. This would later be used in command below.

C:\sw\hlf-scripts\javaenv-image-2>docker image ls
REPOSITORY                                                                                               TAG                 IMAGE ID            CREATED             SIZE
<none>                                                                                                   <none>              eba22c19da02        4 minutes ago       4.94GB
dev-peer0.org2.example.com-fabcar-1.0-264b0a1cb5efbecaac5cf8990339c24474dc8435c6e10f10f2be565d555d0e94   latest              32aca2e8365e        5 hours ago         4.58GB
dev-peer0.org1.example.com-fabcar-1.0-5c906e402ed29f20260ae42283216aa75549c571e2e380f3615826365d8269ba   latest              89f8611e67f7        5 hours ago         4.58GB
hyperledger/fabric-javaenv                                                                               1.4                 190c5452a677        22 hours ago        4.56GB
hyperledger/fabric-ccenv                                                                                 1.4                 774f228847d4        37 hours ago        1.79GB
openjdk                                                                                                  latest              0ce6496aae74        6 weeks ago         497MB
hyperledger/fabric-ca                                                                                    1.4                 3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-ca                                                                                    1.4.6               3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-ca                                                                                    latest              3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-tools                                                                                 1.4.6               0f9743ac0662        3 months ago        1.49GB
hyperledger/fabric-tools                                                                                 latest              0f9743ac0662        3 months ago        1.49GB
hyperledger/fabric-orderer                                                                               1.4                 84eaba5388e7        3 months ago        120MB
hyperledger/fabric-orderer                                                                               1.4.6               84eaba5388e7        3 months ago        120MB
hyperledger/fabric-orderer                                                                               latest              84eaba5388e7        3 months ago        120MB
hyperledger/fabric-peer                                                                                  1.4                 5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-peer                                                                                  1.4.6               5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-peer                                                                                  latest              5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-zookeeper                                                                             0.4                 ede9389347db        7 months ago        276MB
hyperledger/fabric-zookeeper                                                                             0.4.18              ede9389347db        7 months ago        276MB
hyperledger/fabric-zookeeper                                                                             latest              ede9389347db        7 months ago        276MB
hyperledger/fabric-kafka                                                                                 0.4                 caaae0474ef2        7 months ago        270MB
hyperledger/fabric-kafka                                                                                 0.4.18              caaae0474ef2        7 months ago        270MB
hyperledger/fabric-kafka                                                                                 latest              caaae0474ef2        7 months ago        270MB
hyperledger/fabric-couchdb                                                                               0.4                 d369d4eaa0fd        7 months ago        261MB
hyperledger/fabric-couchdb                                                                               0.4.18              d369d4eaa0fd        7 months ago        261MB
hyperledger/fabric-couchdb                                                                               latest              d369d4eaa0fd        7 months ago        261MB

Now we want to tell docker to use this newly created image as 'hyperledger/fabric-javaenv' image (which later would be picked up by HLF during HLF network creation). I'm running HLF 1.4 for all of this, and ':1.4' is given in the tag below. After the command is run, you can now observe that 'eba22c19da02' is now populated as 'hyperledger/fabric-javaenv' and TAG as 1.4

C:\sw\hlf-scripts\javaenv-image-2>docker tag eba22c19da02 hyperledger/fabric-javaenv:1.4

C:\sw\hlf-scripts\javaenv-image-2>docker image ls
REPOSITORY                                                                                               TAG                 IMAGE ID            CREATED             SIZE
hyperledger/fabric-javaenv                                                                               1.4                 eba22c19da02        8 minutes ago       4.94GB
dev-peer0.org2.example.com-fabcar-1.0-264b0a1cb5efbecaac5cf8990339c24474dc8435c6e10f10f2be565d555d0e94   latest              32aca2e8365e        5 hours ago         4.58GB
dev-peer0.org1.example.com-fabcar-1.0-5c906e402ed29f20260ae42283216aa75549c571e2e380f3615826365d8269ba   latest              89f8611e67f7        5 hours ago         4.58GB
hyperledger/fabric-ccenv                                                                                 1.4                 774f228847d4        37 hours ago        1.79GB
openjdk                                                                                                  latest              0ce6496aae74        6 weeks ago         497MB
hyperledger/fabric-ca                                                                                    1.4                 3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-ca                                                                                    1.4.6               3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-ca                                                                                    latest              3b96a893c1e4        3 months ago        150MB
hyperledger/fabric-tools                                                                                 1.4.6               0f9743ac0662        3 months ago        1.49GB
hyperledger/fabric-tools                                                                                 latest              0f9743ac0662        3 months ago        1.49GB
hyperledger/fabric-orderer                                                                               1.4                 84eaba5388e7        3 months ago        120MB
hyperledger/fabric-orderer                                                                               1.4.6               84eaba5388e7        3 months ago        120MB
hyperledger/fabric-orderer                                                                               latest              84eaba5388e7        3 months ago        120MB
hyperledger/fabric-peer                                                                                  1.4                 5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-peer                                                                                  1.4.6               5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-peer                                                                                  latest              5a52faa5d8c2        3 months ago        128MB
hyperledger/fabric-zookeeper                                                                             0.4                 ede9389347db        7 months ago        276MB
hyperledger/fabric-zookeeper                                                                             0.4.18              ede9389347db        7 months ago        276MB
hyperledger/fabric-zookeeper                                                                             latest              ede9389347db        7 months ago        276MB
hyperledger/fabric-kafka                                                                                 0.4                 caaae0474ef2        7 months ago        270MB
hyperledger/fabric-kafka                                                                                 0.4.18              caaae0474ef2        7 months ago        270MB
hyperledger/fabric-kafka                                                                                 latest              caaae0474ef2        7 months ago        270MB
hyperledger/fabric-couchdb                                                                               0.4                 d369d4eaa0fd        7 months ago        261MB
hyperledger/fabric-couchdb                                                                               0.4.18              d369d4eaa0fd        7 months ago        261MB
hyperledger/fabric-couchdb                                                                               latest              d369d4eaa0fd        7 months ago        261MB

C:\sw\hlf-scripts\javaenv-image-2>

Now proceed with your Java HLF network creation and your chain code install and isntantiate should succeed.

Siva
  • 598
  • 3
  • 11
  • Any hint for making the COPY to 'hyperledger/fabric-javaenv'. I'm pretty unexpert with docker – Eduardo Pascual Aseff Jun 01 '20 at 21:09
  • Updated my answer, assumption here is that you are on Windows, and have a little knowledge of 'Docker', if you don't, have a little understanding of Docker and then go through the above post. I've got the above to work on HLF 1.4, all of this should work for HLF 2.0/ 2.1 also in my view nevertheless. – Siva Jun 02 '20 at 17:43
  • Thanks a lot. I haven't tried yet, but marked as answer because looks like as what I'm searching. – Eduardo Pascual Aseff Jun 02 '20 at 22:09
  • if I just want to copy the .gradle file, can I omit the part of `ENV JAVA_HOME="/opt/java/openjdk"` on dockerfile? Even for updating gradle why it is needed? – Eduardo Pascual Aseff Jun 07 '20 at 00:15
  • Yes you can. In retrospect I don't see a reason why I would have put it there. If you get 'java' not found then add it in. – Siva Jun 07 '20 at 17:01