17. blockchain

区块链

17.1. 热门的区块链技术

  1. bitcoin(数字货币) [1]

    这是最早也是最有名的区块链实施项目。一种可保存在电子钱包中的数字货币。

  2. Ripple(区块链技术平台)

    Ripple 能提供全天候、实时、同步、透明且信息丰富的交易。在交易开始前,您能够实时确认汇率和费用,立即完成付款。 Ripple 解决方案为 MasterCard 和 Visa 等发卡机构整合了付款消息传递和资金结算功能

  3. Ethereum(数字货币)

    扩展比特币平台,让比特币能处理数字货币以外的普通交易。为了做到这一点,他们需要一个强大的脚本语言,来编写“智能合同”中的业务逻辑。由于没有与比特币团队达成共识,Vitalik 另起炉灶,启动了一个新平台的开发,也就是我们所说的Ethereum。 Ethereum 的首个生产版本于 2015 年 7 月发布。Ethereum 支持一种名为 Ether 的加密货币。

  4. Hyperledger(区块链技术平台)

    Hyperledger 的重心是为企业构建区块链平台。考虑到支持数字货币所带来的风险,Hyperledger 决定不涉足该领域。这是它与 Ethereum 的一大区别。它的设计重点放在安全性、可扩展性和隐私上面,其他实施项目(如 Ethereum)同样面临这些挑战。巨头参与,比如 IBM,因特尔,埃森哲,摩根大通,富国银行,空客,三星集团

  5. ipfs/filecoin [2]

    星际文件系统IPFS(Inter-Planetary File System)是一个面向全球的、点对点的分布式版本文件系统,目标是为了补充(甚至是取代)目前统治互联网的超文本传输协议(HTTP),将所有具有相同文件系统的计算设备连接在一起。原理用基于内容的地址替代基于域名的地址,也就是用户寻找的不是某个地址而是储存在某个地方的内容,不需要验证发送者的身份,而只需要验证内容的哈希,通过这样可以让网页的速度更快、更安全、更健壮、更持久。

    filecoin [3] 是ipfs上的一个代币,而filecoin就是通过贡献闲置的硬盘来作为奖励矿工的一种方式。Filecoin采用了一种全新的算法(工作量证明),简单的来说,就是你拥有的硬盘容量够大,那么你获取的filecoin奖励就越多

  6. Dragonchain

    龙链(Dragonchain)是迪士尼打造的混合公有/私有区块链的区块链平台。 龙链是另一种用来保持记录和处理交易的区块链。它与比特币的底层技术十分相似,但又有一点不同。龙链是一种多币制的区块链,节点就可以随之定义一种货币并支持其使用。该网络上可以同时使用多种货币。龙链的共识机制可以支持一种或多种现有的共识机制(Trust,PoW,PoS),甚至是可以支持自己定义和创建一种新的共识机制。

区块链统计
区块链应用 厂商 支持语言 部署方式
bitcoin 开源社区 C/C++ 公有云
Ripple Ripple C++、python 公有云或者私有云
Ethereum 开源社区 Solidity、Python 、 C++ 和 Java 公有云(Azure, AWS)
Hyperledger 开源社区,linux基金会 Go language、 Java 和 JavaScript Docker, IBM bluemix
ipfs 开源社区 Go,JavaScript,Python,C 公有云
Filecoin 开源社区 Go 公有云
Dragonchain 迪士尼->龙链基金会 Go 公有云或私有云
[1]https://bitcoincore.org/
[2]https://filecoin.io/
[3]filecoin 编译安装

18. bitcoin

在ARM上区块链 [4] 的支持情况如何,能否使用比特币。

18.1. 有钱包即可使用比特币

目前钱包应用很多,有手机版,桌面版,专用硬件版,网页版 [5] 。可以根据情况到官网网址进行选择。

这里主要看下桌面版能否支持ARM,在上面的网址下载的安装包是bitcoin-0.19.0.1-arm-linux-gnueabihf.tar.gz。查看里面的二进制文件目前不支持ARM64的。

不过我们在 bitcoin-core的网站上找到了ARM64版本bitcoin-0.19.0.1-aarch64-linux-gnu.tar.gz [6]

下载比特币软件。

wget https://bitcoincore.org/bin/bitcoin-core-0.19.0.1/bitcoin-0.19.0.1-aarch64-linux-gnu.tar.gz
tar xf bitcoin-0.19.0.1-aarch64-linux-gnu.tar.gz
cd bitcoin-0.19.0.1/bin

启动服务,会自动同步区块

./btcoind

 2020-07-16T01:53:17Z dnsseed thread exit
 2020-07-16T01:53:19Z Synchronizing blockheaders, height: 4000 (~0.66%)
 2020-07-16T01:53:21Z New outbound peer connected: version: 70015, blocks=639437, peer=5 (full-relay)
 2020-07-16T01:53:22Z New outbound peer connected: version: 70015, blocks=639437, peer=6 (full-relay)
 2020-07-16T01:53:23Z New outbound peer connected: version: 70015, blocks=639437, peer=7 (full-relay)
 2020-07-16T01:53:25Z New outbound peer connected: version: 70015, blocks=639437, peer=8 (full-relay)
 2020-07-16T01:53:33Z Synchronizing blockheaders, height: 6000 (~0.99%)
 2020-07-16T01:53:37Z Synchronizing blockheaders, height: 8000 (~1.33%)
 2020-07-16T01:53:43Z Synchronizing blockheaders, height: 10000 (~1.66%)
 2020-07-16T01:53:50Z Synchronizing blockheaders, height: 12000 (~1.99%)
 2020-07-16T01:53:53Z Synchronizing blockheaders, height: 14000 (~2.33%)
 2020-07-16T01:53:57Z Synchronizing blockheaders, height: 16000 (~2.66%)
 2020-07-16T01:54:06Z Synchronizing blockheaders, height: 18000 (~3.00%)
 2020-07-16T01:54:14Z Synchronizing blockheaders, height: 20000 (~3.35%)

同步数据可能需要很长时间,少则一两个小时,多则10多个小时,取决于和服务器的链接速度。

获取钱包地址: 3a0f7a2e3ba2e1d4810db537959421be866c1f6c ::

[user1@centos bin]$ ./bitcoin-cli getwalletinfo
{
  "walletname": "",
  "walletversion": 169900,
  "balance": 0.00000000,
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 0.00000000,
  "txcount": 0,
  "keypoololdest": 1578981187,
  "keypoolsize": 1000,
  "keypoolsize_hd_internal": 1000,
  "paytxfee": 0.00000000,
  "hdseedid": "3a0f7a2e3ba2e1d4810db537959421be866c1f6c",
  "private_keys_enabled": true,
  "avoid_reuse": false,
  "scanning": false
}

再创建一个钱包

root@40ab90fdd8df:~/bitcoin-0.19.0.1/bin# ./bitcoin-cli createwallet redwallet
{
"name": "redwallet",
"warning": ""
}

18.2. 常用命令

  1. bitcoin-cli
bitcoin-cli getwalletinfo       # 获取钱包信息
bitcoin-cli getnetworkinfo      # 查看网络状态:
bitcoin-cli getpeerinfo         # 查看网络节点:
bitcoin-cli getblockchaininfo   # 查看区块链信息:如同步进度、
bitcoin-cli help                # 查看所有命令
  1. bitcoind
./bitcoind                      # 启动比特币服务
./bitcoind -c                   # 以配置文件启动后台服务

18.3. 搭建运行自定义区块链服务

区块链可以取消中间人,可以实现peer-to-peer的交易。

主要在金融领域应用和论证。全球范围内超过 90% 的中央银行已经开始了这方面的论证

[4]https://github.com/bitcoin/bitcoin
[5]https://bitcoin.org/zh_CN/choose-your-wallet?step=5&platform=linux
[6]https://bitcoincore.org/bin/bitcoin-core-0.19.0.1/

19. filecoin

去中心化的存储网络

filecoin 目前没有ARM64版本。

[user1@centos filecoin]$ pwd
/home/user1/open_software/filecoin-release/filecoin
[user1@centos filecoin]$ file ./*
./go-filecoin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=357de502b13f0450cbe7b1fc0ed73fadffe9e1f5, not stripped
./paramcache:  ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=1c5add2b39bb2cd4c383af6cbef91fe9c4495af3, not stripped

filecoin的编译需要下载很多go模块, 被屏蔽。

[user1@centos go-filecoin]$
[user1@centos go-filecoin]$ FILECOIN_USE_PRECOMPILED_RUST_PROOFS=true go run ./build                                                                                                                     uild deps
pkg-config --version
0.27.1
Installing dependencies...
go mod download
 13.32 KiB / 13.32 KiB [===============================] 100.00% 100.43 KiB/s 0s
 147.90 MiB / 147.90 MiB [================================================================================================================================================] 100.00% 588.52 KiB/s 4m17s
 4.88 KiB / 4.88 KiB [========================================================================================================================================================] 100.00% 27.33 KiB/s 0s
 13.32 KiB / 13.32 KiB [======================================================================================================================================================] 100.00% 81.60 KiB/s 0s
 4.88 KiB / 4.88 KiB [========================================================================================================================================================] 100.00% 55.46 MiB/s 0s
 13.32 KiB / 13.32 KiB [=====================================================================================================================================================] 100.00% 378.19 KiB/s 0s
 2.04 GiB / 2.48 GiB [=======================================================================================================================>--------------------------]  82.07% 587.53 KiB/s 1h0m35s
 4.88 KiB / 4.88 KiB [========================================================================================================================================================] 100.00% 10.93 MiB/s 0s
 4.88 KiB / 4.88 KiB [========================================================================================================================================================] 100.00% 44.05 MiB/s 0s
 4.88 KiB / 4.88 KiB [===============================

执行成功出现:

                                 Dload  Upload   Total   Spent    Left  Speed
100 9498k  100 9498k    0     0   548k      0  0:00:17  0:00:17 --:--:--  593k
+ [[ 0 -ne 0 ]]
+ eval 'tarball_path='\''/tmp/filecoin-ffi-Linux_16941733.tar.gz'\'''
++ tarball_path=/tmp/filecoin-ffi-Linux_16941733.tar.gz
++ mktemp -d
+ tmp_dir=/tmp/tmp.hWE9Bq7GHa
+ tar -C /tmp/tmp.hWE9Bq7GHa -xzf /tmp/filecoin-ffi-Linux_16941733.tar.gz
+ find -L /tmp/tmp.hWE9Bq7GHa -type f -name filecoin.h -exec cp -- '{}' . ';'
+ find -L /tmp/tmp.hWE9Bq7GHa -type f -name libfilecoin.a -exec cp -- '{}' . ';'
+ find -L /tmp/tmp.hWE9Bq7GHa -type f -name filecoin.pc -exec cp -- '{}' . ';'
+ echo 'successfully installed prebuilt libfilecoin'
successfully installed prebuilt libfilecoin

19.1. filecoine工程分析

lotus---------------------------------主工程 https://github.com/filecoin-project/lotus.git
|-- extern
|   |-- filecoin-ffi------------------向量化 https://github.com/filecoin-project/filecoin-ffi.git
|   |                                 filcrypto.h filcrypto.pc libfilcrypto.a
|   |
|   `-- serialization-vectors---------rust库 https://github.com/filecoin-project/serialization-vectors

19.2. 问题记录

19.2.1. 缺少opencl

# github.com/filecoin-project/filecoin-ffi
/opt/rh/devtoolset-8/root/usr/libexec/gcc/aarch64-redhat-linux/8/ld: cannot find -lOpenCL
collect2: error: ld returned 1 exit status

解决办法

sudo dnf install -y ocl-icd-devel.aarch64

19.2.2. 输入文件是x86的

lecoin.a(futures_cpupool-1f3bf26aa9279af0.futures_cpupool.ahnnhqyk-cgu.3.rcgu.o)' is incompatible with aarch64 output
/opt/rh/devtoolset-8/root/usr/libexec/gcc/aarch64-redhat-linux/8/ld: i386:x86-64 architecture of input file `/home/user1/open_software/gopath/src/github.com/filecoin-project/go-filecoin/vendors/filecoin-ffi/libfilecoin.a(futures_cpupool-1f3bf26aa9279af0.futures_cpupool.ahnnhqyk-cgu.4.rcgu.o)' is incompatible with aarch64 output
/opt/rh/devtoolset-8/root/usr/libexec/gcc/aarch64-redhat-linux/8/ld: i386:x86-64 architecture of input file \`/home/user1/open_software/gopath/src/github.com/filecoin-project/go-filecoin/vendors/filecoin-ffi/libfilecoin.a(qutex-8dfbe8197b98ccc5.qutex.8mzkyvtz-cgu.0.rcgu.o)' is incompatible with aarch64 output
/opt/rh/devtoolset-8/root/usr/libexec/gcc/aarch64-redhat-linux/8/ld: i386:x86-64 architecture of input file `/home/user1/open_software/gopath/src/github.com/filecoin-project/go-filecoin/vendors/filecoin-ffi/libfilecoin.a(qutex-8dfbe8197b98ccc5.qutex.8mzkyvtz-cgu.1.rcgu.o)' is incompatible with aarch64 output
/opt/rh/devtoolset-8/root/usr/libexec/gcc/aarch64-redhat-linux/8/ld: i386:x86-64 architecture of input file `/home/user1/open_software/gopath/src/github.com/filecoin-project/go-filecoin/vendors/filecoin-ffi/libfilecoin.a(blake2s_simd-e06fbb96181f173a.blake2s_simd.cqrh7vav-cgu.11.rcgu.o)' is incompatible with aarch64 output
/opt/rh/devtoolset-8/root/usr/libexec/gcc/aarch64-redhat-linux/8/ld: i386:x86-64 architecture of input file `/home/user1/open_software/gopath/src/github.com/filecoin-project/go-filecoin/vendors/filecoin-ffi/libfilecoin.a(crossbeam_utils-e8dfdc01aecf4d4c.crossbeam_utils.av4hkwzx-cgu.0.rcgu.o)' is incompatible with aarch64 output
/opt/rh/devtoolset-8/root/usr/libexec/gcc/aarch64-redhat-linux/8/ld: i386:x86-64 architecture of input file `/home/user1/open_software/gopath/src/github.com/filecoin-project/go-filecoin/vendors/filecoin-ffi/libfilecoin.a(blake2b_simd-8e21006b644a8dcd.blake2b_simd.du1wdeab-cgu.11.rcgu.o)' is incompatible with aarch64 o

未解决。可能是go编译工程没有成功