最近项目上线,数据一致性等问题已处理完,准备做使用资源上的一些优化,
考虑到普通账户CPU和net的资源有限,需要考虑下由合约方出这部分资源,减少用户反复抵押相应资源,以及了解资源相关的学习成本。
按照思路,应该是执行合约相关的动作,用户和合约账户一同多签,并指定资源消耗方为合约账户。

记得之前已经看过相关的EOSIO技术规划,有提到相关,那根下代码把
https://github.com/EOSIO/eos/blob/1418543149b7caf8fc69a23621e3db7f3c6d18ad/libraries/chain/transaction_context.cpp#L230

// 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 );
            }
         }
      }

此时“侧链”代码为 V1.6.6, 预计等1.8.x稳定后,会升级到新共识协议,所以为了最小的差异,先做最小的修改支持吧。

为了简单的先实现,所以改下代码(本想放到config.ini,但是代码嵌套层较深,并且这种协议上的不会在做更新,直接放到代码里吧)
libraries\chain\include\eosio\chain\config.hpp
中增加一字段

const static bool       support_only_bill_first_authorizer           = true; // support only bill first authorizer

修改源代码为

// Record accounts to be billed for network and CPU usage
      if( config::support_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 );
            }
         }
      }

方案的实现建立在,客户端签名后,将数据发给后端,重新签名,并将项目方的验证授权放到第一个,这样执行的资源消耗就都算在项目方的账号上了。

更新各个节点,先支持,等待1.8.x稳定,在做共识性质的更新。

参考

https://github.com/EOSIO/spec-repo/blob/master/esr_contract_trx_auth.md
https://github.com/EOSIO/eos/issues/6332
https://github.com/EOSIO/eos/pull/7089
https://bihu.com/article/1522267629