源码下载
源码改动
root@ubuntu:/mnt/hgfs/yejn/eos/eos/libraries/chain/include/eosio/chain# vim config.hpp
const static int block_interval_ms = 500; 修改出块时间
const static uint32_t default_target_block_net_usage_pct = 10 * percent_1; /// we target 1000 TPS
vim producer_plugin/producer_plugin.cpp 打印
if (head_block_age > fc::seconds(5)) 5改成25
EOS_ASSERT( block->timestamp < (fc::time_point::now() + fc::seconds(7)), block_from_the_future, "received a block from the future, ignoring it" ); 7改成27
简介
编译源码,搭建自己的私有链;部署4个节点,eosio,inita,initb,initc;
eosio:第一个节点,生产创世块,部署系统账户合约,发布系统代币,创建并投票其他超级节点。
inita,initb,initc:超级节点,投票结束后,轮流出块。
提前准备
cleos create key --to-console 很多配置文件需要用到密钥对,用此命令创建即可。
获取密钥对,配置genesis.json 和config.ini文件
为每个节点创建钱包,并且记住密码 本文钱包名称为eosio.wallet inita.wallet inib.wallet initc.wallet
记得把对应的私钥导入钱包,我已经在脚本导入各自的私钥
创建钱包命令 cleos wallet create -n eosio.wallet --to-console
文件说明
/root/eosio/data/ 数据目录。
/root/eosio/config/ 配置文件目录。
/root/eosio/config/genesis.json 创世文件,所有节点保存一致。https://github.com/EOSIO/eos/blob/master/tutorials/bios-boot-tutorial/genesis.json
/root/eosio/config/config.ini 配置文件,配置本节点账户信息,后面有详细说明。https://github.com/EOSIO/eos/blob/master/Docker/config.ini
genesis.json 所有节点,创世文件都一样
"initial_timestamp": "2018-12-13T02:02:13.066", 如果不能出块,可以先运行一次eosio节点,再回填
"initial_key": "EOS5xXJ8LkHDhJWHC5HKz8y9nhq5UaZgxzDMdGbiufrrJXwcCHzH8", 创世区块节点的公钥,必须和源码里的地址一致
"initial_chain_id": "0000000000000000000345000000000000000000000000000000000000000000" 随意填写
config.ini
#blocks-dir = "blocks" 区块目录,建议屏蔽,自己指定
http-server-address = 0.0.0.0:8888 http服务器本地监听
p2p-server-address = 192.168.1.132:9898 配置本地为p2p服务器
p2p-listen-endpoint = 0.0.0.0:9898 本地节点监听
p2p-peer-address = 192.168.1.132:9898 其他超级节点,可以配置多个
agent-name = "EOS Test Agent" 名称,可以随意修改
allowed-connection = any 允许任意节点连接
enable-stale-production = true 第一节点配置为true,允许直接出块,其他超级节点配置为false
max-transaction-time = 1000 防止部署合约失败,此配置设置为1000
producer-name = eosio 本节点的账户名称,eosio为创世节点名称,后面几个节点名称分别为inita,initb,initc由自己设定,这些账户在下面脚本中创建
signature-provider = EOS5xXJ8LkHDhJWHC5HKz8y9nhq5UaZgxzDMdGbiufrrJXwcCHzH8=KEY:5KMmKcSh4cNWLvASoKqVzoKgC8Gn953byfZnzrVS2XeXirRrVWm 节点密钥对,eosio节点配置为genesis.json对应公钥即可
编译源码
git clone https://github.com/EOSIO/eos.git
cd eos
git submodule update --init --recursive 更新到最新
获取密钥对,l osio账户公钥写死在代码中, 在代码根目录 CMakeList.txt里面,
找到 EOSIO_ROOT_KEY,改为自己创建的公钥。并把新的密钥对 要在 config.ini文件中保存,见文件中 “signature-provider = 。。。”。
如果内存低于7G,需要修改配置
vim scripts/eosio_build_ubuntu.sh
- if [ "${MEM_MEG}" -lt 7000 ]; then 如果你的物理内存是4G ,可以把7000改成3000
如果磁盘过低,也需要修改磁盘配置
启动步骤
如果配置文件和私钥和我的一样,可以使用以下脚本自动执行,但是节点ip端口需要自己配置
eosio config.ini
producer-name = eosio
signature-provider = EOS5xXJ8LkHDhJWHC5HKz8y9nhq5UaZgxzDMdGbiufrrJXwcCHzH8=KEY:5KMmKcSh4cNWLvASoKqVzoKgC8Gn953byfZnzrVS2XeXirRrVWm
inita config.ini
producer-name = inita
signature-provider = EOS5VJv4YxPkv9asb5BfSHoDKSVnbuKfay3cNy2kcciELsCdDeqYB=KEY:5K5kgoqiTgYbPv5LUxhRrXodiZeJJPxdxSirVyzpPGHhw7qRvwt
initb config.ini
producer-name = initb
signature-provider = EOS7P4K4wsKaDAkES6VSyFb6tAMRE5afkniB9jE4Sq9tqTy6yddHb=KEY:5HqinXiSMZrNKrEkPuHbkvNDe5vPYDwoNeqmdLtB7yyR7aWpZkT
initc config.ini
producer-name = initc
signature-provider = EOS534ZY8Qk6HCAKubu2prUGxbnsq7NqVq6gK8GWnbUh74w6fD7pG=KEY:5JrmJmyPWPbEG5Tr9La1vzBKYkZfxDCdpwwHk13hBEGKzuixNEv
启动顺序:
eosio节点 sh start.sh sh init.sh
inita节点 sh start.sh sh init.sh
initb节点 sh start.sh sh init.sh
initc节点 sh start.sh sh init.sh
inita节点 sh vote.sh
以下为脚本说明
root@ubuntu:~/eosio# cat start.sh
nodeos --data-dir ./data --config-dir ./config --genesis-json ./config/genesis.json
root@ubuntu:~/eosio# cat init.sh
#创建10对密钥 cleos create key --to-console
#创建钱包 cleos wallet create -n eosio.wallet --to-console 密钥未:"PW5KJ9Jsw4v9qZz4LbD68YUr922Ro9wT1YQdj7MUDbEUr9nDPaptt" 要记住钱包密码
#解锁钱包
echo "wallet unlock ..."
cleos wallet unlock -n eosio.wallet --password PW5KJ9Jsw4v9qZz4LbD68YUr922Ro9wT1YQdj7MUDbEUr9nDPaptt
#导入私钥
echo "wallet import ..."
cleos wallet import -n eosio.wallet --private-key 5JzEdUHZ57jPdTNPpAANnzLQpBf6cv26qV3SJe66QreD4GxEKfD
cleos wallet import -n eosio.wallet --private-key 5KDj65fFcTuQTDDrFomyWb19QoSjEaJJjrJdswmz4VLZkai8ZuT
cleos wallet import -n eosio.wallet --private-key 5JWVi9KdZ273tFyNFxiogUnKMnncxaFdMcYTyb3FFaQEYpMGwbV
cleos wallet import -n eosio.wallet --private-key 5Hpoeryo4brkpBc5utR1bdTubLBhANreEDbXQiDsJaBhcPPuMzV
cleos wallet import -n eosio.wallet --private-key 5J4hmSkbGPHW6CK9i3Y8pb7tzxvoM19T2g5fdNtY7TdpHS4yXX4
cleos wallet import -n eosio.wallet --private-key 5HsEdJM6meYM2guGJrSDkMGLfJcCyEvBseuqChNfGepcFncZWKQ
cleos wallet import -n eosio.wallet --private-key 5KPhYWxhicE8QjsumzHcqpw29B1LchjDHWUZPP9WLiHG94hJBDp
cleos wallet import -n eosio.wallet --private-key 5HqyxVv5tJ2Kjug6owA1CwrhDxMSwNVF3kEh7FHUzfSfEWBRygK
cleos wallet import -n eosio.wallet --private-key 5JbE3wT7o8Dj8crE8gL9eCE7XzXdNeV5NpLba1UjQhmv6gY5btv
cleos wallet import -n eosio.wallet --private-key 5Jdvw42rZg2JTdMxm2ZFATKuw9cq26LYn7Ek2aGywkuW99ZSxQN
cleos wallet import -n eosio.wallet --private-key 5KaJVpBPA89THFz3cpyxGRVgUadf31BdLwWVVrPYtah2z5PoP8c
cleos wallet import -n eosio.wallet --private-key 5JsNaoqmkuMWz6KPqNJkBnAw5ZdtW5iTdzzdgbn3Z8B72Gne3ML
cleos wallet import -n eosio.wallet --private-key 5JSEBVXW6wHX87p8BYbAJDpH7gXJ4C2AXMyXUyPXhCBkTDeVwi6
cleos wallet import -n eosio.wallet --private-key 5Kk5vAvANhp4QWghAQfeos5qoB7GHwxfq8iTii15UxHzCjiZMcz
cleos wallet import -n eosio.wallet --private-key 5JL9bpLQ74VvoxqRGHXP9TRQpJ3TutAR4jxJq8vQJTbEkQ75Zps
cleos wallet import -n eosio.wallet --private-key 5JKkLotKioZWb2vLYxaWjcQZRGYggWCFJbPjP47oeHcYztoATFc
cleos wallet import -n eosio.wallet --private-key 5HuMZmdxEX8Gokwsp6pYEzfaxyVgaZZJcw4zmSvCHYAXZ3vGtFU
cleos wallet import -n eosio.wallet --private-key 5JZu7FKANH5BJKTzzEMKYRUPpFfnpQRQDZpGWJtmapyXguEGRCo
cleos wallet import -n eosio.wallet --private-key 5JL2fQo4eZKJrJCis791yCr2gvLzhJbw3kfD7iJSD1p6zG25sHj
cleos wallet import -n eosio.wallet --private-key 5KTsJSfMCtPjKw4J8fL2xYV3eP5eL6Hgz4h5YoQTfrkg2zuiVTU
cleos wallet import -n eosio.wallet --private-key 5KMwpdSHUAZT3MnwHKeH3fNHua8VokgWjgiincg6ixdnpLyXWW5
cleos wallet import -n eosio.wallet --private-key 5Jhs8DJzEXm9YkFYWhU6SkthLNiYsv1A3RWLJnu5XMF32fRVuAP
#创建系统代币
echo "create eosio.token ..."
sleep 2
cleos create account eosio eosio.token EOS52VT7jeKKP71RWaEcLEhaoSfT86tnVYkrRERXAAuqCZmNjfJke EOS6mnRRwZ26qUe6SbCtJs6ch6aJTvY8X26vKypP4qkHcDmP5BjYU
sleep 2
cleos set contract eosio.token /mnt/hgfs/yejn/eos/eos/build/contracts/eosio.token/
sleep 2
cleos push action eosio.token create '["eosio","1000000000.0000 SYS",0,0,0]' -p eosio.token
sleep 2
cleos push action eosio.token issue '["eosio","1000000000.0000 SYS","issue"]' -p eosio
#创建9个系统账户
echo "create 9 eosio..."
cleos create account eosio eosio.bpay EOS8PMqhqJVm9G3nqYiNtYsP3x2Kvx955Yaz3idrhe5mSVVE6WAcy EOS5H7z2jKMmLbk9Q1LGLivn88PHXBGEpw6a3m9VVeZa15sW8Aanp
cleos create account eosio eosio.msig EOS6UZGR6MYYbMtpsPuF586XGnvbnUnLTrmFZrsacBVMNTTXf3DBh EOS8JBkp1oRqmbGBFs1wVUJUizGrWP93Cceo5aLmCpUvdqH7aXMmv
cleos create account eosio eosio.name EOS8G79TGTBpDPE5ZNbQLvRQJzLcXFSb4991aw8UJTEjFRTWfecry EOS59dYuDA4KiyecJ5eBNeq43X7GmXKSuJuZtDHgRDhG5y6Nu9Evb
cleos create account eosio eosio.names EOS7TfjDo7fTi5TLwWhzvKJjRwoSo8CYuj9mi8YwmFoDLBE5GHYs7 EOS5PZKeR3sGhyimNiXaRcn1xY9SzE3br78E8fz1uARcmvWoWvWry
cleos create account eosio eosio.ram EOS7UpH4rB1mkdZP43B3wHxKyrcQfB1Q674yhcTT1XJ3peyw7kH3i EOS5UgoMbihFgJ8RJyGEJhjm8gvZrH1uuvGWmyEXZWEwmt1VENC1e
cleos create account eosio eosio.ramfee EOS71wtJJMLfm5hnxTK3KJTSAZfrCHtk1awCgXxdGjL6ethSrHVrx EOS61fbgGb1nacyGNUUUkH8QBszNNRpPJoNhANdK74o5r5Uy9Q89M
cleos create account eosio eosio.saving EOS7ThT49aqseDtwjaJrTXbcsLn7Cmv2vXCzLKF65yaoDxjHSd5Jq EOS4ycHTjez57nhEa6Rg2TgD2gJLjKbXs2mVhuR1dEYCY8VoevF2D
cleos create account eosio eosio.stake EOS6BEiHYDUQeu3sGcqnYPajHQZRR6pjyyzoq8puHt32eJYfpCNcr EOS7sCv7XwXTGpYiat3TUWSk6cb66xfi1CcGhMrBsPQGraXgW3UEj
cleos create account eosio eosio.upay EOS5YQE9AEJXVRaddFrS1GBFEUeNStGoHGKnTQmyxaHSgVmav16J1 EOS7PsM6TqNER2QiRHsBnCHC3QS4uWCkjCicoatHvZzgoUGVZ7srN
#创建合约
echo "set contract ..."
sleep 6
cleos set contract eosio.msig /mnt/hgfs/yejn/eos/eos/build/contracts/eosio.msig/
sleep 6
cleos set contract eosio /mnt/hgfs/yejn/eos/eos/build/contracts/eosio.system/
sleep 6
cleos push action eosio setpriv '["eosio.msig", 1]' -p eosio@active
#创建3个超级节点账户
echo "new inita initb initc ..."
sleep 4
cleos system newaccount eosio inita EOS5VJv4YxPkv9asb5BfSHoDKSVnbuKfay3cNy2kcciELsCdDeqYB EOS6DyXgyTCTydr3GMxg34w7vmCErcWLjzYtvCeNFUyZR9YXCf1Gv --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
cleos system newaccount eosio initb EOS7P4K4wsKaDAkES6VSyFb6tAMRE5afkniB9jE4Sq9tqTy6yddHb EOS8N3kNs4eUrvFAnKCkjpzL4aou4mmcxJDZ9uoZpTFcvh7WhUxLm --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
cleos system newaccount eosio initc EOS534ZY8Qk6HCAKubu2prUGxbnsq7NqVq6gK8GWnbUh74w6fD7pG EOS7nNUJ9Nibw5uDYzjgKJ618YrD7yLBbAcxQXGmqJk4XjGRicDeg --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
#转账给超级节点系统币
echo "transfer SYS ..."
sleep 2
cleos push action eosio.token transfer '["eosio", "inita","500000000.0000 SYS","vote"]' -p eosio
cleos push action eosio.token transfer '["eosio", "initb","100000000.0000 SYS","vote"]' -p eosio
cleos push action eosio.token transfer '["eosio", "initc","100000000.0000 SYS","vote"]' -p eosio
root@ubuntu:~/inita# cat start.sh
nodeos --data-dir ./data --config-dir ./config --genesis-json ./config/genesis.json
root@ubuntu:~/inita# cat init.sh 解锁钱包,导入密钥,申请超级节点,抵押eos
#创建密钥 cleos create key --to-console
#创建钱包 cleos wallet create -n inita.wallet --to-console 密钥未:"PW5JFFCzQe37RZ2Qd4vjLsXcoKkyZCWJHvaTSWksbEMaRedfGEepS" 要记住钱包密码
#解锁钱包
echo "wallet unlock ..."
cleos wallet unlock -n inita.wallet --password PW5JFFCzQe37RZ2Qd4vjLsXcoKkyZCWJHvaTSWksbEMaRedfGEepS
#导入私钥
echo "wallet import ..."
cleos wallet import -n inita.wallet --private-key 5K5kgoqiTgYbPv5LUxhRrXodiZeJJPxdxSirVyzpPGHhw7qRvwt
cleos wallet import -n inita.wallet --private-key 5JyTcDtN9DCwjAARByqUXKQaSi2xniJL7Puds6AMvnEQfEG2ZHt
#申请超级节点
echo "regproducer ..."
cleos system regproducer inita EOS5VJv4YxPkv9asb5BfSHoDKSVnbuKfay3cNy2kcciELsCdDeqYB http://http-server-address:8888
#押金
ehco "delegatebw ..."
sleep 2
cleos system delegatebw inita inita '200000000.0000 SYS' '200000000.0000 SYS'
root@ubuntu:~/initb# cat start.sh
nodeos --data-dir ./data --config-dir ./config --genesis-json ./config/genesis.json
sh start.sh
root@ubuntu:~/initb# cat init.sh 解锁钱包,导入密钥,申请超级节点,抵押eos
#创建密钥 cleos create key --to-console
#创建钱包 cleos wallet create -n initb.wallet --to-console 密钥未:"PW5Jj5i7f9WmapBsyvhU6JbFqNeCgjcWp56s2GbHUvmzCtQYL8MY2" 要记住钱包密码
#解锁钱包
cleos wallet unlock -n initb.wallet --password PW5Jj5i7f9WmapBsyvhU6JbFqNeCgjcWp56s2GbHUvmzCtQYL8MY2
#导入私钥
cleos wallet import -n initb.wallet --private-key 5HqinXiSMZrNKrEkPuHbkvNDe5vPYDwoNeqmdLtB7yyR7aWpZkT
cleos wallet import -n initb.wallet --private-key 5Ka8i9wkTeevFtsybJZaM7s86AkAizEQYEQs5VWvHNLhfznUHa6
#申请超级节点
echo "regproducer ..."
sleep 2
cleos system regproducer initb EOS7P4K4wsKaDAkES6VSyFb6tAMRE5afkniB9jE4Sq9tqTy6yddHb http://http-server-address:8888
#押金
echo "delegatebw ..."
sleep 2
cleos system delegatebw initb initb '25000000.0000 SYS' '25000000.0000 SYS'
root@ubuntu:~/initc# cat start.sh
nodeos --data-dir ./data --config-dir ./config --genesis-json ./config/genesis.json
sh start.sh 启动节点
root@ubuntu:~/initc# cat init.sh 解锁钱包,导入密钥,申请超级节点,抵押eos
#创建密钥 cleos create key --to-console
#创建钱包 cleos wallet create -n initc.wallet --to-console 密钥未:"PW5HtgAikopEWVgJyw8P57dx4mn4oESPJ97UxS3WWAfEvpzymg6tp" 要记住钱包密码
#解锁钱包
cleos wallet unlock -n initc.wallet --password PW5HtgAikopEWVgJyw8P57dx4mn4oESPJ97UxS3WWAfEvpzymg6tp
#导入私钥
cleos wallet import -n initc.wallet --private-key 5JrmJmyPWPbEG5Tr9La1vzBKYkZfxDCdpwwHk13hBEGKzuixNEv
cleos wallet import -n initc.wallet --private-key 5KjryDqWfsqErEqbHgBq5JmKd613GiQN6uHM1F9AekjM6MuQuTp
#申请超级节点
echo "regproducer ..."
sleep 2
cleos system regproducer initc EOS534ZY8Qk6HCAKubu2prUGxbnsq7NqVq6gK8GWnbUh74w6fD7pG http://http-server-address:8888
#押金
echo "delegatebw ..."
sleep 2
cleos system delegatebw initc initc '25000000.0000 SYS' '25000000.0000 SYS'
root@ubuntu:~/inita# cat vote.sh 用账户inita给3个节点投票
cleos system voteproducer prods inita inita initb initc
查询
过几十秒就可以看到3个超级节点轮流出块了
root@ubuntu:~/inita# cleos get schedule
active schedule version 4
Producer Producer key
============= ==================
inita EOS5VJv4YxPkv9asb5BfSHoDKSVnbuKfay3cNy2kcciELsCdDeqYB
initb EOS7P4K4wsKaDAkES6VSyFb6tAMRE5afkniB9jE4Sq9tqTy6yddHb
initc EOS534ZY8Qk6HCAKubu2prUGxbnsq7NqVq6gK8GWnbUh74w6fD7pG
pending schedule empty
proposed schedule empty
root@ubuntu:~/inita# cleos system listproducers
Producer Producer key Url Scaled votes
inita EOS5VJv4YxPkv9asb5BfSHoDKSVnbuKfay3cNy2kcciELsCdDeqYB http://http-server-address:8888 0.3333
initb EOS7P4K4wsKaDAkES6VSyFb6tAMRE5afkniB9jE4Sq9tqTy6yddHb http://http-server-address:8888 0.3333
initc EOS534ZY8Qk6HCAKubu2prUGxbnsq7NqVq6gK8GWnbUh74w6fD7pG http://http-server-address:8888 0.3333
网友评论