如何使Hyperledger Fabric Java Smart Contract安装更快(我想避免超时)? [英] How to make faster Hyperledger Fabric java Smart Contract install (I want to avoid a timeout)?

查看:86
本文介绍了如何使Hyperledger Fabric Java Smart Contract安装更快(我想避免超时)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Hyperledger Fabric上部署Java智能合约,并且在执行命令peer lifecycle chaincode install cp.tar.gz时遇到超时问题.

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.

终端上的错误是:

错误:链码安装失败,状态为:500-错误 模拟:无法执行交易 baeacb6b68dac2872098105d20cb0398e5ce5b744afd37bf75ab65b0ffc7a754: 发送错误:执行事务超时超时

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 |下载 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完成的链码:_lifecycle持续时间: 300000ms频道= txID = baeacb6b peer0.org1.example.com | 2020-05-30 03:15:08.176 UTC [enderser] SimulateProposal-> ERRO 04e未能 调用chaincode _lifecycle,错误:执行时超时到期 交易

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

在我看来,下载gradle文件需要太多时间.我的网速不是那么快,但是昨天它运行了好几次.如果我重新执行该命令,则说明合同安装正确,我认为是因为该文件已下载到对等方中.

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.

我对Docker不太了解.有某种方法可以在每次重新启动网络时不下载gradle文件吗?还有其他方法可以加快安装速度吗?

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?

打开Kazam(不录制)是否可能会使我的PC运转速度变慢(并可能导致超时)??

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

推荐答案

这是超级分类帐的工作方式. 1)您的Java代码将是gradle项目.当您在"cli"容器中触发安装"时,该代码将被简单地复制到指定位置. 2)下一步将被实例化.在此步骤中,实际上是渐进式构建"开始并开始下载所有依赖项.

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.

为了加快这一步,请首先在计算机上进行渐变构建"工作.这将导致所有违规行为被下载到您的〜/.gradle"文件夹中.现在,将这个文件夹"COPY"到"hyperledger/fabric-javaenv"泊坞窗映像,即我们正在将所有依赖项从本地磁盘复制到映像中.这样,就可以避免从Docker容器中进行下载.

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.

希望您已经克隆了织物样品"代码.完成后,转到以下位置.正是这些代码从"cli"容器中安装并实例化到同位体中.

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

现在执行gradle构建.假设您可以访问互联网并且没有与代理相关的骚扰,那么您的构建应该会成功.

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

一旦成功,gradle构建将把所有依赖项下载到以下文件夹中

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

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

希望您也已经将结构映像下载到了计算机上.不用担心下面输出中的结构图像的大小.我到处乱逛,所以您看到某些图像很大",例如4.58 GB.也请忽略下面的"dev-peerX.orgX"图像.您将在网络启动时创建它们.

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

现在在上面的图像列表中,是'hyperledger/fabric-javaenv'图像,HLF将使用该图像从"cli"容器中编译您的链代码.我们希望通过此图像来丰富您计算机中的'c:\ users \ your-user-name.gradle'相关性.另外,在撰写本文时,"hyperledger/fabric-javaenv"映像正在使用gradle 4.5版本,而我想使用最新的gradle版本.因此,我也将gradle 6.3(尽管在撰写本文时Gradle 6.4是最新的)也复制到了"hyperledger/fabric-javaenv"图像中.

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.

为此,在一个新文件夹中放入一个名为"Dockerfile"(无文件扩展名)的文件,其中包含以下内容(从这里开始,我假设您将对Docker有所了解,否则,应该在这里停止.了解Docker的一些基础知识,然后从此处恢复.)

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"

现在将zip c:\ users \ your-user-name.gradle文件夹内容(而不是文件夹本身)作为'.gradle.zip'放置在上述文件夹中.接下来还要放置gradle.zip(这是已下载的gradle软件,当您解压缩该gradle.zip时,它应该包含gradle-6.3,并且将具有Gradle的所有软件.您可以在"Dockerfile"上方进行编辑以具有否则,则相应地).

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).

当我在Windows上运行所有这些程序时,我在计算机上安装了"docker desktop",并选择了"switch to linux container".如果没有此软件,则需要安装此软件.再次假设您没有代理,您将不会拥有与代理相关的所有麻烦,并且对于Docker安装而言应该是无缝的.

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.

接下来,我们需要使用"Dockerfile"上方的构建" Docker映像.

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>

检查docker映像列表,您应该在其中找到新创建的映像.在下面的列表中,看到第一个,即现在创建的那个.它具有REPOSITORY和TAG作为.请注意,此新创建的映像的IMAGEID为'eba22c19da02'.稍后将在下面的命令中使用.

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

现在,我们要告诉docker使用此新创建的映像作为"hyperledger/fabric-javaenv"映像(稍后将在HLF网络创建期间由HLF拾取).我正在为所有这些运行HLF 1.4,下面的标记中给出了':1.4'.运行命令后,您现在可以看到"eba22c19da02"现在填充为"hyperledger/fabric-javaenv",而TAG填充为1.4

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>

现在继续创建Java HLF网络,并且链代码的安装和验证应该成功.

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

这篇关于如何使Hyperledger Fabric Java Smart Contract安装更快(我想避免超时)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆