eos程序员EOS开发系列

区块链技术EOS开发系列之Mac下的编译

2017-07-27  本文已影响3246人  菠菜期权

本文档更新于: 2017.7.30,本文最新版请查看http://www.jianshu.com/p/f26ee4cf1d4a

更新:随着eos代码快速迭代,直接查看https://github.com/EOSIO/eos

2018.1 3日更新:现在官方提供脚本,把该文的过程自动化了https://www.jianshu.com/p/81cd8dbe387a

什么是EOS?

EOS.IO 软件引入一种新的区块链架构设计,它使得去中心化的应用可以横向和纵向的扩展。 这通过构建一个仿操作系统的方式来实现,在它之上可以构建应用程序。 该软件提供帐户、身份验证、数据库、异步通信和跨越数百个 CPU 内核或集群的应用程序调度。 由此产生的技术是一种区块链架构,它可以扩展至每秒处理百万级交易,消除用户的手续费,并且允许快速和轻松的部署去中心化的应用。

EOS.IO 技术白皮书中文版 https://github.com/EOSIO/Documentation/blob/master/zh-CN/TechnicalWhitePaper.md

为什么接触EOS?

自2013年开始参与比特币BTC相关项目的开发,愚见BTC适合做基础货币, 脚本系统相对ETH太难用;2014年读完以太坊ETH白皮书后参与了ETH的众筹,愚见ETH适合做智能合约;最近读完EOS白皮书受到一些启发,比如EOS中借鉴引入的lmax流水线架构和笔者之前从事的交易所撮合引擎研发有交集,对于EOS抽象公共组件的区块链架构设计方向也颇感兴趣,笔者接触到的一些ICO项目的负责人,吐槽他们项目的落地迫切需要一个区块链基础系统,但是由于他们自身团队技术水平限制单纯只想通过调用区块链相关的API实现他们的应用,而不想也没有能力从头开始造轮子,有的应用对性能要求还颇高,但是无论是BTC还是ETH目前暂时还不能满足这种来自应用层的迫切需求。

总结一下,目前区块链有几个亟待解决的问题:难以扩展(目前区块链世界好像没有比Bitcoin扩容之争更重要的事情),代价昂贵(以太坊对使用其网络的用户收取燃气费用)、缺乏互操作性,而且很难为传统公司所用。 区块链技术正在重新定义整个互联网,但对于大多数公司所有人来说,没有简单实用的方法来采用这种全新的革命性技术。EOS白皮书声称将会解决这些问题,它的目标是方便大量公司快速创建一个区块链操作系统。

以上是我决定持续跟踪EOS的技术进展的原因。


EOS的Mac下编译过程

EOS支持在Linux, Mac, Windows 等平台编译运行,该文只涉及Mac下的编译流程。由于Mac用的Unix内核,所以编译过程基本与Ubuntu类似,最大的不同的是环境的准备过程和踩坑不同。

1.环境准备:

1.1要先安装好Xcode, 然后执行

xcode-select --install

1.2安装 homebrew http://brew.sh/

1.3然后,在Mac的shell下用brew安装依赖库:

brew install autoconf automake libtool boost openssl pkg-config

大坑注意:因为新版mac已经移除openssl,这里我们安装完需要配置下环境变量OPENSSL_ROOT_DIR和OPENSSL_INCLUDE_DIR:

export OPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2k

export OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2k/includes

若用bash shell,则.bash_profile在后面追加上以上的export,然后执行source ~/.bash_profile

若用zsh shell,则.zshrc在后面追加以上的export,然后执行source ~/.zshrc

2.安装依赖secp256k1-zkp:

secp256k1-zkp (Cryptonomex branch)

git clone https://github.com/cryptonomex/secp256k1-zkp.git

cd secp256k1-zkp

./autogen.sh

./configure

make

sudo make install

3.准备wasm:

mkdir  ~/wasm-compiler

cd ~/wasm-compiler

git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git

cd llvm/tools

git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git

cd ..

mkdir build

cd build

cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../

make -j4 install

4.配置LLVM:

以zsh为例:

echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/build/bin/llvm-config" >> ~/.zshrc

echo "export LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm" >> ~/.zshrc

source ~/.zshrc

5. 克隆eos源代码并进入其目录

git clone https://github.com/eosio/eos --recursive

mkdir -p eos/build && cd eos/build

cmake ..  #试版本编译:cmake . -DCMAKE_BUILD_TYPE=Debug

make -j4

6. 在tests执行编译好的chain_test

./tests/chain_test

7.执行eosd

c d programs/

./eosd/eosd

此时会生成./data-dir/config.ini默认配置并报错,按Ctrl+C,然后修改生成的配置文件

vi ./data-dir/config.ini

# File to read Genesis State from

genesis-json = /YOUR_PATH/eos/genesis.json

# override the initial timestamp in the Genesis State file

# genesis-timestamp =

# the location of the block log (absolute path or relative to application data dir)

block-log-dir = "blocks"

# Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.

# checkpoint =

# open the database in read only mode

readonly = 0

# the location of the chain shared memory files (absolute path or relative to application data dir)

shared-file-dir = "blockchain"

# Minimum size MB of database shared memory file

shared-file-size = 8192

# The local IP and port to listen for incoming http connections.

http-server-endpoint = 127.0.0.1:8888

# The local IP address and port to listen for incoming connections.

listen-endpoint = 0.0.0.0:9876

# The IP address and port of a remote peer to sync with.

# remote-endpoint =

# Overrides the advertised listen endpointlisten ip address.

# public-endpoint =

# The name supplied to identify this node amongst the peers.

agent-name = EOS Test Agent

# Enable block production, even if the chain is stale.

enable-stale-production = true

# Percent of producers (0-99) that must be participating in order to produce blocks

required-participation = false

# ID of producer controlled by this node (e.g. "inita", quotes are required, may specify multiple times)

# producer-name =

producer-name = inita

producer-name = initb

producer-name = initc

producer-name = initd

producer-name = inite

producer-name = initf

producer-name = initg

producer-name = inith

producer-name = initi

producer-name = initj

producer-name = initk

producer-name = initl

producer-name = initm

producer-name = initn

producer-name = inito

producer-name = initp

producer-name = initq

producer-name = initr

producer-name = inits

producer-name = initt

producer-name = initu

# Tuple of [PublicKey, WIF private key] (may specify multiple times)

private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

# Plugin(s) to enable, may be specified multiple times

# plugin =

plugin = eos::producer_plugin

#for eosc command

plugin = eos::chain_api_plugin

然后重新运行

./eosd/eosd

eosd运行图

运行成功。

运行eosc试试:

➜  programs git:(master) ./eosc/eosc info

{

"head_block_num": 902,

"last_irreversible_block_num": 885,

"head_block_id": "000003863abf62f265dc9b90201e77b24e34324e2a8e963e82bd11149c51b9d6",

"head_block_time": "2017-07-30T11:34:27",

"head_block_producer": "inito",

"recent_slots": "0000000000000000000000000000000000000000000000000000000000000011",

"participation_rate": "0.03125000000000000"

}

over!

编译来来回回耗费了三天,校验重试了估计得30次才搞定,也是醉了,主要是llvm的配置问题,好运。


反参考:

http://www.jianshu.com/p/f26ee4cf1d4a

https://steemit.com/eosdev/@skenan/eos-build-guide-on-mac-os

https://steemit.com/eoskorea/@clayop/eos-build-guide-on-ubunbu

https://github.com/EOSIO/eos

https://github.com/EOSIO/eos/issues/99

大家可以通过一下方式跟踪关注我:

github:https://github.com/philsong

微博:http://weibo.com/bocaicfa

本文是EOS技术研究系列的第一篇。

第一篇.Mac下的编译:http://www.jianshu.com/p/f26ee4cf1d4a

第二篇.eosc命令行工具:http://www.jianshu.com/p/b2db966435d0

第三篇.appbase库:http://www.jianshu.com/p/b7f0bbe89610

第四篇.chainbase库与database_plugin插件:http://www.jianshu.com/p/df835b574b52

第五篇.如何开发合约发行代币:http://www.jianshu.com/p/5228da9c5631

第六篇.块,交易等结构:http://www.jianshu.com/p/d5ef6280b94d


区块链技术EOS开发系列之Mac下的编译
上一篇 下一篇

猜你喜欢

热点阅读