EOS研究系列【怎么同步公网节点】

in #eos6 years ago

这两天简单运行了一下cleos连接EOS主网,但是连接网上节点经常会断,返回数据也比较慢,如果想用得开心点还是得自己跑节点了!

在网上看到很多都是运行本地测试节点,其实我更需要的是同步公共节点数据,找到一两篇文章按其方式完成了了同步节点的配置,记录一下。

如果还没有nodeos、cleos参考:EOS研究系列【mac下编译运行】

创建genesis.json

下载区块链创世文件genesis.json,位置为:https://github.com/EOS-Mainnet/eos/blob/launch-rc-1.0.2/mainnet-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
  }
}

看起来这个文件和Bitshares差别还是挺大的,把这个文件拷贝到自己放eos数据目录下:

(env3) Chaim:~ Chaim$ mkdir eosdata
(env3) Chaim:~ Chaim$ vi genesis.json

genesis.json放上刚下载的内容,我们把目录建在用户根目录下,没有在代码目录下,因为代码目录经常清或重编容易弄丢。

生成config.ini

先执行下面命令在用户目录/eosdata下生成config.ini,执行几秒“Ctrl+C”即可:

Chaim:nodeos Chaim$ ./nodeos -d ~/eosdata/generator_node --config-dir ~/eosdata/generator_node --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --p2p-listen-endpoint localhost:5555

增加p2p节点

编辑~/eosdata/generator_node/config.ini文件,增加p2p节点,节点可以在这取到,太多不全列出,如下节点亲测可用:

p2p-peer-address = 54.38.250.15:19878
p2p-peer-address = mainnet.eospay.host:19876
p2p-peer-address = peer.eosn.io:9876
p2p-peer-address = node.eosflare.io:1883
p2p-peer-address = eos.staked.us:9870

可能很多节点连不上,这还有一份列表,看日志把连接出错的给删除吧!

增加plugins

同样的config.ini,增加以下plugins:

plugin = eosio::producer_plugin 
plugin = eosio::wallet_api_plugin 
plugin = eosio::chain_api_plugin 
plugin = eosio::http_plugin 
plugin = eosio::history_api_plugin

http-server-address

这一项改不改都行,如果keosd没有占用的话就不用改:

# The local IP and port to listen for incoming http connections; set blank to disable. (eosio::http_plugin)
http-server-address = 127.0.0.1:8899

第一次启动

./nodeos -d ~/eosdata/generator_node --config-dir ~/eosdata/generator_node --genesis-json ~/eosdata/genesis.json --delete-all-blocks

以后启动就不需要“--genesis-json”和“--delete-all-blocks”参数了!

直到出现类似以下提示表明已经接收到数据包:

2515041ms thread-0   producer_plugin.cpp:290       on_incoming_block    ] Received block ddc03486114e6a1c... #1000 @ 2018-06-09T12:06:33.000 signed by eosio [trxs: 1, lib: 999, conf: 0, latency: 2345722041 ms]

不过这些节点在国内连起来很多都有问题,不知道是网络问题呢还是节点问题!同步了一天数据才同步完成!

轻松访问EOS数据

(env3) Chaim:cleos Chaim$ ./cleos -u http://127.0.0.1:8899 get info

早两天用网上节点取块数据经常一会就卡住,现在用本地节点应该不会有这些问题了吧!

踩个坑

同步得好好的,突然退出了,需要“replay”,replay就是区块数据重新跑一遍,可千万不要重新下载区块啊,都跑一天了!

libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> >: Could not restore object, most likely a uniqueness constraint was violated
./pub.sh: line 1: 78500 Abort trap: 6           ./nodeos -d ~/eosdata/generator_node --config-dir ~/eosdata/generator_node

Chaim:nodeos Chaim$ ./pub.sh 
2433929ms thread-0   chain_plugin.cpp:209          plugin_initialize    ] initializing chain plugin
2434000ms thread-0   main.cpp:123                  main                 ] database dirty flag set (likely due to unclean shutdown): replay required

加上“--replay-blockchain”参数还是出错:

Chaim:nodeos Chaim$ ./nodeos -d ~/eosdata/generator_node --config-dir ~/eosdata/generator_node --replay-blockchain
3086942ms thread-0   chain_plugin.cpp:209          plugin_initialize    ] initializing chain plugin
3086942ms thread-0   chain_plugin.cpp:341          plugin_initialize    ] Replay requested: deleting state database
3087788ms thread-0   main.cpp:123                  main                 ] database dirty flag set (likely due to unclean shutdown): replay required

还有一招“--hard-replay-blockchain”先试试:

Chaim:nodeos Chaim$ ./nodeos -d ~/eosdata/generator_node --config-dir ~/eosdata/generator_node --replay-blockchain --hard-replay-blockchain
3178561ms thread-0   chain_plugin.cpp:209          plugin_initialize    ] initializing chain plugin
3178562ms thread-0   chain_plugin.cpp:322          plugin_initialize    ] Hard replay requested: deleting state database
3178646ms thread-0   block_log.cpp:323             repair_log           ] Recovering Block Log...
3178652ms thread-0   block_log.cpp:343             repair_log           ] Moved existing blocks directory to backup location: '/Users/Chaim/eosdata/generator_node/blocks-2018-07-07T11:52:58.646'
3178653ms thread-0   block_log.cpp:348             repair_log           ] Reconstructing '/Users/Chaim/eosdata/generator_node/blocks/blocks.log' from backed up block log
3231752ms thread-0   block_log.cpp:458             repair_log           ] Existing block log was undamaged. Recovered all irreversible blocks up to block number 4419270.
3231891ms thread-0   chain_plugin.cpp:534          recover_reversible_b ] Reconstructing '/Users/Chaim/eosdata/generator_node/blocks/reversible' from backed up reversible directory
3232222ms thread-0   chain_plugin.cpp:577          recover_reversible_b ] Recovered 2890 blocks from reversible block database: blocks 4419271 to 4422160

结果很慢的执行还是出错了,最终没有办法重新走第一次启动的过程,删除全部区块重来!

参考

https://blog.csdn.net/lizhe_dashuju/article/details/80746377

https://eosio.stackexchange.com/questions/725/how-to-vote-using-cleos/726#726


感谢您阅读 @chaimyu 的帖子,期待您能留言交流!

Sort:  

你好吗?小可可,淘气包帅还是我帅? 小可可,啥星座的? 小可可,你有半块橡皮吗?假如我的留言打扰到你,请回复“取消”。

Congratulations @chaimyu! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Quarter Finals - Day 2


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.29
TRX 0.11
JST 0.033
BTC 63901.15
ETH 3133.40
USDT 1.00
SBD 4.05