基于EOS源代码搭建自己的多节点链
微信:jtyd008
打赏地址:
BTC(USDT) 1Hd5fKmTrvtdL51yeh5prN8FwXjegaSFa2
ETH 0x6e81623f6345f428201ca18cb5ef5de790b5aea0
(注:1.本文操作前提是EOS(最新版v1.0.8)代码编译正常,有一定EOS基础 ; 2. 生产环境 ubuntu 16.04 LTS ;3.以下操作需要根据具体情况 变通处理!!)
一 .修改代币符号
1.在 eos 源代码中,查找包含 “SYS” 的文件 (有好几个地方), 把它们修改为自己的,如改为 “SWC”。
2. eosio账户公钥写死在代码中, 在代码根目录 CMakeList.txt里面,找到 EOSIO_ROOT_KEY,改为自己创建的公钥。并把新的密钥对 要在 config.ini文件中保存,见文件中 “signature-provider = 。。。”。
3.编译,安装。
二 .配置文件
1.建议在 nodeos 程序运行目录创建 config文件夹,保存配置文件;同时创建 data文件夹 ,保存区块文件.
2.搭建4个独立IP 的 节点(同一局域网),命名为:eosio, inita,initb,initc。所有节点的 genesis.json文件一样,否则不是一个网络,不能通信。
3.genesis.json 文件内容,如下:
{
"initial_timestamp": "2018-06-08T08:08:08.888",
"initial_key": "public key", #####必须是 eosio 节点 的 公钥
"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_winSYSw": 600,
"max_transaction_delay": 3888000,
"max_inline_action_size": 4096,
"max_inline_action_depth": 4,
"max_authority_depth": 6
}
}
4.eosio 节点的 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-peer-address = 192.168.8.109:9876
p2p-peer-address = 192.168.8.52:9876
p2p-peer-address = 192.168.8.216:9876
agent-name = "SWC chain"
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 ## 只是eosio节点 为true
max-transaction-time = 1000
required-participation = 33
producer-name = eosio ## 注意节点账户名称,下面是 账户的 keys
signature-provider =
public key=KEY:"public key"
wallet-dir = "."
unlock-timeout = 90000
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
plugin = eosio::history_api_plugin
5.inita ,initb,initc 节点的 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-peer-address = 192.168.8.215:9876 ##其他节点的 p2p 地址及端口,不要填写本节点的IP!
p2p-peer-address = 192.168.8.216:9876
p2p-peer-address = 192.168.8.52:9876
agent-name = "SWC chain"
allowed-connection = any
max-clients = 25
connection-cleanup-period = 30
network-version-match = 0
sync-fetch-span = 100
max-implicit-request = 1500
max-transaction-time = 30
required-participation = 33
producer-name = inita ## 设置本节点账户名称,下面是 该账户的 keys ,根据自己的去修改!!
signature-provider = "public key"=KEY:"key"
txn-reference-block-lag = 0
wallet-dir = "."
unlock-timeout = 90000
plugin = eosio::chain_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
plugin = eosio::history_api_plugin
三 .创建与发行代币
1.启动四个节点nodeos程序
(把 config.ini, genesis.json文件放到 config 目录, 区块文件放在 data目录)
命令如下:
rm /home/pay_eos/nohup.out
rm -rf /data/nodeos4/data/*
rm -rf /data/nodeos3/data/*
rm -rf /data/nodeos2/data/*
rm -rf /data/nodeos1/data/*
suSYS ./eosio_build.sh -o Debug
cd /home/pay_eos/eos/build/programs/nodeos
nohup ./nodeos --contracts-console --max-transaction-time=1000 --verbose-http-errors --data-dir /data/nodeos1/data --config-dir /data/nodeos1/config --genesis-json /data/nodeos1/config/genesis.json &
nohup ./nodeos --contracts-console --max-transaction-time=1000 --verbose-http-errors --data-dir /data/nodeos2/data --config-dir /data/nodeos2/config --genesis-json /data/nodeos2/config/genesis.json &
nohup ./nodeos --contracts-console --max-transaction-time=1000 --verbose-http-errors --data-dir /data/nodeos3/data --config-dir /data/nodeos3/config --genesis-json /data/nodeos3/config/genesis.json &
nohup ./nodeos --contracts-console --max-transaction-time=1000 --verbose-http-errors --data-dir /data/nodeos4/data --config-dir /data/nodeos4/config --genesis-json /data/nodeos4/config/genesis.json &
2.在 eosio 节点上创建钱包 swcwallet ,并导入eosio账户私钥
[pay_eos@cc-node1 cleos]$ ./cleos wallet create
eosio public key: public key
eosio private key: privete key
Public key public key
Private key privete key
./cleos wallet import
private key: imported private key for: public key
./cleos wallet unlock
3.创建发布token的帐号eosio.token (需自己去创建 key,并不私钥导入到钱包)
./cleos create account eosio eosio.token public key public key
4.发布eosio.token合约 (在EOS源代码的编译后的 build/下面执行)
./cleos set contract eosio.token ../../contracts/eosio.token
5.创建和发布代币(SWC)
./cleos push action eosio.token create '["eosio","10000000000.0000 SYS",0,0,0]' -p eosio.token
./cleos push action eosio.token issue '["eosio","10000000000.0000 SYS","issue"]' -p eosio
四 .发布 eosio.system合约
1.创建下面系统账户(共用一套公钥,实际情况 最好使用不同key,并不key导入到钱包)
./cleos create account eosio eosio.bpay public key public key
./cleos create account eosio eosio.msig public key public key
./cleos create account eosio eosio.name public key public key
./cleos create account eosio eosio.names public key public key
./cleos create account eosio eosio.ram public key public key
./cleos create account eosio eosio.ramfee public key public key
./cleos create account eosio eosio.saving public key public key
./cleos create account eosio eosio.stake public key public key
./cleos create account eosio eosio.upay public key public key
2.设置eosio.msig合约
msig合约支持并简化了权限级别的定义和管理以及执行多重签名操作。
./cleos set contract eosio.msig ../../contracts/eosio.msig
3.部署eosio.system合约(必须先执行上面的 “创建下面系统账户”)
该合约为几乎所有基于令牌的操作行为提供了操作。在安装系统合同之前,操作是独立于会计完成的。
一旦系统合同启用,行动现在对他们有一个经济因素。资源(cpu,网络,内存)必须付费。同样,必须支付新帐户。
系统合同使得令牌能够被放置和不被冻结,被购买的资源,可能的生产者被注册并且随后被投票,生产者奖励被要求,被设置 的特权和限制等等。
./cleos set contract eosio ../../contracts/eosio.system
4.在安装eosio.system合同后,我们希望尽快将eosio.msig设置为特权帐户,以便它可以代表eosio帐户进行授权。尽快eosio将辞职,eosio.prods将接管。
使eosio.msig成为一个特权帐户。我们使用以下方法使eosio.msig有特权。
./cleos push action eosio setpriv '["eosio.msig", 1]' -p eosio@active
五 .注册BP及投票
1.用下面这个命令创建投票账户:
部署了eosio.system合约之后,cleos create account这个命令就不能创建账户了。
为 inita,initb,initc 准备不同的 key, 并导入钱包。 然后创建各个出块节点的 账户:inita,initb,initc。
./cleos system newaccount eosio inita public key public key --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
./cleos system newaccount eosio initb public key public key --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
./cleos system newaccount eosio initc public key public key --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
2.将所有需要出块的节点(配置文件中 producer-name = inita)注册成bp
./cleos system regproducer inita public key http://127.0.0.1:8888
./cleos system regproducer initb public key http://127.0.0.1:8888
./cleos system regproducer initc public key http://127.0.0.1:8888
3.给创建的账户转账
./cleos push action eosio.token transfer '["eosio", "inita","100000000.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
4.锁定代币
./cleos system delegatebw inita inita '25000000.0000 SYS' '25000000.0000 SYS'
./cleos system delegatebw initb initb '25000000.0000 SYS' '25000000.0000 SYS'
./cleos system delegatebw initc initc '25000000.0000 SYS' '25000000.0000 SYS'
5.给出块节点投票
给 inita节点投票如下
./cleos system voteproducer prods inita inita
./cleos system voteproducer prods initb inita
./cleos system voteproducer prods initc inita
给 initb节点投票如下
./cleos system voteproducer prods inita initb
./cleos system voteproducer prods initb initb
./cleos system voteproducer prods initc initb
给 initc节点投票如下
./cleos system voteproducer prods inita initc
./cleos system voteproducer prods initb initc
./cleos system voteproducer prods initc initc
投票后,过一段时间,可以看到 节点inita,initb,initc 轮流出块。eosio节点将停止出块, 不能再给 eosio节点投票出块, eosio节点在此完成使命!
6.检查结果
./cleos system listproducers
./cleos get info
7. 检查发布代币情况
./cleos get currency balance eosio.token eosio
./cleos get currency balance eosio.token eosio.token
./cleos get table eosio.token eosio.token accounts
团队成立于2011年,运用认知盈余,我们聚合了大量的民间高手,通过挖掘技术发现未知,创造价值。团队通过紧密协作服务各应用领域。目前团队成员主要从事金融、电信、互联网等行业,积累了广泛且丰富的多行业经验。