知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
這種模式一般用於合約開發,學習和測試
nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::wallet_api_plugin
區塊數據保存在 ~/.local/share/eosio/nodeos/data
[root@netkiller ~]# find ~/.local/share/eosio/nodeos/data /root/.local/share/eosio/nodeos/data /root/.local/share/eosio/nodeos/data/blocks /root/.local/share/eosio/nodeos/data/blocks/blocks.index /root/.local/share/eosio/nodeos/data/blocks/reversible /root/.local/share/eosio/nodeos/data/blocks/reversible/shared_memory.meta /root/.local/share/eosio/nodeos/data/blocks/reversible/shared_memory.bin /root/.local/share/eosio/nodeos/data/blocks/blocks.log /root/.local/share/eosio/nodeos/data/state /root/.local/share/eosio/nodeos/data/state/shared_memory.meta /root/.local/share/eosio/nodeos/data/state/shared_memory.bin
本地私鏈會提示 warning: transaction executed locally, but may not be confirmed by the network yet.
https://github.com/EOSIO/eos/wiki/Testnet-Single-Host-Multinode
EOS 有三個模組組成分別是nodeos,keosd,和cleos。nodeos 是節點進程,keosd 是錢包服務,cleos 是命令行介面。實現單機多節點主要工作在於怎樣配置 nodeos 進程,使其連接埠不衝突。
多級多節點配置只需要將其他節點的IP加入到 p2p-peer-address 池中即可,配置項涉及一下:
[root@iZj6c39y62jl5b1wmfv6u8Z config]# grep -v "^#" ~/.local/share/eosio/nodeos/config/config.ini | grep -v "^$" p2p-peer-address = node1:9876 ... ... p2p-peer-address = node(n):9876 agent-name: 改成你自己的標識, 域名或其他. producer-name: 節點賬戶名(12位[12345a-z]字元串). signature-provider: 你的密鑰對.
準備幾台伺服器或者云主機
Node1 172.16.0.10 Node2 172.16.0.20 Node3 172.16.0.30
創世區塊 genesis.json
{ "initial_timestamp": "2018-06-01T00:00:00.000", "initial_key": "EOS69EZcBVwgRz3AbHheR3ZpeHtaoHAPyLXfvmsiqYMAtazN3WdiL", "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": 100000, "target_block_cpu_usage_pct": 500, "max_transaction_cpu_usage": 50000, "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, "max_generated_transaction_count": 16 }, "initial_chain_id": "0000000000000000000000000000000000000000000000000000000000000000" }
編輯配置檔案 ~/.local/share/eosio/nodeos/config/config.ini
p2p-peer-address = 172.16.0.20:9876 p2p-peer-address = 172.16.0.30:9876 agent-name = "EOS Test Agent - Node 1" producer-name = eosio signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
啟動 nodeos 進程
nodeos --genesis-json genesis.json
編輯配置檔案 ~/.local/share/eosio/nodeos/config/config.ini
p2p-peer-address = 172.16.0.10:9876 p2p-peer-address = 172.16.0.30:9876 agent-name = "EOS Test Agent - Node 2" producer-name = eosio signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
啟動 nodeos 進程
編輯配置檔案 ~/.local/share/eosio/nodeos/config/config.ini
p2p-peer-address = 172.16.0.10:9876 p2p-peer-address = 172.16.0.20:9876 agent-name = "EOS Test Agent - Node 3" producer-name = eosio signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
啟動 nodeos 進程
cleos wallet create cleos wallet unlock # 導入eosio賬戶的私鑰到錢包,signature-provider 中的 KEY:是私鑰 cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 cleos create key cleos create account eosio eosio.token <公鑰> <公鑰> cleos set contract eosio /usr/local/src/eos/build/contracts/eosio.bios -p eosio # 發佈eosio.token合約 cleos set contract eosio.token /usr/local/src/eos/build/contracts/eosio.token # 創建和發佈代幣 cleos push action eosio.token create '["eosio","1000000000.0000 EOS",0,0,0]' -p eosio.token cleos push action eosio.token issue '["eosio","1000000000.0000 EOS","issue"]' -p eosio # 查詢代幣數量 cleos get currency balance eosio.token eosio # 部署eosio.system合約 cleos set contract eosio /usr/local/src/eos/build/contracts/eosio.system # 創建賬號 cleos create key cleos system newaccount eosio test <公鑰> <公鑰> --stake-net '50.00 EOS' --stake-cpu '50.00 EOS' # 登錄 Node 2 註冊成為 bp cleos system regproducer test <公鑰> http://127.0.0.1:8888 # 給創建的賬戶轉賬 cleos push action eosio.token transfer '["eosio", "test","100000000.0000 EOS","vote"]' -p eosio # 鎖定代幣 cleos system delegatebw test test '25000000.0000 EOS' '25000000.0000 EOS' --transfer # 給出塊節點投票 cleos system voteproducer prods test test
HTTP Endpoint: testnet1.eos.io P2P Endpoint: p2p-testnet1.eos.io:9876 Web Wallet Endpoint: t1wallet.eos.io, t1api.eos.io, t1readonly.eos.io $ curl testnet1.eos.io/v1/chain/get_info
https://eosnodes.privex.io
[root@netkiller build]# cleos -u http://api.eosnewyork.io get info { "server_version": "1509de21", "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", "head_block_num": 3185805, "last_irreversible_block_num": 3185470, "last_irreversible_block_id": "00309b3e25263b1f6cef6a87a304284afcc06bacd1290e6904760395e07d2321", "head_block_id": "00309c8d9f01ba0ac66bd577cdfdd4e85162ba1d68e18f5660356bc8207615b1", "head_block_time": "2018-06-29T02:46:41.000", "head_block_producer": "eosisgravity", "virtual_block_cpu_limit": 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 198989, "block_net_limit": 1048304 }
https://eosnodes.privex.io/static/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 } }
檢查創世區塊配置是否正確
[root@netkiller build]# cleos -u http://api.eosnewyork.io get info { "server_version": "1509de21", "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", "head_block_num": 3185805, "last_irreversible_block_num": 3185470, "last_irreversible_block_id": "00309b3e25263b1f6cef6a87a304284afcc06bacd1290e6904760395e07d2321", "head_block_id": "00309c8d9f01ba0ac66bd577cdfdd4e85162ba1d68e18f5660356bc8207615b1", "head_block_time": "2018-06-29T02:46:41.000", "head_block_producer": "eosisgravity", "virtual_block_cpu_limit": 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 198989, "block_net_limit": 1048304 } [root@netkiller build]# cleos get info { "server_version": "90fefdd1", "chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", "head_block_num": 26364, "last_irreversible_block_num": 26363, "last_irreversible_block_id": "000066fbb919e9e7613765190b7e2e6639588d36e834da77ab63f7cc43d04ec2", "head_block_id": "000066fc54c27265bb243a3ef19923a54b52ab1cb568e067fb2f83ebcf9d1d26", "head_block_time": "2018-06-29T02:46:56.000", "head_block_producer": "eosio", "virtual_block_cpu_limit": 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 199900, "block_net_limit": 1048576 }
對比兩次 chain_id 是否一致,一致表示配置正確。
https://eosnodes.privex.io/?config=1
p2p-peer-address = 106.10.42.238:9876 p2p-peer-address = 123.59.116.52:49876 p2p-peer-address = 13.230.91.225:9865 p2p-peer-address = 130.211.59.178:9876 p2p-peer-address = 159.65.214.150:9876 p2p-peer-address = 173.242.25.101:7115 p2p-peer-address = 178.49.174.48:9876 p2p-peer-address = 18.191.33.148:59876 p2p-peer-address = 185.253.188.1:19876 p2p-peer-address = 185.253.188.1:19877 p2p-peer-address = 195.43.95.98:9876 p2p-peer-address = 34.252.209.121:5556 p2p-peer-address = 35.197.190.234:19878 p2p-peer-address = 40.114.68.16:9876 p2p-peer-address = 54.153.59.31:9999 p2p-peer-address = 807534da.eosnodeone.io:19872 p2p-peer-address = 94.130.250.22:9806 p2p-peer-address = api-full1.eoseoul.io:9876 p2p-peer-address = api-full2.eoseoul.io:9876 p2p-peer-address = api.eosuk.io:12000 p2p-peer-address = boot.eostitan.com:9876 p2p-peer-address = bp.antpool.com:443 p2p-peer-address = bp.cryptolions.io:9876 p2p-peer-address = bp.eosbeijing.one:8080 p2p-peer-address = bp.eosmedi.com:9877 p2p-peer-address = bp.libertyblock.io:9800 p2p-peer-address = dc1.eosemerge.io:9876 p2p-peer-address = dns1-p2p.oraclechain.io:49876 p2p-peer-address = eno.eosvan.io:19866 p2p-peer-address = eos-seed-de.privex.io:9876 p2p-peer-address = eos.infinitystones.io:9876 p2p-peer-address = eos.nodepacific.com:9876 p2p-peer-address = eos.staked.us:9870 p2p-peer-address = eosapi.blockmatrix.network:13546 p2p-peer-address = eosboot.chainrift.com:9876 p2p-peer-address = eosbp.buildteam.io:8532 p2p-peer-address = eosbp.eosvillage.io:8181 p2p-peer-address = eosnode.fi:9888 p2p-peer-address = eu-west-nl.eosamsterdam.net:9876 p2p-peer-address = eu1.eosdac.io:49876 p2p-peer-address = fn001.eossv.org:443 p2p-peer-address = fullnode.acroeos.one:9876 p2p-peer-address = fullnode.eoslaomao.com:443 p2p-peer-address = mainnet-eos.wancloud.cloud:55576 p2p-peer-address = mainnet.eos.ren:9376 p2p-peer-address = mainnet.eosarabia.org:3571 p2p-peer-address = mainnet.eoscalgary.io:5222 p2p-peer-address = mainnet.eoseco.com:10010 p2p-peer-address = mainnet.eospay.host:19876 p2p-peer-address = mainnet.eoswz.com:8866 p2p-peer-address = mainnet2.eostaxrelief.com:9876 p2p-peer-address = mars.fnp2p.eosbixin.com:443 p2p-peer-address = node.eos.lawyer:9876 p2p-peer-address = node.eosflare.io:1883 p2p-peer-address = node.eosio.lt:9878 p2p-peer-address = node.eosmeso.io:9876 p2p-peer-address = node1.eosjapan.co.jp:9876 p2p-peer-address = node1.eosnewyork.io:6987 p2p-peer-address = node2.blockeos.io:9987 p2p-peer-address = node2.eosarmy.io:3330 p2p-peer-address = node2.eosnewyork.io:6987 p2p-peer-address = node2.eosphere.io:9876 p2p-peer-address = p.jeda.one:3322 p2p-peer-address = p2p.eos.bitspace.no:9876 p2p-peer-address = p2p.eosdetroit.io:3018 p2p-peer-address = p2p.eosholding.ca:9876 p2p-peer-address = p2p.eosio.cr:1976 p2p-peer-address = p2p.eosio.cr:5418 p2p-peer-address = p2p.genereos.io:9876 p2p-peer-address = p2p.mainnet.eosgermany.online:9876 p2p-peer-address = p2p.mainnet.eospace.io:88 p2p-peer-address = p2p.meet.one:9876 p2p-peer-address = p2p.one.eosdublin.io:9876 p2p-peer-address = p2p.saltblock.io:19876 p2p-peer-address = p2p.two.eosdublin.io:9876 p2p-peer-address = peer.blockgenicbp.com:9876 p2p-peer-address = peer.eosio.sg:9876 p2p-peer-address = peer.eosjrr.io:9876 p2p-peer-address = peer.eosn.io:9876 p2p-peer-address = peer.main.alohaeos.com:9876 p2p-peer-address = peer1.eos.csx.io:9806 p2p-peer-address = peer1.eosthu.com:8080 p2p-peer-address = peer1.mainnet.eos.store:80 p2p-peer-address = peer1.mainnet.helloeos.com.cn:80 p2p-peer-address = peer2.eos.csx.io:9806 p2p-peer-address = peer2.eosthu.com:8080 p2p-peer-address = peer2.mainnet.helloeos.com.cn:80 p2p-peer-address = peering.dutcheos.io:9876 p2p-peer-address = peering.mainnet.eoscanada.com:9876 p2p-peer-address = peering1.mainnet.eosasia.one:80 p2p-peer-address = peering2.mainnet.eosasia.one:80 p2p-peer-address = pub0.eosys.io:6637 p2p-peer-address = pub1.eostheworld.io:9876 p2p-peer-address = pub1.eosys.io:6637 p2p-peer-address = pub2.eostheworld.io:9876 p2p-peer-address = publicnode.cypherglass.com:9876 p2p-peer-address = seed1.greymass.com:9876 p2p-peer-address = seed2.greymass.com:9876
[root@netkiller ~]# cleos --url=http://mainnet.genereos.io get info { "server_version": "b195012b", "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", "head_block_num": 3218632, "last_irreversible_block_num": 3218299, "last_irreversible_block_id": "00311b7b6a24585e4a1fd806f619ca075fe9c72fa0310b6ca465e91aad33999c", "head_block_id": "00311cc8bb55e1c6d2ec9c1455908545ecee293efa556c1dce444814cf891611", "head_block_time": "2018-06-29T07:20:16.000", "head_block_producer": "teamgreymass", "virtual_block_cpu_limit": 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 199900, "block_net_limit": 1048576 }
[root@netkiller ~]# cleos -u http://mainnet.eoswz.com get info { "server_version": "aa351733", "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", "head_block_num": 3221149, "last_irreversible_block_num": 3220819, "last_irreversible_block_id": "003125538662bf4cdc367336daba8a8609d6b4f5edb6e8bf0189a27fa306fbde", "head_block_id": "0031269d3ee1f2b8dbc9419a9d8ac0be7024c3a072d9f178ce297dbea6cbb58e", "head_block_time": "2018-06-29T07:41:14.500", "head_block_producer": "teamgreymass", "virtual_block_cpu_limit": 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 199900, "block_net_limit": 1048576 }