Build Hyperledger Fabric 1.0

下面列举了我在搭建过程中遇到的一些问题、思考以及解决方法

其实搭建最好参考官方文档,这篇博文只是一个文档没有覆盖的补充
1.

jason@ubuntu:~/docker$ sudo apt install docker.io
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

solution

root@ubuntu:/home/jason/docker# ps -A | grep apt
  2121 ?        00:00:01 aptd
  2841 ?        00:00:00 aptd
  2889 ?        00:00:00 apt-check
root@ubuntu:/home/jason/docker# sudo kill -SIGKILL 2121
root@ubuntu:/home/jason/docker# sudo kill -SIGKILL 2841
root@ubuntu:/home/jason/docker# sudo kill -SIGKILL 2889
root@ubuntu:/home/jason/docker# ps -A | grep apt
root@ubuntu:/home/jason/docker# apt-get install dock.io

2.

sudo apt-get update
AppStream cache update completed, but some metadata was ignored due to errors.

solution:

sudo rm /var/lib/dpkg/lock

https://askubuntu.com/questions/854168/how-i-can-fix-appstream-cache-update-completed-but-some-metadata-was-ignored-d/854256

3.

Unable to fetch some archives, maybe run apt-get update or try with --fix-missing

solution

sudo  apt-get update
sudo apt-get upgrade --fix-missing

4.

./byfn.sh -m up

Error building images: Tag latest not found in repository docker.io/hyperledger/fabric-peer

步骤一:
Pull a specific base image from https://hub.docker.com/r/hyperledger/fabric-peer/ using docker pull hyperledger/fabric-peer:

我到https://hub.docker.com/r/hyperledger/fabric-peer/tags/上看了的确没有latest的tag,然后看到tag主要分为以下三类:

  1. ppc64le(POWER Architecture 体系
    是RISC指令集的CPU)
  2. x86_64(AMD64 一種64位元的電腦處理器架構。它是建基於現有32位元的x86架構,由AMD公司所開發)
  3. s390x(IBM System z 系列 (zSeries)大型机 (mainframe) 硬件平台)

我认为我pull x86_64的版本到本地
docker pull hyperledger/fabric-peer:ppc64le-1.0.0

然后可以通过docker show images看结果

步骤二
Tag this image as latest docker

docker tag hyperledger/fabric-peer:ppc64le-1.0.0  hyperledger/fabric-peer:latest

可以通过docker images查看结果

删除某个镜像的方法:docker rmi -f hyperledger/fabric-peer:latest

更多的docker命令

5.
如果chaincode陷入死循环,有什么hyperledger有什么机制吗?

从目前的资料看来,hyperledger上没有提及,貌似把锅甩给了endoser peer。

下面是一些讨论:
https://github.com/hyperledger-archives/fabric/issues/2232

6.
Hyperledger1.0有个很诡异的地方,orderer会认为client提供的都是endoserment,但其实client完全可以随便扔个东西给orderer,但orderer都会把其打包发送给所有的peer(包括orderer peer和committer peer),然后这些peer再判断这个交易是否合法,然后标记上位掩码。

何为非法交易:i.e., transactions with invalid endorsement or with invalid version dependencies

这样的话,client可以造出很多假的endoserment,造成区块大部分存储了非法交易

下面是一些或许的解决方法,但是peer ledger是不再存储了吗?是只存vledger?最后即使这样也可以让orderer瞎忙活!
http://hyperledger-fabric.readthedocs.io/en/latest/arch-deep-dive.html(4 (post-v1). Validated ledger and PeerLedger checkpointing (pruning))

7.
新的结点加入,找谁去同步?
应该是向orderer请求同步,因为orderer不检出交易的有效性,新的peer同步的也是包含非法交易的peer ledger。

8.
chaincode能够相互调用?
State created by a chaincode is scoped exclusively to (专属于) that chaincode and can’t be accessed directly by another chaincode. However, within the same network, given the appropriate permission a chaincode may invoke another chaincode to access its state.

The other interface in the chaincode “shim” APIs is the ChaincodeStubInterface which is used to access and modify the ledger, and to make invocations between chaincodes.

9.
当你下载编写chaincode时需要的依赖包shime时出错(如下图),因为ubuntu apt-get默认的是glang-1.6.x的版本,而我们需要的是glang-1.7.x的版本(需要手动下载)。
Build Hyperledger Fabric 1.0_第1张图片

删除安装的golang:
apt-get remove xxxx //卸载但不删除配置
apt-get purge xxxx //卸载并且删除相关配置

# 注意删除后环境变量还在的,需要好好修改
apt-get purge golang
apt autoremove

关于环境变量:

  1. GOROOT
  2. GOPATH

如何修改环境变量:
修改~/.bashrc(terminal启动是时候会自动加载这个脚本)

# GOROOT是golang的安装地址
export GOROOT=$HOME/go
# GOPATH是个人工作空间,下载的第三方包等都会在这个路径下
export GOPATH=$HOME/go/goproject
# 把路径$GOROOT/bin添加到路径PATH中
export PATH=$PATH:$GOROOT/bin

source ~/.bashrc

更多

  1. 在Hyperledger的网络初始部署,容器peer, cli, orderer由相应的镜像所生成,而在此部署则不会重新生成,而网络部署后可能你突然中断网络之类的,导致容器情况异常,容器可能不能再被访问。

解决方法:
1. 利用docker ps -a查看所有的容器情况
2. 利用docker rm -f container_id删除所有的id
3. 重新部署网络

关于docker常用命令

10.
SDK 与 API 的联系和区别

11.
HA Proxy
LDAP
libtool
https://www.gnu.org/software/libtool/manual/libtool.html
libltdl
动态链接库

12.
LevelDB和CouchDB的选择

State database options include LevelDB and CouchDB (beta). LevelDB is the default key/value state database embedded in the peer process. CouchDB is an optional alternative external state database. Like the LevelDB key/value store, CouchDB can store any binary data that is modeled in chaincode (CouchDB attachment functionality is used internally for non-JSON binary data). But as a JSON document store, CouchDB additionally enables rich query against the chaincode data, when chaincode values (e.g. assets) are modeled as JSON data.

Both LevelDB and CouchDB support core chaincode operations such as getting and setting a key (asset), and querying based on keys. Keys can be queried by range, and composite keys can be modeled to enable equivalence queries against multiple parameters. For example a composite key of (owner,asset_id) can be used to query all assets owned by a certain entity. These key-based queries can be used for read-only queries against the ledger, as well as in transactions that update the ledger.

If you model assets as JSON and use CouchDB, you can also perform complex rich queries against the chaincode data values, using the CouchDB JSON query language within chaincode. These types of queries are excellent for understanding what is on the ledger. Proposal responses for these types of queries are typically useful to the client application, but are not typically submitted as transactions to the ordering service. In fact, there is no guarantee the result set is stable between chaincode execution and commit time for rich queries, and therefore rich queries are not appropriate for use in update transactions, unless your application can guarantee the result set is stable between chaincode execution time and commit time, or can handle potential changes in subsequent transactions. For example, if you perform a rich query for all assets owned by Alice and transfer them to Bob, a new asset may be assigned to Alice by another transaction between chaincode execution time and commit time, and you would miss this ‘phantom’ item.

CouchDB runs as a separate database process alongside the peer, therefore there are additional considerations in terms of setup, management, and operations. You may consider starting with the default embedded LevelDB, and move to CouchDB if you require the additional complex rich queries. It is a good practice to model chaincode asset data as JSON, so that you have the option to perform complex rich queries if needed in the future.

To enable CouchDB as the state database, configure the /fabric/sampleconfig/core.yaml stateDatabase section.

13.
Erlang

14.
Make

你可能感兴趣的:(hyperledge,2017,blockchain)