EOS 本地环境
1. 获取代码
下载EOS源代码及其两个子模块以完整下载整个项目。通过递归克隆是最快的方式:
$ 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"。
$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ ./build.sh ubuntu full
增量构建
$ 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_CONFIG 和 LLVM_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. 安装依赖
- Docker Docker 17.05以上
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.ini和docker-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
2、如何知道我运行或正在连接的eosd版本?
使用
eosc -H ${eosd_host} -p ${eosd_port} get info,您将看到server_version字段
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
