Hyperledger Fabric笔记4--运行IBM Marbles项目

Hyperledger Fabric笔记4--运行IBM Marbles项目
 

最近又开始接触Fabric项目了,把之前的安装配置环境又熟悉了一遍,顺便也把IBM Marbles项目的测试运行过程给说明一下,以便于后续查阅,若有不妥敬请指出以便于共同学习!

1、基础环境
IBM项目需要的环境包括git、golang、docker、nodejs,其环境配置参考笔者之前的文章  Hyperledger Fabric笔记1--配置fabric运行基础环境 https://blog.csdn.net/u011127242/article/details/79596815

fabric GitHub网址:https://github.com/hyperledgerhttps://github.com/hyperledger

marbles GitHub网址:https://github.com/IBM-Blockchain/marbles

2、部署流程
注:以下步骤前置条件为 1中基础环境已经按照要求安装完毕!使用的Marbles和笔者提供的版本相同,建议直接下载笔者使用的Marbles源码:https://download.csdn.net/download/u011127242/10748501!

1)将Marbles源码解压到 /opt/gopath/src/github.com/hyperledger目录下;

下载fabric-samples项目 git clone https://github.com/hyperledger/fabric-samples.git

git tag  #查看所有tag版本

git checkout -b v4.0.2 #在本地新建tag为v4.0.2的分支

2)下载平台二进制文件
该文件一般很难下载,多需要FQ,建议参考 Hyperledger Fabric笔记2--运行fabric测试网络:
https://blog.csdn.net/u011127242/article/details/79597351
2->3)执行fabric/scripts下的bootstrap-1.0.0.sh脚本,以获取一个包含configtxgen、cryptogen和peer等文件的bin目录

3)进入fabcar执行如下命令获取项目运行的nodejs环境
cd fabric-samples/fabcar
sudo npm install 安装项目需要的依赖文件

4)清理缓存 (若没有运行其它重要镜像建议能删除的都删除掉)
docker rm -f $(docker ps -aq)
docker network prune

5)启动网络,运行、注册用户、执行查询
./startFabric.sh
npm install
node enrollAdmin.js
node registerUser.js
node query.js

query后出现如下内容即表示之前配置正常。


拷贝fabric-samples/fabcar/hfc-key-store文件到/root/.hfc-key-store目录:
mv /root/hfc-key-store/ /root/.hfc-key-store/
mv /root/hfc-key-store/ /root/.hfc-key-store/

注意:此处若直接使用笔者上传的Marbles压缩包,直接使用上述拷贝即可正常运行;若从官方clone的,则需要修改marblesconfigconnection_profile_local.json中的 hfc-key-store 的绝对路径,使其为fabric-samples/fabcar/hfc-key-store的绝对路径,否则会出现3、中的错误3)。

6)安装并实例化链码
cd marbles ( 步骤1)中下载的路径)
npm install
cd ./scripts
node install_chaincode.js (如果首次,最好npm rebuild一下)
node instantiate_chaincode.js

install 和instantiate成功后如下图所示:

 

 

7)运行项目、查看效果
npm install gulp -g
npm install
gulp marbles_local
localhost:3001(若为桌面版Ubuntu系统,则直接在浏览器中输入localhost:3001即可,server版本则输入对应的IP地址)

注意:

若重新执行5)中的步骤则需要对应更新  $HOME/.hfc-key-store/中的文件,否则在执行的时候可能出现证书过期的错误,若出现该类错误则参考  3、注意事项->4) 中的方法更新文件即可。

执行成功后如下图所示:

运行效果如下图所示:

 

3、注意事项
1)执行node install_chaincode.js 出现如下错误:

info: First we enroll error:  Error: ENOENT: no such file or directory, open '/home/ibmadmin/fabric-samples/fabcar/hfc-key-store/admin' ,即在指定目录没有找到hfc-key-store文件夹,笔者将其 fabric-samples/fabcar/hfc-key-store文件拷贝到/root/.hfc-key-store目录即可解决该问题。

2)执行node install_chaincode.js 出现如下错误:

Error: Failed to load gRPC binary module because it was not installed for the current system,即没有找到gRPC库,此时重新执行 npm rebuild一下接即可获取gRPC运行环境。

3)node install_chaincode.js 出现 Error('Cannot find org.', orgName):

root@xg:/opt/gopath/src/github.com/hyperledger/marbles/scripts# node install_chaincode.js 
info: Loaded config file /opt/gopath/src/github.com/hyperledger/marbles/config/marbles_local.json
info: Loaded connection profile file /opt/gopath/src/github.com/hyperledger/marbles/config/connection_profile_local.json

Connection Profile Lib Functions:()
......
  getAdminSignedCertPEM()
---------------------------------------
info: Lets install some chaincode - marbles v4
---------------------------------------
info: First we enroll
/opt/gopath/src/github.com/hyperledger/marbles/utils/connection_profile_lib/parts/org.js:102
        throw new Error('Cannot find org.', orgName);
        ^
Error: Cannot find org.
......

该问题是由于 marblesconfigconnection_profile_local.json中的 hfc-key-store 的绝对路径不正确导致的,需要更改是实际路径,当我们执行了 2、部署流程->5)后,在其目录下生成了一个hfc-key-store文件夹,该文件夹路径就是需要更改的绝对路径。

如下图,笔者marbles 的tag=v4.0.1版本中有3处需要修改,依次修改即可:

 

修改后再次执行,即可解决该问题。

参考网址:use peer org cert to install on local hyperledger https://github.com/IBM-Blockchain/marbles/issues/217

4)如果更新connection_profile_local.json后,执行gulp marbles_local时候出现如下错误:

 

解决方法如下: cp ../fabric-samples/fabcar/hfc-key-store/*  $HOME/.hfc-key-store/ 

拷贝后再次执行 gulp marbles_local 即可正常启动marbles项目。

参考网址:Host Marbles Locally->4 : https://github.com/IBM-Blockchain/marbles/blob/master/docs/host_marbles_locally.md

5)marbles不同版本对应不同的fabric版本,如v4对应fabric 1.0.x系列,v5对应1.1.x系列,具体版本信息以GitHub文档为主。

4、说明
截图系统版本:Ubuntu 16.04.4 SERVER LTS (64-bit), 安装在VM虚拟机上

以上 2、部署流程 中的fabric版本为1.0.0-rc1,fabric-samples版本为v1.1.0-alpha, marbles版本为v4.0

原文链接:https://blog.csdn.net/u011127242/article/details/83450015

原文地址:https://www.cnblogs.com/show58/p/13153718.html