新手教程 EOS4.0 局域网测试网络搭建教程

chuanhui · 2018年05月19日 · 最后由 dnbstarz 回复于 2018年08月22日 · 2512 次阅读
本帖已被设为精华帖!

在局域网里搭建了一个测试环境,分享一下操作步骤,希望和大家一起交流。

运行平台:ubuntu16.04虚拟机

  • 获取代码

    git clone https://github.com/EOSIO/eos --recursive
    git checkout dawn-v4.0.0
    
  • 编译

    ./eosio_build.sh
    

编译可能会有个错误如下

解决方法是到build/contracts执行make命令,之后在重新执行编译脚本eosio_build.sh就可以了,编译完成之后,在build目录下make install。

连接测试网络同步区块完成相关测试

  • 连接社区的测试网络

  • config.ini配置如下:

get-transactions-time-limit = 3
genesis-json = "genesis.json"
block-log-dir = "blocks"
max-reversible-block-time = -1
max-pending-transaction-time = -1
max-deferred-transaction-time = 20
shared-memory-size-mb = 32768
faucet-create-interval-ms = 1000
http-server-address = 0.0.0.0:8888
access-control-allow-credentials = false
p2p-listen-endpoint = 0.0.0.0:9876
#自己ip:port
p2p-server-address = 192.168.28.131:9876 
p2p-peer-address = cn.party.eosfans.io:9877 
p2p-peer-address = hk.party.eosfans.io:6789 
agent-name =
max-clients = 25
connection-cleanup-period = 30
network-version-match = 0
sync-fetch-span = 100
max-implicit-request = 1500
enable-stale-production = false
required-participation = 33
producer-name = kgtest
private-key = ["EOS4ugXbSzF1EfcpM9TepkgpMqLiKb3M14LTjd8smQtcicH3KSaCp","5JwVVY24wGBJSLKPawU9fJ8VvbfBo3xEv1SRQAFdJqxD36cVk79"]
# Plugin(s) to enable, may be specified multiple times
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin= eosio::producer_plugin
plugin = eosio::http_plugin
  • genesis配置如下:
{
"initial_timestamp": "2018-04-06T12:00:00.000",
"initial_key": "EOS7JWUDhCv6eGEoKJB4dTBF3GrLrJHT8jSeWhadpmH9Bkpt3jLy5",
"initial_configuration": {
"base_per_transaction_net_usage": 100,
"base_per_transaction_cpu_usage": 500,
"base_per_action_cpu_usage": 1000,
"base_setcode_cpu_usage": 2097152,
"per_signature_cpu_usage": 100000,
"per_lock_net_usage": 32,
"context_free_discount_cpu_usage_num": 20,
"context_free_discount_cpu_usage_den": 100,
"max_transaction_cpu_usage": 10485760,
"max_transaction_net_usage": 104857,
"max_block_cpu_usage": 104857600,
"target_block_cpu_usage_pct": 1000,
"max_block_net_usage": 1048576,
"target_block_net_usage_pct": 1000,
"max_transaction_lifetime": 3600,
"max_transaction_exec_time": 0,
"max_authority_depth": 6,
"max_inline_depth": 4,
"max_inline_action_size": 4096,
"max_generated_transaction_count": 16,
"max_transaction_delay": 3888000
},
"initial_chain_id": "0000000000000000000000000000000000000000000000000000000000000000"
} 

如果出现如下错误

在build目录下make install,删除~/.local/share/eosio/nodeos/data目录,重新启动nodeos命令,如果错误没有解决,可以多尝试几次,暂时还不知道什么原因。

局域网自己搭建一个测试网络

Node1:192.168.195.144

  • config.ini配置如下:
genesis-json = "genesis.json"
block-log-dir = "blocks"
shared-memory-size-mb = 1024
http-server-address = 127.0.0.1:8888
access-control-allow-credentials = false
p2p-listen-endpoint = 0.0.0.0:9876
p2p-server-address = 192.168.195.144:9876
agent-name = "EOS Test Agent"
allowed-connection = any
max-clients = 25
connection-cleanup-period = 30
network-version-match = 0
sync-fetch-span = 100
max-implicit-request = 1500
enable-stale-production = true
max-transaction-time = 30
required-participation = 33
producer-name = eosio
private-key = ["EOS8HF8XSGjfSvG5zfPgXFcUjFJh56ifWzYneWMEQSCkXgSdPJ51R","5JC4FQVzAZuxWmaAfbW1RWsNDEpjjF5enfn9WBHkYTupFJQaBWt"]
txn-reference-block-lag = 0
wallet-dir = "."
unlock-timeout = 900
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
  • genesis配置如下:
{
  "initial_timestamp": "2018-03-02T12:00:00.000",
  "initial_key": "EOS8HF8XSGjfSvG5zfPgXFcUjFJh56ifWzYneWMEQSCkXgSdPJ51R",
  "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": 100000,
    "base_per_transaction_cpu_usage": 512,
    "base_per_action_cpu_usage": 1024,
    "base_setcode_cpu_usage": 2097152,
    "per_signature_cpu_usage": 102400,
    "cpu_usage_leeway": 2048,
    "context_free_discount_cpu_usage_num": 20,
    "context_free_discount_cpu_usage_den": 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"
}

Node2:192.168.195.176

  • config.ini配置如下:
genesis-json = "genesis.json"
block-log-dir = "blocks"
shared-memory-size-mb = 1024
http-server-address = 127.0.0.1:8888
access-control-allow-credentials = false
p2p-listen-endpoint = 0.0.0.0:9876
p2p-server-address = 192.168.195.176:9876
p2p-peer-address = 192.168.195.144:9876
p2p-peer-address = 192.168.195.191:9876
agent-name = "EOS Test Agent"
allowed-connection = any
max-clients = 25
connection-cleanup-period = 30
network-version-match = 0
sync-fetch-span = 100
max-implicit-request = 1500
enable-stale-production = false
max-transaction-time = 30
required-participation = 33
producer-name = kgtest
private-key = ["",""]
txn-reference-block-lag = 0
wallet-dir = "."
unlock-timeout = 900
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
  • genesis配置和Node1一样

Node3:192.168.195.191

  • config.ini配置如下:
genesis-json = "genesis.json"
block-log-dir = "blocks"
shared-memory-size-mb = 1024
http-server-address = 127.0.0.1:8888
access-control-allow-credentials = false
p2p-listen-endpoint = 0.0.0.0:9876
p2p-server-address = 192.168.195.176:9876
p2p-peer-address = 192.168.195.144:9876
p2p-peer-address = 192.168.195.176:9876
agent-name = "EOS Test Agent"
allowed-connection = any
max-clients = 25
connection-cleanup-period = 30
network-version-match = 0
sync-fetch-span = 100
max-implicit-request = 1500
enable-stale-production = false
max-transaction-time = 30
required-participation = 33
producer-name = kgtest
private-key = ["",""]
txn-reference-block-lag = 0
wallet-dir = "."
unlock-timeout = 900
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
  • genesis配置和Node1一样

环境搭建开始

首先需要启动Node1节点,正常的话Node1会开始出块。同时启动Node2和Node3,这两个节点会同步Node1节点的区块。

  • 创建钱包
cleos wallet create -n kgbp

这里需要保存好wallet的私钥,之后unlock需要使用

  • 打开并解锁钱包 cleos wallet open -n kgbp cleos wallet unlock -n kgbp
  • 导入eosio账户的私钥到钱包里

    cleos wallet import -n kgbp xxxxxxxxxxxxxxxxxxxxxx
    
  • 创建并发布token

1.创建eosio.token账户,这里可以使用别的名字,只要在后序的命令操作中保持一致就好了,另外创建完账户之后记得要导入账户的私钥,要不后序关于这个账户的操作会没有权限。

cleos create account eosio eosio.token EOS721PhsVCdLXatGMxu2kNBMPtQZzV8QU6Wu1qC9YFBZegyiP8if EOS721PhsVCdLXatGMxu2kNBMPtQZzV8QU6Wu1qC9YFBZegyiP8if

2.发布eosio.token合约

cleos set contract eosio.token ./contracts/eosio.token/

3.创建和发布代币

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

4查询代币数量

如果上面的操作都成功的话,下面这个命令返回的是1000000000.00000 EOS

cleos get currency balance eosio.token eosio
  • 部署eosio.system合约

如果部署失败的话,可以多尝试几次,我是尝试到第三次成功的

cleos set contract eosio ./contracts/eosio.system/

部署了eosio.system合约之后,cleos create account这个命令就不能创建账户了,暂时还不清楚是什么原因。让后可以用下面这个命令创建账户。

cleos system newaccount eosio kgtest EOS5VPJHpT6aUfqVyW2XNNc2JgwtAa15nnQXMbzyvSQQHr2NYqCDz EOS5VPJHpT6aUfqVyW2XNNc2JgwtAa15nnQXMbzyvSQQHr2NYqCDz  --stake-net '50.00 EOS' --stake-cpu '50.00 EOS'
cleos system newaccount eosio kgtestt EOS79bDtiWLaSkWaHi59u5wdWL4XKfLgwBCvWa1FTvCT8bDiYXjQY EOS79bDtiWLaSkWaHi59u5wdWL4XKfLgwBCvWa1FTvCT8bDiYXjQY  --stake-net '50.00 EOS' --stake-cpu '50.00 EOS'
cleos system newaccount eosio kgtesttt EOS5WhVn5sKfTudx7THKLMSCH9BWchfBMdM1Q6aLU86tCvhUsjJZ6 EOS5WhVn5sKfTudx7THKLMSCH9BWchfBMdM1Q6aLU86tCvhUsjJZ6  --stake-net '50.00 EOS' --stake-cpu '50.00 EOS'

创建完成之后导入账户私钥。

  • Node2注册成为bp

    cleos  system regproducer kgtest EOS5VPJHpT6aUfqVyW2XNNc2JgwtAa15nnQXMbzyvSQQHr2NYqCDz http://http-server-address:8888
    
  • 给创建的账户转账

cleos  push action eosio.token transfer '["eosio", "kgtest","100000000.0000 EOS","vote"]' -p eosio
cleos  push action eosio.token transfer '["eosio", "kgtestt","100000000.0000 EOS","vote"]' -p eosio
cleos  push action eosio.token transfer '["eosio", "kgtesttt","100000000.0000 EOS","vote"]' -p eosio
  • 锁定代币

    cleos system delegatebw kgtest kgtest '25000000.0000 EOS' '25000000.0000 EOS' --transfer
    cleos system delegatebw kgtestt kgtestt '25000000.0000 EOS' '25000000.0000 EOS' --transfer
    cleos system delegatebw kgtesttt kgtesttt '25000000.0000 EOS' '25000000.0000 EOS' --transfer
    
  • 给出块节点投票

cleos system voteproducer prods kgtest kgtest
cleos system voteproducer prods kgtestt kgtest
cleos system voteproducer prods kgtesttt kgtest

然后就可以观察到Node2节点出块了。

共收到 59 条回复

占坑

strahe 将本帖设为了精华贴 05月19日 23:53

node3的p2p-server-address是不是错了

ripley 回复

一般填的是自己的本地的IP:port,不过也可以填同网络的其他机器,测试的时候没发现有什么影响

请教:在Ubuntu16.04安装EOS时,运行./eosio_build.sh后:报如下错:

你检查下代码是不是下对了,这个教程之适用于4.0的代码,还有下载完整了没,还有依赖库

请问下,node 1 2 3 的config文件在哪里设置呢,.local/...只有一个config文件呢

cleos set contract eosio ./contracts/eosio.system/ 使用eosio创建eosio.system合约不成功
改用eosio.token 创建可以成功
注意合约路径

Babena 回复

你没看到是三个IP,三台机器或虚拟机

部署了eosio.system合约之后,cleos create account这个命令就不能创建账户了,暂时还不清楚是什么原因。让后可以用下面这个命令创建账户。
我这边可以的,是部署了eosio.system合约之后创建的

请问genesis.json文件在什么路径下面呢?我在~/.local/share/eosio/nodeos/config/下面并未找到

请问一下,我投票以后,节点1和节点2都不出块了,这是什么原因,我用的是master版的

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册