本文使用了四台同网段的主机,第一台做为eosio创世用户使用,另外三台做为出块者节点使用,最终实现了EOS多主机多节点的配置。最后EOSIO创世用户不再出块,由选举出来的各个节点轮流出块,下面将介绍具体的操作流程。
EOS versio: 1.0.8
system: ubuntu1804
四台服务器节点名称与对应IP:
eosio 192.168.154.157
zero 192.168.154.190
two 192.168.154.132
four 192.168.154.114
一、安装EOS
1、获取源码:git clone https://github.com/EOSIO/eos --recursive
2、cd eos
3、sudo vi ./contracts/eosio.system/voting.cpp +80 将21改成3
top_producers.reserve(3);
for ( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 3 && 0 < it->total_votes && it->active(); ++it ) {
top_producers.emplace_back( std::pair({{it->owner, it->producer_key}, it->location}) );
}
4、编译源码 ./eosio_build.sh
cd build
sudo make install
二、修改配置文件
1、对四台主机都在命令行先运行nodeos与keosd,让其产生各自的配置文件。
配置文件路径一般为:~/.local/share/eosio/nodeos/config/config.ini
2、为三个用户创建三组密钥对 cleos create key
account zero:
Private key: 5KXAsA1nizwEYAaWFA2uBUQqeHNhYA6hZ3dZ3tGb3X6aeW58UXF
Public key: EOS5nquErGx97QiN6m5DspwLU8wNLmVAm78ccpzV6Ht4nfcJhepyj
account two:
Private key: 5JSxqFojAkd2HARaxN5rFniK6oEu8YEZ1EcabSoFMhqxTQphKvF
Public key: EOS5VmHFnwVyiFurmFLw387xRpgXEnyF1yxqZs6JLtVwU1hv9gaEb
account four:
Private key: 5KHmyWSp6dhEoGRxx1wxAK7kSvtAAy7WDmumMLK3UNg6cqTCWYm
Public key: EOS8UXVwDadaS8pLDjQ2vRa6Jaqy5k1rqpMHUNCFqzeDF4KfoguJe
3、修改创世节点配置文件
eosio sign的密钥对(被记录在./tutorials/bios-boot-tutorial/genesis.json的initial_key里面):
EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p
eosio key的密钥对(被记录在默认的eosio配置文件的signature-provider里面):
EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
注意:要改这俩秘钥的话需要同步更改配置文件和创世节点里对应的密钥对
p2p-server-address = 192.168.154.157:9876
p2p-peer-address = 192.168.154.114:9876
p2p-peer-address = 192.168.154.132:9876
p2p-peer-address = 192.168.154.190:9876
enable-stale-production = true
producer-name = eosio
unlock-timeout = 90000
plugin = eosio::producer_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::http_plugin
plugin = eosio::http_client_plugin
plugin = eosio::bnet_plugin
plugin = eosio::net_plugin
plugin = eosio::net_api_plugin
plugin = eosio::history_api_plugin
plugin = eosio::history_plugin
4、修改其他节点配置文件
p2p-server-address = 192.168.154.132:9876
p2p-peer-address = 192.168.154.114:9876
p2p-peer-address = 192.168.154.157:9876
p2p-peer-address = 192.168.154.190:9876
enable-stale-production = false
producer-name = two
signature-provider = EOS5VmHFnwVyiFurmFLw387xRpgXEnyF1yxqZs6JLtVwU1hv9gaEb=KEY:5JSxqFojAkd2HARaxN5rFniK6oEu8YEZ1EcabSoFMhqxTQphKvF
plugin = eosio::chain_api_plugin
plugin = eosio::history_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::history_plugin
plugin = eosio::net_plugin
plugin = eosio::net_api_plugin
注意:不同的节点p2p-server-address和signature-provider需要改动,对应不同用户的IP和秘钥
三、创建钱包,导入秘钥
1、创建并解锁钱包
bee2@ubuntu:~/eos$ cleos wallet create
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5HwJAUXcgD1veDewfEAJAj2MGmfYfCc19Pu5srsnMLhCvFpRQGT"
bee2@ubuntu:~/eos$ cleos wallet unlock --password PW5HwJAUXcgD1veDewfEAJAj2MGmfYfCc19Pu5srsnMLhCvFpRQGT
出现解锁成功或者Error 3120007: Already unlocked字样即可
2、导入三个普通用户和创世节点eosio(eosio key ,eosio sign)的秘钥:
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 wallet import 5KXAsA1nizwEYAaWFA2uBUQqeHNhYA6hZ3dZ3tGb3X6aeW58UXF
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 wallet import 5JSxqFojAkd2HARaxN5rFniK6oEu8YEZ1EcabSoFMhqxTQphKvF
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 wallet import 5KHmyWSp6dhEoGRxx1wxAK7kSvtAAy7WDmumMLK3UNg6cqTCWYm
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 wallet import 5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p
注意:最后两个秘钥必须导入,不然会提示各种权限不足的错误
四、创建九个系统账户
这九个系统用户的名称及其作用如下说明:
eosio.bpay:矿工获取出块奖励的临时代管账户,增发EOS的1%的25%会先转到这个账户;
eosio.msig:多重签名管理的账户;
eosio.names:靓号账户拍卖管理的账户;
eosio.ram:内存买卖管理的账户;
eosio.ramfee:内存买卖收取手续费的账户,按照每笔交易千分之5的费率收取手续费;
eosio.saving:增发EOS临时存放账户,增发总量 5%,其中80%放在此账户,另外 20%再分成25%和75%,分别给eosio.bpay和eosio.vpay;
eosio.stake:管理EOS抵押的账户;
eosio.token:发行和管理token的账户;
eosio.vpay:矿工按照获得投票多少比例获取奖励的临时代管账户,增发EOS的1%的75%会先转到这个账户.
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.bpay EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.msig EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.names EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.ram EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.ramfee EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.saving EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.stake EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.token EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 create account eosio eosio.vpay EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr
五、加载四大合约,发行代币
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 set contract eosio.token ~/eos/build/contracts/eosio.token/
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 set contract eosio.msig ~/eos/build/contracts/eosio.msig/
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 push action eosio.token create '["eosio", "1000000000.0000 SYS"]' -p eosio.token
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 push action eosio.token issue '["eosio", "1000000000.0000 SYS", "memo"]' -p eosio
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 set contract eosio ~/eos/build/contracts/eosio.system/
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 push action eosio setpriv '["eosio.msig", 1]' -p eosio@active
六、创建普通用户
加载了eosio.system之后就不能使用create account命令了,只能用system newaccount创建账户
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system newaccount --transfer eosio zero EOS5nquErGx97QiN6m5DspwLU8wNLmVAm78ccpzV6Ht4nfcJhepyj --stake-net "100000000.0000 SYS" --stake-cpu "100000000.0000 SYS" --buy-ram "20000.0000 SYS"
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 transfer eosio zero "20000.0000 SYS"
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system newaccount --transfer eosio two EOS5VmHFnwVyiFurmFLw387xRpgXEnyF1yxqZs6JLtVwU1hv9gaEb --stake-net "100000000.0000 SYS" --stake-cpu "100000000.0000 SYS" --buy-ram "20000.0000 SYS"
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 transfer eosio two "20000.0000 SYS"
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system newaccount --transfer eosio four EOS8UXVwDadaS8pLDjQ2vRa6Jaqy5k1rqpMHUNCFqzeDF4KfoguJe --stake-net "100000000.0000 SYS" --stake-cpu "100000000.0000 SYS" --buy-ram "20000.0000 SYS"
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 transfer eosio four "20000.0000 SYS"
七、注册节点候选人
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system regproducer zero EOS5nquErGx97QiN6m5DspwLU8wNLmVAm78ccpzV6Ht4nfcJhepyj
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system regproducer two EOS5VmHFnwVyiFurmFLw387xRpgXEnyF1yxqZs6JLtVwU1hv9gaEb
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system regproducer four EOS8UXVwDadaS8pLDjQ2vRa6Jaqy5k1rqpMHUNCFqzeDF4KfoguJe
可以用下列命令查看节点候选人:
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system listproducers
八、给创建的账户转账
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 push action eosio.token transfer '["eosio", "zero","1000.0000 SYS","vote"]' -p eosio
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 push action eosio.token transfer '["eosio", "two","1000.0000 SYS","vote"]' -p eosio
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 push action eosio.token transfer '["eosio", "four","1000.0000 SYS","vote"]' -p eosio
九、使用命令进行投票(自己给自己投票)
所有代币的15%进行投票后eosio会停止出块,主网会自动启动。在这里我们的代币数据数量总共是10亿,那么我们的主网启动需要1.5亿质押的代币进行投票后才能启动,质押的代币计算方式:staked = cpu + net:
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system voteproducer prods zero zero
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system voteproducer prods two two
cleos --wallet-url http://127.0.0.1:8900 --url http://192.168.154.157:8888 system voteproducer prods four four
十、结尾
过一段时间后就能看到节点轮流产块,创世节点只需同步块,如下所示
本文是在学习了q_776355102的博客后做的简单总结,有诸多详细命令请参考原文:
https://blog.csdn.net/weixin_39842528/article/details/81034018
十一、更改节点出块数目
按上面的步骤可以让节点轮流出块了,但是每个节点出块个数是12,而不是像官网白皮书说的那样是6个,修改下相关代码就可以让节点出块个数变为6。
执行指令:vi libraries/chain/include/eosio/chain/config.hpp +99
//const static int producer_repetitions = 12;
const static int producer_repetitions = 6;
保存退出之后编译下源码,在按照上面的步骤再来一遍就可以看到如下界面: