EOS主網啓動至今已經超過一個月,然而截至當前,註冊成爲EOS Block Producer(大家習慣稱爲見證人)的賬號僅有393個,活躍的EOS BP節點更是僅有376個,遠遠不如EOS主網上線前我的預期。
來源:https://eosmeta.io/
這裏我們不討論個人啓動EOS BP節點是否有意義,是否有利可圖。僅從技術上講,註冊成爲EOS BP賬號並搭建EOS BP節點的難度也讓很多愛好者望而卻步。同時目前網絡上相關資料,我可以說是幾乎都不準確,要麼是東拼西湊來的,要麼是翻譯官方通用文檔但並不適用於EOS主網。
那麼本篇文章就通過實戰手把手教你如何搭建一個最簡單的EOS BP節點。
首先假設我們已經註冊了EOS賬號,賬號名爲 producer1111 ,且已經通過購買和抵押獲得了基本的RAM,CPU和NET資源。注意,本文中 producer1111 賬戶以及密鑰對均爲虛構,應根據實際情況替換。
安裝DOCKER
Docker可以理解爲應用軟件的運行容器,我們之後會使用Docker運行EOS的應用軟件。我們需要在一臺Mac或Linux主機上安裝Docker,如果你只有Windows主機,那麼請先安裝虛擬機或購買雲主機。
國外的朋友請參照Docker官網進行安裝:
https://docs.docker.com/install/
國內的朋友建議使用Daocloud的服務加速Docker和EOS軟件下載速度:
拉取EOS軟件DOCKER鏡像
$ docker pull eosio/eos Using default tag: latest latest: Pulling from eosio/eos 6b98dfc16071: Already exists 4001a1209541: Already exists 6319fc68c576: Already exists b24603670dc3: Already exists 97f170c87c6f: Already exists ca8277dae3e4: Already exists d9de8ba6e50e: Already exists 1deb6823b375: Pull complete 9c2603092f7e: Pull complete 1300b7a5da6e: Pull complete d2db7bdf8eb8: Pull complete 13d59df8dca8: Pull complete Digest: sha256:cbd42518fc56a699c7e70687c34821fd505e466dc1af25fa6c671e7b4c7dbaf5 Status: Downloaded newer image for eosio/eos:latest
我們拉取官方eosio/eos鏡像的最新版本,本文完成時爲 v1.0.8 。
註冊 PRODUCER1111 賬戶爲EOS BP
啓動並進入容器:
$ docker run -it --rm eosio/eos root@4606b6d1b632:/#
我們使用eosio/eos鏡像啓動了一個臨時EOS軟件容器。
注意之後我們在容器中的命令均以 root@4606b6d1b632:/#
開頭。
創建默認錢包:
root@4606b6d1b632:/# cleos wallet create "/opt/eosio/bin/keosd" launched Creating wallet: default Save password to use in the future to unlock this wallet. Without password imported keys will not be retrievable. "PW5HyYPYshs9vHc8AashiSF17CMKd1ymPXEP5wJbXQHMpR69m5iPd"
導入 producer1111 賬戶的私鑰:
root@4606b6d1b632:/# cleos wallet import 5Kg8jkyxSZ7GSAYGUJ42PugigxEKHpxEaRiWsSu8tgfUb98yxf9 imported private key for: EOS7PD3ykQtKAgkkYb4jrG5fpgZa4RPTUmyq8r31eNdgxwMjUx7sR
註冊EOS BP:
root@4606b6d1b632:/# cleos -u https://mainnet.eoscannon.io system regproducer producer1111 EOS7PD3ykQtKAgkkYb4jrG5fpgZa4RPTUmyq8r31eNdgxwMjUx7sR
這條命令中,我們使用參數 -u https://mainnet.eoscannon.io
爲cleos指定了遠程RPC節點,因此本機不需要啓動nodeos並同步數據。
爲自己投票:
root@4606b6d1b632:/# cleos -u https://mainnet.eoscannon.io system voteproducer prods producer1111 producer1111
登錄 https://eosmonitor.io/ ,查詢 producer1111 賬戶,可看到已更變爲 Producer Account :
來源:https://eosmonitor.io/
此容器中的數據均爲臨時數據,執行 exit
退出並銷燬容器:
root@4606b6d1b632:/# exit exit
配置GENESIS.JSON創世文件
主機中新建 /tmp/eos-work
目錄,並在 /tmp/eos-work
目錄下建立 genesis.json
文件:
$ mkdir -p /tmp/eos-work $ cd /tmp/eos-work $ vim genesis.json
寫入以下信息:
{ "initial_timestamp": "2018-06-08T08:08:08.888", "initial_key": "EOS7EarnUhcyYqmdnPon8rm7mBCTnBoot6o7fE2WzjvEX2TdggbL3", "initial_configuration": { "max_block_net_usage": 1048576, "target_block_net_usage_pct": 1000, "max_transaction_net_usage": 524288, "base_per_transaction_net_usage": 12, "net_usage_leeway": 500, "context_free_discount_net_usage_num": 20, "context_free_discount_net_usage_den": 100, "max_block_cpu_usage": 200000, "target_block_cpu_usage_pct": 1000, "max_transaction_cpu_usage": 150000, "min_transaction_cpu_usage": 100, "max_transaction_lifetime": 3600, "deferred_trx_expiration_window": 600, "max_transaction_delay": 3888000, "max_inline_action_size": 4096, "max_inline_action_depth": 4, "max_authority_depth": 6 } }
主網 genesis.json
文件可以在網絡上找到,內容都是一致,只有使用這些配置,才能創建可以鏈接到EOS主網的區塊鏈。
初始化區塊鏈
啓動並進入容器:
$ docker run -it --rm -v /tmp/eos-work:/eos-work eosio/eos root@4606b6d1b632:/#
我們使用eosio/eos鏡像啓動了一個EOS軟件容器,並將主機 /tmp/eos-work
目錄掛載到容器的 /eos-work
目錄,共享主機與容器的數據,且容器關閉後數據不會丟失,還存在主機中。我們的配置和區塊鏈數據均會存儲在此目錄,上一步的 genesis.json
就在此目錄。
初始化EOS主網區塊鏈:
root@4606b6d1b632:/# nodeos --config-dir /eos-work --data-dir /eos-work --genesis-json /eos-work/genesis.json 1456650ms thread-0 chain_plugin.cpp:209 plugin_initialize ] initializing chain plugin 1456654ms thread-0 chain_plugin.cpp:379 plugin_initialize ] Using genesis state provided in '/eos-work/genesis.json' 1456655ms thread-0 chain_plugin.cpp:385 plugin_initialize ] Starting up fresh blockchain with provided genesis state. CHAINBASE: Failed to pin chainbase shared memory (of size 1024 MB) in RAM. Performance degradation is possible. CHAINBASE: Failed to pin chainbase shared memory (of size 340 MB) in RAM. Performance degradation is possible. 1456692ms thread-0 http_plugin.cpp:331 plugin_initialize ] configured http to listen on 127.0.0.1:8888 1456693ms thread-0 net_plugin.cpp:2948 plugin_initialize ] Initialize net plugin 1456693ms thread-0 net_plugin.cpp:2972 plugin_initialize ] host: 0.0.0.0 port: 9876 1456693ms thread-0 net_plugin.cpp:3044 plugin_initialize ] my node_id is e3f599fdaa9ec53a0481a01200e4fab4613512dbc3b51e18f2f7c5e96d021d86 1456694ms thread-0 main.cpp:104 main ] nodeos version ef654aa3 1456694ms thread-0 main.cpp:105 main ] eosio root is /root/.local/share 1456694ms thread-0 controller.cpp:1212 startup ] No head block in fork db, perhaps we need to replay 1456695ms thread-0 controller.cpp:305 initialize_fork_db ] Initializing new blockchain with genesis state 1456767ms thread-0 chain_plugin.cpp:450 plugin_startup ] starting chain in read/write mode 1456767ms thread-0 chain_plugin.cpp:455 plugin_startup ] Blockchain started; head block is #1, genesis timestamp is 2018-06-08T08:08:08.888 1456768ms thread-0 http_plugin.cpp:376 plugin_startup ] start listening for http requests 1456768ms thread-0 net_plugin.cpp:3056 plugin_startup ] starting listener, max clients is 25 1456768ms thread-0 producer_plugin.cpp:580 plugin_startup ] producer plugin: plugin_startup() begin 1456769ms thread-0 producer_plugin.cpp:607 plugin_startup ] producer plugin: plugin_startup() end
這個命令啓動了nodeos節點程序,並傳入3個參數:
--config-dir /eos-work --data-dir /eos-work --genesis-json /eos-work/genesis.json
nodeos啓動後輸出類似信息說明區塊鏈初始化成功,我們 ctrl+c
退出nodeos,然後在容器中執行 exit
退出關閉容器。
配置EOS BP節點信息
進入主機 /tmp/eos-work
目錄,查看上一步生成的目錄文件:
$ cd /tmp/eos-work $ ll total 32 drwxr-xr-x 5 xxx wheel 160B 7 12 23:24 blocks -rw-r--r-- 1 xxx wheel 9.2K 7 12 23:24 config.ini -rw-r--r-- 1 xxx wheel 816B 7 12 23:01 genesis.json drwxr-xr-x 5 xxx wheel 160B 7 12 23:29 state
config.ini
是由nodeos生成的默認配置文件,搭建 producer1111 賬戶的BP節點最少需要修改以下配置:
# BP賬戶名 producer-name = producer1111 # signature-provider的格式爲${public_key}=KEY:${private_key} signature-provider = EOS7PD3ykQtKAgkkYb4jrG5fpgZa4RPTUmyq8r31eNdgxwMjUx7sR=KEY:5Kg8jkyxSZ7GSAYGUJ42PugigxEKHpxEaRiWsSu8tgfUb98yxf9 # 必要插件 plugin = eosio::chain_plugin plugin = eosio::chain_api_plugin plugin = eosio::producer_plugin plugin = eosio::http_plugin # 可選支持錢包操作 # plugin = eosio::wallet_plugin # plugin = eosio::wallet_api_plugin # 若不希望暴露RPC端口給網外,修改爲127.0.0.1:8888 http-server-address = 0.0.0.0:8888 # 可以添加多個,但是你用到的時候可能已經失效,若沒有一個能用的通信節點,可在網絡上查找 p2p-peer-address = bp.cryptolions.io:9876 p2p-peer-address = p2p.mainnet.eospace.io:88 p2p-peer-address = eu-west-nl.eosamsterdam.net:9876 p2p-peer-address = eosnode.fi:9888 p2p-peer-address = api.eosuk.io:12000 p2p-peer-address = fullnode.eoslaomao.com:443 p2p-peer-address = new.eoshenzhen.io:10034 p2p-peer-address = peer.eosio.sg:9876 p2p-peer-address = eos.nodepacific.com:9876 p2p-peer-address = 18.234.6.119:80 p2p-peer-address = eu1.eosdac.io:49876 p2p-peer-address = br.eosrio.io:9876 p2p-peer-address = p2p-public.hkeos.com:19875 p2p-peer-address = node.eosmeso.io:9876 p2p-peer-address = pub1.eostheworld.io:9876 p2p-peer-address = 807534da.eosnodeone.io:19872 p2p-peer-address = mainnet.eoseco.com:10010 p2p-peer-address = p2p.meet.one:9876 p2p-peer-address = node.eosflare.io:1883 p2p-peer-address = mainnet.eoscalgary.io:5222 p2p-peer-address = eos-p2p.worbli.io:33981 p2p-peer-address = 18.188.38.175:9876 p2p-peer-address = 18.221.255.38:9876 p2p-peer-address = eos.staked.us:9870 p2p-peer-address = peering.dutcheos.io:9876 p2p-peer-address = 18.188.4.97:9876 p2p-peer-address = 18.191.125.105:9876 p2p-peer-address = boot.eostitan.com:9876 p2p-peer-address = eosboot.chainrift.com:9876
啓動BP節點
後臺啓動BP節點:
$ docker run -d -p 8888:8888 -p 9876:9876 --rm --name eosio -v /tmp/eos-work:/eos-work eosio/eos nodeos --config-dir /eos-work --data-dir /eos-work a5f0f3332e7b4266cff0e6de9369e5df54c9d02f9a9845b373b04d2554008a6c
這一步我們使用 -p 8888:8888 -p 9876:9876
將容器中的兩個端口映射到本機的對應端口,使得可以被外部訪問。 -d
參數使容器直接後臺啓動。 --name eos
將容器命名爲eosio。
因爲 eos-work
目錄中已經初始化了區塊數據,所以啓動nodeos時不能再指定 genesis.json
文件。
查看容器輸出:
$ docker logs eosio 176343ms thread-0 chain_plugin.cpp:209 plugin_initialize ] initializing chain plugin 176364ms thread-0 block_log.cpp:123 open ] Log is nonempty 176367ms thread-0 block_log.cpp:141 open ] Index is nonempty 176386ms thread-0 http_plugin.cpp:290 plugin_initialize ] configured http to listen on 127.0.0.1:18888 176386ms thread-0 net_plugin.cpp:2948 plugin_initialize ] Initialize net plugin 176386ms thread-0 net_plugin.cpp:2972 plugin_initialize ] host: 0.0.0.0 port: 9876 176387ms thread-0 net_plugin.cpp:3044 plugin_initialize ] my node_id is abf02d39810fd00b66173669f4d7031a11874e5655f984b3e797a23a7b0e01ca 176388ms thread-0 main.cpp:104 main ] nodeos version 5875549c
查看BP節點運行狀態:
$ docker exec -it eosio cleos get info { "server_version": "5875549c", "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", "head_block_num": 979967, "last_irreversible_block_num": 979641, "last_irreversible_block_id": "000ef2b965e1dd90df22859312e82adcb59822a7b178b5c3c08a10fab282e5b9", "head_block_id": "000ef3ff63ad4428650bc934322c9297b49d328e5806f10008734a13a0eeb6e4", "head_block_time": "2018-06-16T03:12:42.500", "head_block_producer": "eosriobrazil", "virtual_block_cpu_limit": 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 199900, "block_net_limit": 1048576 }
如果 chain_id
爲 aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906
,說明已經鏈接上主網,並在同步區塊鏈數據。
這個信息顯示主網區塊才同步到2018-06-16T03:12:42.500。等到BP節點和主網完全同步後,便可以使用cleos進行各種操作了。
同時我們也可以在 https://eosmeta.io/ 上查看BP節點信息:
來源:https://eosmeta.io/