- 1 獲取代碼
- 2 構(gòu)建EOS
- 3 Docker
- 4 創(chuàng)造并啟動(dòng)一個(gè)單節(jié)點(diǎn)測(cè)試網(wǎng)絡(luò)
- 5 常見(jiàn)問(wèn)題
1. 獲取代碼
下載EOS源代碼及其兩個(gè)子模塊以完整下載整個(gè)項(xiàng)目肄鸽。通過(guò)遞歸克隆是最快的方式:
$ git clone https://github.com/eosio/eos --recursive
如果克隆時(shí)不添加--recursive
選項(xiàng),則子模塊可通過(guò)在此倉(cāng)庫(kù)中運(yùn)行如下命令再獲取:
$ git submodule update --init --recursive
2. 構(gòu)建EOS
2.1. 自動(dòng)構(gòu)建腳本
Ubuntu 16.10與MacOS Sierra均有自動(dòng)構(gòu)建腳本,腳本將自動(dòng)安裝所有依賴并構(gòu)建EOS。
腳本名為 build.sh榛瓮,支持以下選項(xiàng):
- architecture [ubuntu|darwin]
- optional mode [full|build]
第一個(gè)選項(xiàng)決定構(gòu)建腳本是在哪個(gè)架構(gòu)平臺(tái)上運(yùn)行,MacOS選擇"darwin",Ubuntu選擇"ubuntu"嗤栓。
第二個(gè)選項(xiàng)可輸入"full"或"build","build"僅構(gòu)建EOS,而"full"安裝所有依賴后再進(jìn)行構(gòu)建茉帅。默認(rèn)值為"full"叨叙。
$ ./build.sh ${architecture} ${optional_mode}
按如下步驟遞歸克隆EOS倉(cāng)庫(kù)后并執(zhí)行eos文件夾下的build.sh腳本。
2.1.1. Ubuntu 16.10
完全構(gòu)建
$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ ./build.sh ubuntu full
增量構(gòu)建
$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ ./build.sh ubuntu
下一步請(qǐng)見(jiàn)創(chuàng)造并啟動(dòng)一個(gè)單節(jié)點(diǎn)測(cè)試網(wǎng)絡(luò)
2.1.2. MacOS Sierra
運(yùn)行前請(qǐng)安裝并升級(jí)XCode和brew:
$ xcode-select --install
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
完全構(gòu)建
$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ build.sh darwin full
增量構(gòu)建
$ git clone https://github.com/eosio/eos --recursive
$ cd eos
$ build.sh darwin
下一步請(qǐng)見(jiàn)創(chuàng)造并啟動(dòng)一個(gè)單節(jié)點(diǎn)測(cè)試網(wǎng)絡(luò)
2.2. 手動(dòng)構(gòu)建腳本
2.2.1 從源代碼構(gòu)建
推薦使用上面的build.sh構(gòu)建堪澎,但如果您希望自己構(gòu)建擂错,請(qǐng)按如下步驟操作:
使用環(huán)境變量WASM_LLVM_CONFIG來(lái)尋找我們最近構(gòu)建的WASM編譯器。我們需要它來(lái)編譯eos/contracts
文件夾下的樣例合約及相應(yīng)測(cè)試樱蛤。
$ 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
項(xiàng)目也支持外部編譯钮呀。若要更改clang的默認(rèn)編譯器,向CMake添加如下選項(xiàng)即可:
-DCMAKE_CXX_COMPILER=/path/to/c++ -DCMAKE_C_COMPILER=/path/to/cc
對(duì)調(diào)試時(shí)的構(gòu)建昨凡,請(qǐng)?zhí)砑?code>-DCMAKE_BUILD_TYPE=Debug爽醋。其他的常用構(gòu)建類(lèi)型有Release
和 RelWithDebInfo
。
若要構(gòu)建后運(yùn)行測(cè)試土匀,請(qǐng)運(yùn)行tests
文件夾下的chain_test
文件子房。
EOS的~/eos/build/programs
文件夾下包含多個(gè)程序,如下所列:
- eosd - 服務(wù)器端區(qū)塊鏈節(jié)點(diǎn)組件
- eosc - 和區(qū)塊鏈交互的命令行接口
- eos-walletd - EOS錢(qián)包
- launcher - 用于多節(jié)點(diǎn)網(wǎng)絡(luò)構(gòu)建和部署 更多信息
手動(dòng)安裝依賴
如果您想手動(dòng)安裝依賴就轧,請(qǐng)按如下步驟操作
本工程主要是用C++14編寫(xiě)并使用CMake作為構(gòu)建系統(tǒng)证杭。推薦使用最新Clang和CMake。
依賴:
- Clang 4.0.0
- CMake 3.5.1
- Boost 1.64
- OpenSSL
- LLVM 4.0
- secp256k1-zkp (Cryptonomex branch)
- binaryen
2.2.2 在Ubuntu 16.10從頭安裝
安裝開(kāi)發(fā)工具包:
$ 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
默認(rèn)情況下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
至此環(huán)境配置完畢解愤,您可以構(gòu)建EOS并啟動(dòng)節(jié)點(diǎn)了。
2.2.3 MacOS Sierra 10.12.6
macOS 額外依賴:
- Brew
- Newest XCode
將您的XCode升級(jí)到最新版本:
$ 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
$ 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構(gòu)建 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
也可通過(guò)Docker簡(jiǎn)單快速地安裝EOS乎莉。
3.1. 安裝依賴
- Docker Docker 17.05以上
3.2. 構(gòu)建eos image
$ git clone https://github.com/EOSIO/eos.git --recursive
$ cd eos/Docker
$ docker build . -t eosio/eos
3.3. 僅啟動(dòng)eosd docker容器
$ docker run --name eosd -p 8888:8888 -p 9876:9876 -t eosio/eos start_eosd.sh arg1 arg2
默認(rèn)情況下送讲,所有數(shù)據(jù)均存在一個(gè)docker volume中,如果數(shù)據(jù)過(guò)時(shí)或損壞可能會(huì)被刪除惋啃。
$ 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. 啟動(dòng)eosd和walletd容器
$ docker-compose up
在docker-compose up
后哼鬓,eosd 和 walletd 將會(huì)啟動(dòng)。eosd服務(wù)將起在host的8888和9876端口边灭。walletd 并不暴露在host的任何端口上异希,它只能如“執(zhí)行eosc命令”一節(jié)所述,通過(guò)在walletd容器內(nèi)運(yùn)行eosc來(lái)交互绒瘦。
3.5.1. 執(zhí)行eosc命令
您可通過(guò)bash alias來(lái)運(yùn)行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服務(wù):
$ docker-compose stop walletd
3.5.2. 更改默認(rèn)配置
你可以使用docker compose覆蓋配置文件,改變默認(rèn)配置惰帽。例如憨降,新建如下的配置文件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創(chuàng)造的data volume可刪除:
$ docker volume rm docker_eosd-data-volume
4. 創(chuàng)造并啟動(dòng)一個(gè)單節(jié)點(diǎn)測(cè)試網(wǎng)絡(luò)
成功構(gòu)建工程后,build/programs/eosd
文件夾下應(yīng)當(dāng)有名為eosd
的二進(jìn)制文件该酗。運(yùn)行eosd
授药,-- 它可能會(huì)報(bào)錯(cuò)退出,但如果沒(méi)有,立即通過(guò)Ctrl-C
關(guān)閉悔叽。注意eosd
將產(chǎn)生一個(gè)名為data-dir
航邢,含有默認(rèn)配置文件(config.ini
)及一些其他內(nèi)部文件的文件夾。如果要更改這個(gè)默認(rèn)數(shù)據(jù)存儲(chǔ)路徑骄蝇,請(qǐng)?jiān)?code>eosd中通過(guò)--data-dir /path/to/data
配置。
編輯config.ini
文件操骡,在現(xiàn)有配置下新增如下設(shè)置:
# 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
現(xiàn)在我們應(yīng)當(dāng)可以運(yùn)行eosd
并看到它生成區(qū)塊了九火。
當(dāng)運(yùn)行eosd
時(shí),您應(yīng)當(dāng)看到如下日志輸出册招,這意味著區(qū)塊被成功產(chǎn)生出來(lái)了岔激。
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. 常見(jiàn)問(wèn)題
- 當(dāng)嘗試啟動(dòng)
eosd
時(shí),產(chǎn)生St9exception: content of memory does not match data expected by executable
報(bào)錯(cuò)
嘗試添加
--resync
選項(xiàng)重啟eosd
- 如何知道我運(yùn)行或正在連接的
eosd
版本?
使用
eosc -H ${eosd_host} -p ${eosd_port} get info
是掰,您將看到server_version
字段