精华内容
下载资源
问答
  • Please report this message and include the following information to us. 把防火墙壁关一下试试 ^^
    Please report this message and include the following information to us.
    

    把防火墙壁关一下试试 ^^

    展开全文
  • Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/lucid/main/source/Sources 404 Not Found [IP: 91.189.91.26 80] 使用的系统为:http://old-releases.ubuntu.com/releases/11.10/中的ubuntu-11.10-...

    Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/lucid/main/source/Sources 404 Not Found [IP: 91.189.91.26 80]

     

    使用的系统为:http://old-releases.ubuntu.com/releases/11.10/ 中的ubuntu-11.10-server-amd64.iso

     

    解决原理粘贴https://askubuntu.com/questions/840036/failed-to-fetch-http-us-archive-ubuntu-com-ubuntu-dists-lucid-main-source-sourThomas Ward的回答。

    主要问题为下载库源出错,需进行修改。

    参考完Thomas Ward的回答,发现仍然有些源仍然不能获取,ERR 404。

    于是乎将所有源地址都替换成old-releases.ubuntu.com;

    以下为修改后的/etc/apt/source.list

    # deb cdrom:[Ubuntu 11.10 _Oneiric Ocelot_ - Release amd64 (20111012)]/ dists/oneiric/main/binary-i386/
    
    # deb cdrom:[Ubuntu 11.10 _Oneiric Ocelot_ - Release amd64 (20111012)]/ oneiric main restricted
    
    # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    # newer versions of the distribution.
    deb http://old-releases.ubuntu.com/ubuntu/ oneiric main restricted
    deb-src http://old-releases.ubuntu.com/ubuntu/ oneiric main restricted
    
    ## Major bug fix updates produced after the final release of the
    ## distribution.
    deb http://old-releases.ubuntu.com/ubuntu/ oneiric-updates main restricted
    deb-src http://old-releases.ubuntu.com/ubuntu/ oneiric-updates main restricted
    
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team. Also, please note that software in universe WILL NOT receive any
    ## review or updates from the Ubuntu security team.
    deb http://old-releases.ubuntu.com/ubuntu/ oneiric universe
    deb-src http://old-releases.ubuntu.com/ubuntu/ oneiric universe
    deb http://old-releases.ubuntu.com/ubuntu/ oneiric-updates universe
    deb-src http://old-releases.ubuntu.com/ubuntu/ oneiric-updates universe
    
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
    ## team, and may not be under a free licence. Please satisfy yourself as to 
    ## your rights to use the software. Also, please note that software in 
    ## multiverse WILL NOT receive any review or updates from the Ubuntu
    ## security team.
    deb http://old-releases.ubuntu.com/ubuntu/ oneiric multiverse
    deb-src http://old-releases.ubuntu.com/ubuntu/ oneiric multiverse
    deb http://old-releases.ubuntu.com/ubuntu/ oneiric-updates multiverse
    deb-src http://old-releases.ubuntu.com/ubuntu/ oneiric-updates multiverse
    
    ## N.B. software from this repository may not have been tested as
    ## extensively as that contained in the main release, although it includes
    ## newer versions of some applications which may provide useful features.
    ## Also, please note that software in backports WILL NOT receive any review
    ## or updates from the Ubuntu security team.
    deb http://old-releases.ubuntu.com/ubuntu/ oneiric-backports main restricted universe multiverse
    deb-src http://old-releases.ubuntu.com/ubuntu/ oneiric-backports main restricted universe multiverse
    
    deb http://old-releases.ubuntu.com/ubuntu oneiric-security main restricted
    deb-src http://old-releases.ubuntu.com/ubuntu oneiric-security main restricted
    deb http://old-releases.ubuntu.com/ubuntu oneiric-security universe
    deb-src http://old-releases.ubuntu.com/ubuntu oneiric-security universe
    deb http://old-releases.ubuntu.com/ubuntu oneiric-security multiverse
    deb-src http://old-releases.ubuntu.com/ubuntu oneiric-security multiverse
    
    ## Uncomment the following two lines to add software from Canonical's
    ## 'partner' repository.
    ## This software is not part of Ubuntu, but is offered by Canonical and the
    ## respective vendors as a service to Ubuntu users.
    # deb http://archive.canonical.com/ubuntu oneiric partner
    # deb-src http://archive.canonical.com/ubuntu oneiric partner
    
    ## This software is not part of Ubuntu, but is offered by third-party
    ## developers who want to ship their latest software.
    deb http://old-releases.ubuntu.com/ubuntu oneiric main
    deb-src http://old-releases.ubuntu.com/ubuntu oneiric main
    deb http://old-releases.ubuntu.com/ lucid partner
    deb-src http://old-releases.ubuntu.com/ lucid partner
    deb http://old-releases.ubuntu.com/ lucid partner
    deb-src http://old-releases.ubuntu.com/ lucid partner
    deb http://old-releases.ubuntu.com/ lucid partner
    deb-src http://old-releases.ubuntu.com/ lucid partner
    deb http://old-releases.ubuntu.com/ lucid partner
    deb-src http://old-releases.ubuntu.com/ lucid partner
    deb http://archive.canonical.com/ lucid partner
    deb-src http://archive.canonical.com/ lucid partner

    修改之后执行:

    sudo apt-get update

     

     

    附上原来的/etc/opt/source.list

    # deb cdrom:[Ubuntu 11.10 _Oneiric Ocelot_ - Release amd64 (20111012)]/ dists/oneiric/main/binary-i386/
    
    # deb cdrom:[Ubuntu 11.10 _Oneiric Ocelot_ - Release amd64 (20111012)]/ oneiric main restricted
    
    # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    # newer versions of the distribution.
    deb http://us.archive.ubuntu.com/ubuntu/ oneiric main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric main restricted
    
    ## Major bug fix updates produced after the final release of the
    ## distribution.
    deb http://us.archive.ubuntu.com/ubuntu/ oneiric-updates main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric-updates main restricted
    
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team. Also, please note that software in universe WILL NOT receive any
    ## review or updates from the Ubuntu security team.
    deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric universe
    deb http://us.archive.ubuntu.com/ubuntu/ oneiric-updates universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric-updates universe
    
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
    ## team, and may not be under a free licence. Please satisfy yourself as to 
    ## your rights to use the software. Also, please note that software in 
    ## multiverse WILL NOT receive any review or updates from the Ubuntu
    ## security team.
    deb http://us.archive.ubuntu.com/ubuntu/ oneiric multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric multiverse
    deb http://us.archive.ubuntu.com/ubuntu/ oneiric-updates multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric-updates multiverse
    
    ## N.B. software from this repository may not have been tested as
    ## extensively as that contained in the main release, although it includes
    ## newer versions of some applications which may provide useful features.
    ## Also, please note that software in backports WILL NOT receive any review
    ## or updates from the Ubuntu security team.
    deb http://us.archive.ubuntu.com/ubuntu/ oneiric-backports main restricted universe multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ oneiric-backports main restricted universe multiverse
    
    deb http://security.ubuntu.com/ubuntu oneiric-security main restricted
    deb-src http://security.ubuntu.com/ubuntu oneiric-security main restricted
    deb http://security.ubuntu.com/ubuntu oneiric-security universe
    deb-src http://security.ubuntu.com/ubuntu oneiric-security universe
    deb http://security.ubuntu.com/ubuntu oneiric-security multiverse
    deb-src http://security.ubuntu.com/ubuntu oneiric-security multiverse
    
    ## Uncomment the following two lines to add software from Canonical's
    ## 'partner' repository.
    ## This software is not part of Ubuntu, but is offered by Canonical and the
    ## respective vendors as a service to Ubuntu users.
    # deb http://archive.canonical.com/ubuntu oneiric partner
    # deb-src http://archive.canonical.com/ubuntu oneiric partner
    
    ## This software is not part of Ubuntu, but is offered by third-party
    ## developers who want to ship their latest software.
    deb http://extras.ubuntu.com/ubuntu oneiric main
    deb-src http://extras.ubuntu.com/ubuntu oneiric main
    deb http://archive.canonical.com/ lucid partner
    deb-src http://archive.canonical.com/ lucid partner
    deb http://archive.canonical.com/ lucid partner
    deb-src http://archive.canonical.com/ lucid partner
    deb http://archive.canonical.com/ lucid partner
    deb-src http://archive.canonical.com/ lucid partner
    deb http://archive.canonical.com/ lucid partner
    deb-src http://archive.canonical.com/ lucid partner

     

    展开全文
  • Can animals be made to work for us? Some scientists think that one day animals may be taught to do a number of simple jobs. They say that in a film or on TV, we may see elephants or monkeys, dogs, ...

    Can animals be made to work for us? Some scientists think that one day animals may be taught to do a number of simple jobs. They say that in a film or on TV, we may see elephants or monkeys, dogs, bears or other animals doing a lot of things. If you watch carefully, you may find that those animals are always given something to eat in return for doing them. The scientists said that many different animals may be taught to do a number of simple jobs if they know they will get something to eat in return. Of course, as we know, dogs can be used to guard a house. And elephants can be used to do some heavy jobs. And we can also teach animals to work in factories. Apes(猩猩), for example, have been used in America to help make cars. And scientists believe that these large monkeys may one day get in crops(庄家) and even drive trains.

     

    听力网址链接:http://www.tingroom.com/lesson/dxyyljtldw/123801.html

    展开全文
  • EOS 向节点提交交易时失败 ...EOS 向节点提交交易时失败,提示 billed CPU time (Y us) is greater than the maximum billable CPU time for the transaction (X us). 本文通过分析源代码来一探...

    EOS 向节点提交交易时失败问题分析

    EOS 向节点提交交易时失败,提示 billed CPU time (Y us) is greater than the maximum billable CPU time for the transaction (X us).

    本文通过分析源代码来一探这个失败的原因,首先给出结论:

    • 当前时间窗口内(24小时)用户最大 CPU 时间 = 全网总 CPU 时间 * 当前用户质押 EOS 数量 / 所有用户质押 EOS 数量

    • 当前时间窗口内用户可用 CPU 时间 = 当前用户最大 CPU 时间 - 当前用户已经使用 CPU 时间

    • 当前用户已经使用 CPU 时间是实时变化的:(1 - t / 24) * t 时间之前使用的资源大小,直到距离上次 CPU 资源使用 24 小时后(t = 24)完全恢复

    • Get Account 接口看到的不是实时可用的资源使用量,而是上一笔交易之后缓存的资源使用量

    • 向 RPC 节点提交交易时 RPC 节点会计算出当前交易 CPU 使用量,这个 CPU 使用量和当前 RPC 节点 CPU 使用情况有关,通过系统计时器计算时间,因此,RPC 节点计算出的交易 CPU 使用量不是最终上链时的交易使用量,最终交易时的 CPU 使用量由打包节点决定。

    • 因此,当质押 CPU EOS 数量固定时,向 RPC 节点提交交易时,CPU 资源需要满足 交易使用 CPU 资源的大小 < 账户可用 CPU 资源大小,因此提交交易能否成功有两方面原因:

      • RPC 节点 CPU 状态,决定了交易使用 CPU 资源的大小
      • 全网可用 CPU 资源,决定了账户可用 CPU 资源大小
    • 所以

      • 可以把交易提交到更快(CPU 空闲 / 服务器配置高)的 RPC 节点
      • 等待全网可用 CPU 资源增多,账户分配的可用 CPU 增多(错峰)
      • 增大 CPU 资源 EOS 质押比例,获得更多的 CPU 使用权重(质押更多 EOS 在 CPU 资源上)

    看完结论如果想继续看实现,请看下文,不过,我,懒,简单贴几段代码…

    错误报出的位置

    函数:validate_cpu_usage_to_bill

    https://github.com/EOSIO/eos/blob/e19afc8072219282a7c3fc20e47aa80cb70299e4/libraries/chain/transaction_context.cpp

    void transaction_context::validate_cpu_usage_to_bill( int64_t billed_us, bool check_minimum )const {
      if (!control.skip_trx_checks()) {
        if( check_minimum ) {
          const auto& cfg = control.get_global_properties().configuration;
          EOS_ASSERT( billed_us >= cfg.min_transaction_cpu_usage, transaction_exception,
                     "cannot bill CPU time less than the minimum of ${min_billable} us",
                     ("min_billable", cfg.min_transaction_cpu_usage)("billed_cpu_time_us", billed_us)
                    );
        }
    
        if( billing_timer_exception_code == block_cpu_usage_exceeded::code_value ) {
          EOS_ASSERT( billed_us <= objective_duration_limit.count(),
                     block_cpu_usage_exceeded,
                     "billed CPU time (${billed} us) is greater than the billable CPU time left in the block (${billable} us)",
                     ("billed", billed_us)("billable", objective_duration_limit.count())
                    );
        } else {
          if (cpu_limit_due_to_greylist) {
            EOS_ASSERT( billed_us <= objective_duration_limit.count(),
                       greylist_cpu_usage_exceeded,
                       "billed CPU time (${billed} us) is greater than the maximum greylisted billable CPU time for the transaction (${billable} us)",
                       ("billed", billed_us)("billable", objective_duration_limit.count())
                      );
          } else {
            // 这里抛出的错误
            EOS_ASSERT( billed_us <= objective_duration_limit.count(),
                       tx_cpu_usage_exceeded,
                       "billed CPU time (${billed} us) is greater than the maximum billable CPU time for the transaction (${billable} us)",
                       ("billed", billed_us)("billable", objective_duration_limit.count())
                      );
          }
        }
      }
    }
    

    从函数中可以发现,错误在与 billed_us <= objective_duration_limit.count() 条件没有满足。其中 billed_us 指交易所需要的 CPU 时间,objective_duration_limit.count() 指一个上限,后文介绍上限是多少。

    运行交易所需要的时间

    从 transaction_context init 到 finalize

    看中文注释:

    void transaction_context::finalize() {
      EOS_ASSERT( is_initialized, transaction_exception, "must first initialize" );
    
      if( is_input ) {
        auto& am = control.get_mutable_authorization_manager();
        for( const auto& act : trx.actions ) {
          for( const auto& auth : act.authorization ) {
            am.update_permission_usage( am.get_permission(auth) );
          }
        }
      }
    
      auto& rl = control.get_mutable_resource_limits_manager();
      for( auto a : validate_ram_usage ) {
        rl.verify_account_ram_usage( a );
      }
    
      // Calculate the new highest network usage and CPU time that all of the billed accounts can afford to be billed
      int64_t account_net_limit = 0;
      int64_t account_cpu_limit = 0;
      bool greylisted_net = false, greylisted_cpu = false;
      std::tie( account_net_limit, account_cpu_limit, greylisted_net, greylisted_cpu) = max_bandwidth_billed_accounts_can_pay();
      net_limit_due_to_greylist |= greylisted_net;
      cpu_limit_due_to_greylist |= greylisted_cpu;
    
      // Possibly lower net_limit to what the billed accounts can pay
      if( static_cast<uint64_t>(account_net_limit) <= net_limit ) {
        // NOTE: net_limit may possibly not be objective anymore due to net greylisting, but it should still be no greater than the truly objective net_limit
        net_limit = static_cast<uint64_t>(account_net_limit);
        net_limit_due_to_block = false;
      }
    
      // Possibly lower objective_duration_limit to what the billed accounts can pay
      if( account_cpu_limit <= objective_duration_limit.count() ) {
        // NOTE: objective_duration_limit may possibly not be objective anymore due to cpu greylisting, but it should still be no greater than the truly objective objective_duration_limit
        objective_duration_limit = fc::microseconds(account_cpu_limit);
        billing_timer_exception_code = tx_cpu_usage_exceeded::code_value;
      }
    
      net_usage = ((net_usage + 7)/8)*8; // Round up to nearest multiple of word size (8 bytes)
    
      eager_net_limit = net_limit;
      check_net_usage();
    
      auto now = fc::time_point::now();
      trace->elapsed = now - start;
    
      // 交易结束后获取当前时间,然后计算 now 到 交易开始时的时间,保存到 billed_cpu_time_us
      // 具体可以跟进这个函数看
      update_billed_cpu_time( now );
    
      // 调用时间资源验证函数
      validate_cpu_usage_to_bill( billed_cpu_time_us );
    
      rl.add_transaction_usage( bill_to_accounts, static_cast<uint64_t>(billed_cpu_time_us), net_usage,
                               block_timestamp_type(control.pending_block_time()).slot ); // Should never fail
    }
    

    update_billed_cpu_time 如下:

    uint32_t transaction_context::update_billed_cpu_time( fc::time_point now ) {
      if( explicit_billed_cpu_time ) return static_cast<uint32_t>(billed_cpu_time_us);
    
      const auto& cfg = control.get_global_properties().configuration;
      // 当前时间减去 pseudo_start
      billed_cpu_time_us = std::max( (now - pseudo_start).count(), static_cast<int64_t>(cfg.min_transaction_cpu_usage) );
    
      return static_cast<uint32_t>(billed_cpu_time_us);
    }
    
    void transaction_context::pause_billing_timer() {
      if( explicit_billed_cpu_time || pseudo_start == fc::time_point() ) return; // either irrelevant or already paused
    
      auto now = fc::time_point::now();
      billed_time = now - pseudo_start;
      deadline_exception_code = deadline_exception::code_value; // Other timeout exceptions cannot be thrown while billable timer is paused.
      // 时间赋值
      pseudo_start = fc::time_point();
      transaction_timer.stop();
    }
    

    时间相关操作在另一个仓库 fc 里:https://github.com/EOSIO/fc/blob/e95a03eed1796a3054e02e67f1171f8c9fdb57e5/src/time.cpp

    同时要注意 void transaction_context::finalize() 函数里的 objective_duration_limit

    // Possibly lower objective_duration_limit to what the billed accounts can pay
    if( account_cpu_limit <= objective_duration_limit.count() ) {
    // NOTE: objective_duration_limit may possibly not be objective anymore due to cpu greylisting, but it should still be no greater than the truly objective objective_duration_limit
    // 如果用户的可用 cpu 时间小于 objective_duration_limit
    // objective_duration_limit 赋值为 account_cpu_limit 用户可用的时间
    objective_duration_limit = fc::microseconds(account_cpu_limit);
    billing_timer_exception_code = tx_cpu_usage_exceeded::code_value;
    

    从上面可以看出,交易的运行时间为交易执行开始到结束时间之差,那么问题来了,如果服务器 CPU 空闲,在交易执行时没有其他任务打断,该交易执行时间会比较短;当 CPU 繁忙的,频繁的上下文切换会导致交易执行时间增加。交易也因提交到 RPC 所在服务器的配置,服务器 CPU 情况而定。

    那最终以哪个为准呢?以打包该交易的节点所计算出的时间为准,打包该交易时会把交易 CPU 用时放在交易中,然后广播给其他超级节点。

    交易可用时间上限

    
    // 下面函数 init 函数中用到了
    uint64_t resource_limits_manager::get_block_cpu_limit() const {
       const auto& state = _db.get<resource_limits_state_object>();
       const auto& config = _db.get<resource_limits_config_object>();
       // cpu_limit_parameters 可以发现是从配置中获取的
       // cpu_limit_parameters 设定来自:https://github.com/EOSIO/eos/blob/a2317d380de2ca4b8753673ee42fdfd6fb1b4819/libraries/chain/include/eosio/chain/resource_limits_private.hpp
       // 可以发现 max 指的是 default_max_block_cpu_usage https://github.com/EOSIO/eos/blob/e19afc8072219282a7c3fc20e47aa80cb70299e4/libraries/chain/include/eosio/chain/config.hpp
       // config.hpp 中
       // const static uint32_t   default_max_block_cpu_usage                 = 200'000; /// max block 
       // pending_cpu_usage 指队列中的时间
       return config.cpu_limit_parameters.max - state.pending_cpu_usage;
    }
    
    void transaction_context::init(uint64_t initial_net_usage)
    {
      EOS_ASSERT( !is_initialized, transaction_exception, "cannot initialize twice" );
      const static int64_t large_number_no_overflow = std::numeric_limits<int64_t>::max()/2;
    
      const auto& cfg = control.get_global_properties().configuration;
      auto& rl = control.get_mutable_resource_limits_manager();
    
      net_limit = rl.get_block_net_limit();
    
      // get_block_cpu_limit 首先获得一个可用时间
      objective_duration_limit = fc::microseconds( rl.get_block_cpu_limit() );
      _deadline = start + objective_duration_limit;
    
      // Possibly lower net_limit to the maximum net usage a transaction is allowed to be billed
      if( cfg.max_transaction_net_usage <= net_limit ) {
        net_limit = cfg.max_transaction_net_usage;
        net_limit_due_to_block = false;
      }
    
      // 和配置单个交易最大可用 CPU 时间比较
      // Possibly lower objective_duration_limit to the maximum cpu usage a transaction is allowed to be billed
      if( cfg.max_transaction_cpu_usage <= objective_duration_limit.count() ) {
        objective_duration_limit = fc::microseconds(cfg.max_transaction_cpu_usage);
        billing_timer_exception_code = tx_cpu_usage_exceeded::code_value;
        _deadline = start + objective_duration_limit;
      }
    
      // Possibly lower net_limit to optional limit set in the transaction header
      uint64_t trx_specified_net_usage_limit = static_cast<uint64_t>(trx.max_net_usage_words.value) * 8;
      if( trx_specified_net_usage_limit > 0 && trx_specified_net_usage_limit <= net_limit ) {
        net_limit = trx_specified_net_usage_limit;
        net_limit_due_to_block = false;
      }
      
      // 和交易头比较
      // Possibly lower objective_duration_limit to optional limit set in transaction header
      if( trx.max_cpu_usage_ms > 0 ) {
        auto trx_specified_cpu_usage_limit = fc::milliseconds(trx.max_cpu_usage_ms);
        if( trx_specified_cpu_usage_limit <= objective_duration_limit ) {
          objective_duration_limit = trx_specified_cpu_usage_limit;
          billing_timer_exception_code = tx_cpu_usage_exceeded::code_value;
          _deadline = start + objective_duration_limit;
        }
      }
    
      initial_objective_duration_limit = objective_duration_limit;
    
      if( billed_cpu_time_us > 0 ) // could also call on explicit_billed_cpu_time but it would be redundant
        validate_cpu_usage_to_bill( billed_cpu_time_us, false ); // Fail early if the amount to be billed is too high
    
      // Record accounts to be billed for network and CPU usage
      if( control.is_builtin_activated(builtin_protocol_feature_t::only_bill_first_authorizer) ) {
        bill_to_accounts.insert( trx.first_authorizer() );
      } else {
        for( const auto& act : trx.actions ) {
          for( const auto& auth : act.authorization ) {
            bill_to_accounts.insert( auth.actor );
          }
        }
      }
      validate_ram_usage.reserve( bill_to_accounts.size() );
    
      // Update usage values of accounts to reflect new time
      rl.update_account_usage( bill_to_accounts, block_timestamp_type(control.pending_block_time()).slot );
    
      // Calculate the highest network usage and CPU time that all of the billed accounts can afford to be billed
      int64_t account_net_limit = 0;
      int64_t account_cpu_limit = 0;
      bool greylisted_net = false, greylisted_cpu = false;
      std::tie( account_net_limit, account_cpu_limit, greylisted_net, greylisted_cpu) = max_bandwidth_billed_accounts_can_pay();
      net_limit_due_to_greylist |= greylisted_net;
      cpu_limit_due_to_greylist |= greylisted_cpu;
    
      eager_net_limit = net_limit;
    
      // Possible lower eager_net_limit to what the billed accounts can pay plus some (objective) leeway
      auto new_eager_net_limit = std::min( eager_net_limit, static_cast<uint64_t>(account_net_limit + cfg.net_usage_leeway) );
      if( new_eager_net_limit < eager_net_limit ) {
        eager_net_limit = new_eager_net_limit;
        net_limit_due_to_block = false;
      }
    
      // Possibly limit deadline if the duration accounts can be billed for (+ a subjective leeway) does not exceed current delta
      if( (fc::microseconds(account_cpu_limit) + leeway) <= (_deadline - start) ) {
        _deadline = start + fc::microseconds(account_cpu_limit) + leeway;
        billing_timer_exception_code = leeway_deadline_exception::code_value;
      }
    
      billing_timer_duration_limit = _deadline - start;
    
      // Check if deadline is limited by caller-set deadline (only change deadline if billed_cpu_time_us is not set)
      if( explicit_billed_cpu_time || deadline < _deadline ) {
        _deadline = deadline;
        deadline_exception_code = deadline_exception::code_value;
      } else {
        deadline_exception_code = billing_timer_exception_code;
      }
    
      eager_net_limit = (eager_net_limit/8)*8; // Round down to nearest multiple of word size (8 bytes) so check_net_usage can be efficient
    
      if( initial_net_usage > 0 )
        add_net_usage( initial_net_usage );  // Fail early if current net usage is already greater than the calculated limit
    
      checktime(); // Fail early if deadline has already been exceeded
    
      if(control.skip_trx_checks())
        transaction_timer.start(fc::time_point::maximum());
      else
        transaction_timer.start(_deadline);
    
      is_initialized = true;
    }
    

    还记得 交易运行时间章节,验证交易 CPU 使用时间之前还判断了 objective_duration_limit 与 account_cpu_limit。因此可以发现,objective_duration_limit 是个上限,和 block cpu limit 又关系,和 单个交易的 cpu limit 又关系,和交易头的配置又关系,和用户可用的 cpu limit 又关系。对于用户而言,正常能改变的只有质押换来的 CPU 时间。

    用户可用 CPU 时间

    那,account_cpu_limit 怎么计算的?

    直接看代码吧:

    int64_t account_cpu_limit = large_number_no_overflow;
    auto [cpu_limit, cpu_was_greylisted] = rl.get_account_cpu_limit(a, greylist_limit);
    if( cpu_limit >= 0 ) {
       // 获取用户 cpu limit
       account_cpu_limit = std::min( account_cpu_limit, cpu_limit );
       greylisted_cpu |= cpu_was_greylisted;
    }
    
    std::pair<int64_t, bool> resource_limits_manager::get_account_cpu_limit( const account_name& name, uint32_t greylist_limit ) const {
       auto [arl, greylisted] = get_account_cpu_limit_ex(name, greylist_limit);
       return {arl.available, greylisted};
    }
    
    std::pair<account_resource_limit, bool> resource_limits_manager::get_account_cpu_limit_ex( const account_name& name, uint32_t greylist_limit ) const {
    
       const auto& state = _db.get<resource_limits_state_object>();
       const auto& usage = _db.get<resource_usage_object, by_owner>(name);
       const auto& config = _db.get<resource_limits_config_object>();
    
       int64_t cpu_weight, x, y;
       get_account_limits( name, x, y, cpu_weight );
    
       if( cpu_weight < 0 || state.total_cpu_weight == 0 ) {
          return {{ -1, -1, -1 }, false};
       }
    
       account_resource_limit arl;
    
       uint128_t window_size = config.account_cpu_usage_average_window;
       uint64_t  greylisted_virtual_cpu_limit = config.cpu_limit_parameters.max * greylist_limit;
    
       bool greylisted = false;
       uint128_t virtual_cpu_capacity_in_window = window_size;
       if( greylisted_virtual_cpu_limit < state.virtual_cpu_limit ) {
          virtual_cpu_capacity_in_window *= greylisted_virtual_cpu_limit;
          greylisted = true;
       } else {
          virtual_cpu_capacity_in_window *= state.virtual_cpu_limit;
       }
    
       uint128_t user_weight     = (uint128_t)cpu_weight;
       uint128_t all_user_weight = (uint128_t)state.total_cpu_weight;
    
       // 重点是这里
       // 窗口内可用时间 * 质押 EOS 获得的权重 / 所有质押权重
       // window_size 24小时
       // rate_limiting_precision 1000*1000 都可以从头文件中查到
       auto max_user_use_in_window = (virtual_cpu_capacity_in_window * user_weight) / all_user_weight;
       // 已经用过的 cpu
       auto cpu_used_in_window  = impl::integer_divide_ceil((uint128_t)usage.cpu_usage.value_ex * window_size, (uint128_t)config::rate_limiting_precision);
    
       if( max_user_use_in_window <= cpu_used_in_window )
          arl.available = 0;
       else
          // 可用的就是 最大 cpu 时间 减去 已经用过的 cpu 时间
          arl.available = impl::downgrade_cast<int64_t>(max_user_use_in_window - cpu_used_in_window);
    
       arl.used = impl::downgrade_cast<int64_t>(cpu_used_in_window);
       arl.max = impl::downgrade_cast<int64_t>(max_user_use_in_window);
       return {arl, greylisted};
    }
    

    所以,当前时间窗口内(24小时)用户最大 CPU 时间 = 全网总 CPU 时间 * 当前用户质押 EOS 数量 / 所有用户质押 EOS 数量

    当前时间窗口内用户可用 CPU 时间 = 当前用户最大 CPU 时间 - 当前用户已经使用 CPU 时间

    当前用户已经使用 CPU 时间是实时变化的:(1 - t / 24) * t 时间之前使用的资源大小,直到距离上次 CPU 资源使用 24 小时后(t = 24)完全恢复

    总结

    • 当前时间窗口内(24小时)用户最大 CPU 时间 = 全网总 CPU 时间 * 当前用户质押 EOS 数量 / 所有用户质押 EOS 数量

    • 当前时间窗口内用户可用 CPU 时间 = 当前用户最大 CPU 时间 - 当前用户已经使用 CPU 时间

    • 当前用户已经使用 CPU 时间是实时变化的:(1 - t / 24) * t 时间之前使用的资源大小,直到距离上次 CPU 资源使用 24 小时后(t = 24)完全恢复

    • Get Account 接口看到的不是实时可用的资源使用量,而是上一笔交易之后缓存的资源使用量

    • 向 RPC 节点提交交易时 RPC 节点会计算出当前交易 CPU 使用量,这个 CPU 使用量和当前 RPC 节点 CPU 使用情况有关,通过系统计时器计算时间,因此,RPC 节点计算出的交易 CPU 使用量不是最终上链时的交易使用量,最终交易时的 CPU 使用量由打包节点决定。

    • 因此,当质押 CPU EOS 数量固定时,向 RPC 节点提交交易时,CPU 资源需要满足 交易使用 CPU 资源的大小 < 账户可用 CPU 资源大小,因此提交交易能否成功有两方面原因:

      • RPC 节点 CPU 状态,决定了交易使用 CPU 资源的大小
      • 全网可用 CPU 资源,决定了账户可用 CPU 资源大小
    • 所以

      • 可以把交易提交到更快(CPU 空闲 / 服务器配置高)的 RPC 节点
      • 等待全网可用 CPU 资源增多,账户分配的可用 CPU 增多(错峰)
      • 增大 CPU 资源 EOS 质押比例,获得更多的 CPU 使用权重(质押更多 EOS 在 CPU 资源上)
    展开全文
  • 微秒(us)延时 程序

    千次阅读 2019-12-31 11:24:41
    static void retry_delay_100us(void) { /* 100 microsecond delay */ rt_thread_delay((RT_TICK_PER_SECOND * 1 + 9999) / 10000); } 2 wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClo...
  • OGG同步字符集从US7ASCII to ZHS16GBK故障解决 系统环境 源端:   aix 5.3  oracle 9.2.0.7 for rac  IP 192.168.124.1  ogg 11.1.1.1.2  字符集 US7ASCII 目标端:  Red hat 6.5  oracle 11.2.0.4
  • 初学使用flex 4.6,一个原有项目用flex,在eclipse报...Location Type Unable to resolve resource bundle "xxx" for locale "en_US"。 在project > properites > Flex compiler的the Aditional compiler ar
  • 加入了以下的库以后就会出现"unable to resolve resource bundle for locale en_us"错误 flex_sdk_4.0.0.14159/frameworks/libs     解决方法: 把下边的库也加入项目
  • 问题描述: 在使用cocoapods 上传自己的库时,执行命令:...'Source code for your Pod was not accessible to CocoaPods Trunk. Is it a private repo or behind a us 解决方案:将spec 文件中的 source 地址,使用
  • jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useSSL=false
  • 学术论文撰写中for和to的用法

    千次阅读 2011-04-25 17:50:00
    学术论文撰写中for和to的用法     看这篇文章时你的头脑必须绝对清醒。若是你现在的状况不错的话,就请先来判断判断下面的句子哪些是正确的,哪些是错误的吧。 <br /> Exercise is good to...
  • perl: warning: Falling back to a fallback locale ("en_US.utf8")."错误提示,如图:根据提示,估计是系统语言库缺失的问题,于是安装i18n(internationalization:国际化)语言包:如下apt install ...
  • 连接了数据库之后,网页上显示Access denied for user 'root'@'%' to database 'xxx'的字样时, 通过数据库授权: grant all on xxx.* to 'root'@'%' identified by 'password' with grant option; 其中:xxx代表...
  • 遇到这个问题去百度,发现网上的主流办法没法解决我的问题,后来发现在app的build.gradle里面,// testImplementation ...testImplementationandroidTestImplementation 注释掉即可。就解决了。 希望对大家有帮助。
  • ERR_WHEN_INSERT_TO_DB↵Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)"原因:数据库密码错了,若使用了腾讯云微信小程序解决方案,开发环境下,MySQL 的...
  • 错误信息为:check the manual that corresponds to your MySQL server version for the right syntax 这是之前写的一条 Mysql语句报的 SQL错误,但是仔细检查 SQL语句没有发现有什么异常问题。后来百度查到,我的...
  • —-首先出现这个问题肯定是studio升级到3.0Gradle升级到4.1导致的,百度一波后,大致知道是怎么造成的了,下面说出解决办法! 如果你有这类似的错误,可以尝试尝试。 把这种依赖方式 debugCompile ...
  • Unable to connect to the server: x509: certificate is valid for问题解决
  • call和called的区别和用法

    千次阅读 2020-12-22 00:23:02
    匿名用户1级2018-11-06 回答1、calledcall都是同源单词,called可以看做是call的派生词,二者意思相近,形式用法都不同,即called是call的过去式或过去分词形式。2、call的用法call既可用作动词,又可用作名词。...
  • This agent is for learning and research purposes only.Do nto user it for commercial purposes!For commercial user,please contact the Jetbrains to purchase some licenses,please support genuine! If you h...
  • Unable to load native-hadoop library for your platform解决方法

    万次阅读 多人点赞 2019-01-11 22:20:42
    在执行hadoop命令的...WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 检查发现本地并没有库 [hadoop001@192 ~]$ hado...
  • Error:Cannot determine path to ‘tools.jar‘ library for 17解决方案 运行一个Java项目出现如上所示错误。实质是当前IDEA版本不支持Java 17. 解决办法: 1.下载当前IDEA版本支持的JDK,如14。 2.卸载当前版本IDEA...
  • Clang is now used to build Chrome for Windows

    千次阅读 2020-01-13 16:46:04
    Clang is now used to build Chrome for Windows As of Chrome 64, Chrome for Windows is compiled with Clang. We now use Clang to build Chrome for all platforms it runs on: macOS, iOS, Linux, Chrome OS,.....
  • 18/09/19 11:29:08 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 原因: Apache提供的hadoop本地库是32位的,而在...
  • 本人使用的hadoop版本是: 每次执行hadoop命令:列如hadoop fs...都会出现如下警告 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where ...
  •  出现: Access denied for user ''@'localhost' to database '   原因是因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的...
  • 2,第一个错解决后,又出现了一个问题:org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version. Underlying cause: java.sql.SQLException : Access denied for user 'hadoop'@'...
  • 获取数据库连接::Can't find bundle for base name config, locale en_US [2012-09-29 10:19:33] [ERROR] SmsSubAccountServiceImpl类中的|activeStatus()方法null ResourceBundle.getBundle
  • HAL 库 uS 延时的 3 种实现方式

    千次阅读 2021-02-03 15:03:45
    CUBEMX 可视化初始化配置,结合 HAL 库,给我们开发带来了很多便利,但 HAL 库封装的延时函数目前仅支持 ms 级别的延时,日常很多情况下会用到 us 延时,特别是一些传感器... 使用 for 循环实现 us 延时 1、普通定时
  • 在settings.py中添加写一段代码 AUTH_USER_MODEL = 'users.User' 即可

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 332,393
精华内容 132,957
关键字:

tous和forus的区别

友情链接: ILOVEYOU-master.zip