EOS 本地环境

1. 获取代码

下载EOS源代码及其两个子模块以完整下载整个项目。通过递归克隆是最快的方式:

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

如果克隆时不添加--recursive 选项,则子模块可通过在此仓库中运行如下命令再获取:

$ git submodule update --init --recursive

2. 构建EOS

2.1. 自动构建脚本

Ubuntu 16.10与MacOS Sierra均有自动构建脚本,脚本将自动安装所有依赖并构建EOS。

脚本名为 build.sh,支持以下选项:

  • architecture [ubuntu|darwin]
  • optional mode [full|build]

第一个选项决定构建脚本是在哪个架构平台上运行,MacOS选择"darwin",Ubuntu选择"ubuntu"。
第二个选项可输入"full"或"build","build"仅构建EOS,而"full"安装所有依赖后再进行构建。默认值为"full"。

$ ./build.sh ${architecture} ${optional_mode}

按如下步骤递归克隆EOS仓库后并执行eos文件夹下的build.sh脚本。

2.1.1. Ubuntu 16.10

完全构建

$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ ./build.sh ubuntu full 

增量构建

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

$ cd eos
$ ./build.sh ubuntu 

下一步请见创造并启动一个单节点测试网络

2.1.2. MacOS Sierra

运行前请安装并升级XCode和brew:

$ xcode-select --install
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

完全构建

$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ build.sh darwin full

增量构建

$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ build.sh darwin

下一步请见创造并启动一个单节点测试网络

2.2. 手动构建脚本

2.2.1 从源代码构建

推荐使用上面的build.sh构建,但如果您希望自己构建,请按如下步骤操作:
使用环境变量WASM_LLVM_CONFIG来寻找我们最近构建的WASM编译器。我们需要它来编译eos/contracts 文件夹下的样例合约及相应测试。

$ cd ~
$ git clone https://github.com/eosio/eos --recursive
$ mkdir -p ~/eos/build && cd ~/eos/build
$ cmake -DBINARYEN_BIN=~/binaryen/bin -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib ..
$ make -j4

项目也支持外部编译。若要更改clang的默认编译器,向CMake添加如下选项即可:

-DCMAKE_CXX_COMPILER=/path/to/c++ -DCMAKE_C_COMPILER=/path/to/cc

对调试时的构建,请添加-DCMAKE_BUILD_TYPE=Debug。其他的常用构建类型有ReleaseRelWithDebInfo

若要构建后运行测试,请运行tests文件夹下的chain_test文件。

EOS的~/eos/build/programs文件夹下包含多个程序,如下所列:

  • eosd - 服务器端区块链节点组件
  • eosc - 和区块链交互的命令行接口
  • eos-walletd - EOS钱包
  • launcher - 用于多节点网络构建和部署 更多信息

手动安装依赖

如果您想手动安装依赖,请按如下步骤操作

本工程主要是用C++14编写并使用CMake作为构建系统。推荐使用最新Clang和CMake。

依赖:

2.2.2 在Ubuntu 16.10从头安装

安装开发工具包:

$ sudo apt-get update
$ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
$ sudo apt-get install clang-4.0 lldb-4.0 libclang-4.0-dev cmake make \
                     libbz2-dev libssl-dev libgmp3-dev \
                     autotools-dev build-essential \
                     libbz2-dev libicu-dev python-dev \
                     autoconf libtool git

安装Boost 1.64:

$ cd ~
$ wget -c 'https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.bz2/download' -O boost_1.64.0.tar.bz2
$ tar xjf boost_1.64.0.tar.bz2
$ cd boost_1_64_0/
$ echo "export BOOST_ROOT=$HOME/opt/boost_1_64_0" >> ~/.bash_profile
$ source ~/.bash_profile
$ ./bootstrap.sh "--prefix=$BOOST_ROOT"
$ ./b2 install
$ source ~/.bash_profile

安装 secp256k1-zkp (Cryptonomex branch):

$ cd ~
$ git clone https://github.com/cryptonomex/secp256k1-zkp.git
$ cd secp256k1-zkp
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install

为了使用WASM编译器, EOS需要外部依赖binaryen:

$ cd ~
$ git clone https://github.com/WebAssembly/binaryen.git
$ cd ~/binaryen
$ git checkout tags/1.37.14
$ cmake . && make

BINARYEN_ROOT添加到您的.bash_profile:

$ echo "export BINARYEN_ROOT=~/binaryen" >> ~/.bash_profile
$ source ~/.bash_profile

默认情况下LLVM和clang并不编译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

至此环境配置完毕,您可以构建EOS并启动节点了

2.2.3 MacOS Sierra 10.12.6

macOS 额外依赖:

  • Brew
  • Newest XCode

将您的XCode升级到最新版本:

$ xcode-select --install

安装homebrew:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装依赖:

$ brew update
$ brew install git automake libtool boost openssl llvm@4 gmp ninja gettext
$ brew link gettext --force

安装 secp256k1-zkp (Cryptonomex branch):

$ cd ~
$ git clone https://github.com/cryptonomex/secp256k1-zkp.git
$ cd secp256k1-zkp
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install

安装 binaryen v1.37.14:

$ cd ~
$ git clone https://github.com/WebAssembly/binaryen.git
$ cd ~/binaryen
$ git checkout tags/1.37.14
$ cmake . && make

BINARYEN_ROOT添加到您的.bash_profile:

$ echo "export BINARYEN_ROOT=~/binaryen" >> ~/.bash_profile
$ source ~/.bash_profile

为WASM构建 LLVM and clang:

$ 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

WASM_LLVM_CONFIGLLVM_DIR添加到您的.bash_profile:

$ echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
$ echo "export LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm" >> ~/.bash_profile
$ source ~/.bash_profile

3. Docker

也可通过Docker简单快速地安装EOS。

3.1. 安装依赖

3.2. 构建eos image

$ git clone https://github.com/EOSIO/eos.git --recursive
$ cd eos/Docker
$ docker build . -t eosio/eos

3.3. 仅启动eosd docker容器

$ docker run --name eosd -p 8888:8888 -p 9876:9876 -t eosio/eos start_eosd.sh arg1 arg2

默认情况下,所有数据均存在一个docker volume中,如果数据过时或损坏可能会被删除。

$ docker inspect --format '{{ range .Mounts }}{{ .Name }} {{ end }}' eosd
fdc265730a4f697346fa8b078c176e315b959e79365fc9cbd11f090ea0cb5cbc
$ docker volume rm fdc265730a4f697346fa8b078c176e315b959e79365fc9cbd11f090ea0cb5cbc

或者您可以直接将host目录挂在到容器里

$ docker run --name eosd -v /path-to-data-dir:/opt/eos/bin/data-dir -p 8888:8888 -p 9876:9876 -t eosio/eos start_eosd.sh arg1 arg2

3.4. 获取链信息

$ curl http://127.0.0.1:8888/v1/chain/get_info

3.5. 启动eosd和walletd容器

$ docker-compose up

docker-compose up后,eosd 和 walletd 将会启动。eosd服务将起在host的8888和9876端口。walletd 并不暴露在host的任何端口上,它只能如“执行eosc命令”一节所述,通过在walletd容器内运行eosc来交互。

3.5.1. 执行eosc命令

您可通过bash alias来运行eosc命令

$ alias eosc='docker-compose exec walletd /opt/eos/bin/eosc -H eosd'
$ eosc get info
$ eosc get account inita

上传样例中的exchange contract

$ eosc set contract exchange contracts/exchange/exchange.wast contracts/exchange/exchange.abi

如果您不再需要walletd了,您可以停止walletd服务:

$ docker-compose stop walletd

3.5.2. 更改默认配置

你可以使用docker compose覆盖配置文件,改变默认配置。例如,新建如下的配置文件config2.inidocker-compose.override.yml

version: "2"

services:
  eosd:
    volumes:
      - eosd-data-volume:/opt/eos/bin/data-dir
      - ./config2.ini:/opt/eos/bin/data-dir/config.ini

然后如下重启docker容器:

$ docker-compose down
$ docker-compose up

3.5.3. 清除 data-dir

docker-compose创造的data volume可删除:

$ docker volume rm docker_eosd-data-volume

4. 创造并启动一个单节点测试网络

成功构建工程后,build/programs/eosd文件夹下应当有名为eosd的二进制文件。运行eosd,-- 它可能会报错退出,但如果没有,立即通过Ctrl-C关闭。注意eosd将产生一个名为data-dir,含有默认配置文件(config.ini)及一些其他内部文件的文件夹。如果要更改这个默认数据存储路径,请在eosd中通过--data-dir /path/to/data配置。

编辑config.ini文件,在现有配置下新增如下设置:

# Load the testnet genesis state, which creates some initial block producers with the default key
genesis-json = /path/to/eos/source/genesis.json
 # Enable production on a stale chain, since a single-node test chain is pretty much always stale
enable-stale-production = true
# Enable block production with the testnet producers
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
# Load the block producer plugin, so you can produce blocks
plugin = eosio::producer_plugin
# Wallet plugin
plugin = eosio::wallet_api_plugin
# As well as API and HTTP plugins
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin

现在我们应当可以运行eosd并看到它生成区块了。

当运行eosd时,您应当看到如下日志输出,这意味着区块被成功产生出来了。

1575001ms thread-0   chain_controller.cpp:235      _push_block          ] initm #1 @2017-09-04T04:26:15  | 0 trx, 0 pending, exectime_ms=0
1575001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initm generated block #1 @ 2017-09-04T04:26:15 with 0 trxs  0 pending
1578001ms thread-0   chain_controller.cpp:235      _push_block          ] initc #2 @2017-09-04T04:26:18  | 0 trx, 0 pending, exectime_ms=0
1578001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initc generated block #2 @ 2017-09-04T04:26:18 with 0 trxs  0 pending
...

5. 常见问题

  1. 当尝试启动eosd时,产生St9exception: content of memory does not match data expected by executable报错

尝试添加--resync选项重启eosd

  1. 如何知道我运行或正在连接的eosd版本?

使用eosc -H ${eosd_host} -p ${eosd_port} get info,您将看到server_version字段

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,425评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,058评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,186评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,848评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,249评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,554评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,830评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,536评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,239评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,505评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,004评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,346评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,999评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,060评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,821评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,574评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,480评论 2 267