动态 EOS 1.1 新功能源码分析

lome · July 18, 2018 · Last by dnbstarz replied at August 22, 2018 · 10373 hits
  1. 首先值得庆祝的是继3个月以后eosio::mongo_db_plugin终于可用了。
  2. nodeos 性能提升,再同步的状态下,加了许多判断,使得在同步状态下,速度更快。

添加start_block_result::waiting状态,当状态为waiting时不做任何操作,避免了程序运行行不必要的代码。 prodcucer_plugin 添加: enable-stale-speculation, 设置为false可加快

if( !_production_enabled ) {
      _pending_block_mode = pending_block_mode::speculating;
   } else if( _producers.find(scheduled_producer.producer_name) == _producers.end()) {
      _pending_block_mode = pending_block_mode::speculating;
   } else if (signature_provider_itr == _signature_providers.end()) {
      elog("Not producing block because I don't have the private key for ${scheduled_key}", ("scheduled_key", scheduled_producer.block_signing_key));
      _pending_block_mode = pending_block_mode::speculating;
   } else if ( _pause_production ) {
      elog("Not producing block because production is explicitly paused");
      _pending_block_mode = pending_block_mode::speculating;
   } else if ( _max_irreversible_block_age_us.count() >= 0 && irreversible_block_age >= _max_irreversible_block_age_us ) {
      elog("Not producing block because the irreversible block is too old [age:${age}s, max:${max}s]", ("age", irreversible_block_age.count() / 1'000'000)( "max", _max_irreversible_block_age_us.count() / 1'000'000 ));
      _pending_block_mode = pending_block_mode::speculating;
   }

如果enable-stale-production=false、不是生产者、不是产块生产者、不签名块、停止生产块、不可逆块的到现在的时间大于最大的不可逆块时间:设置_pending_block_mode=speculating

if (_pending_block_mode == pending_block_mode::producing) {
      // determine if our watermark excludes us from producing at this point
      if (currrent_watermark_itr != _producer_watermarks.end()) {
         if (currrent_watermark_itr->second >= hbs->block_num + 1) {
            elog("Not producing block because \"${producer}\" signed a BFT confirmation OR block at a higher block number (${watermark}) than the current fork's head (${head_block_num})",
                ("producer", scheduled_producer.producer_name)
                ("watermark", currrent_watermark_itr->second)
                ("head_block_num", hbs->block_num));
            _pending_block_mode = pending_block_mode::speculating;
         }
      }
   }

如果是产块生产者,但是不是目前正在产块的生产者:设置_pending_block_mode=speculating

_pending_block_mode=speculating,则返回start_block_result=waiting

if (result == start_block_result::failed) {
    ...............
   } else if (result == start_block_result::waiting) {
      // nothing to do until more blocks arrive
   } else if (_pending_block_mode == pending_block_mode::producing) {

如果start_block_result=waiting则不执行任何代码。 从而提升了nodeos的效率。

  1. chain_plugin中加入chain-state-db-guard-size-mbreversible-blocks-db-guard-size-mb void controller::validate_db_available_size() const { const auto free = db().get_segment_manager()->get_free_memory(); const auto guard = my->conf.state_guard_size; EOS_ASSERT(free >= guard, database_guard_exception, "database free: ${f}, guard size: ${g}", ("f", free)("g",guard)); }
chian_plugin.cpp
void chain_plugin::handle_guard_exception(const chain::guard_exception& e) const {
+   log_guard_exception(e);
+
+   // quit the app
+   app().quit();
+}

若可用内存小于chain-state-db-guard-size-mbreversible-blocks-db-guard-size-mb则打印报警日志,并正常的关闭,这将不会出现需要重新同步的情况。

共收到 45 条回复

现在BP都升级到1.1了吗

这个就不知道了。

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up