http://www.7klian.com

EOS新资源模子的先容

其源代码地点在EOS代码客栈的1.8.x-rentbw分支,链接为: rentbw.cpp

新资源模子,是更过更新系统合约,,集成在eosio系统里的系统级资源租赁市场。

合约表布局

rent.state 数据库用于存储租赁市场的状态,雷同市场的状态看板,租赁价值的计较,租借环境的计较,皆从这里来:

struct [[eosio::table("rent.state"),eosio::contract("eosio.system")]] rentbw_state { static constexpr uint32_t default_rent_days = 30; // 30 day resource rentals uint8_t version = 0; rentbw_state_resource net = {}; // NET market state rentbw_state_resource cpu = {}; // CPU market state uint32_t rent_days = default_rent_days; // `rentbw` `days` argument must match this. asset min_rent_fee = {}; // Rental fees below this amount are rejected uint64_t primary_key()const { return 0; } }; typedef eosio::singleton<"rent.state"_n, rentbw_state> rentbw_state_singleton;

个中的rentbw_state_resource是一个子级的数据布局,存储了cpu和net各自的市场状态和参数设置:

struct rentbw_state_resource { static constexpr double default_exponent = 2.0; // Exponent of 2.0 means that the price to rent a // tiny amount of resources increases linearly // with utilization. static constexpr uint32_t default_decay_secs = 1 * seconds_per_day; // 1 day; if 100% of bandwidth resources are in a // single loan, then, assuming no further renting, // 1 day after it expires the adjusted utilization // will be at approximately 37% and after 3 days // the adjusted utilization will be less than 5%. uint8_t version = 0; int64_t weight = 0; // resource market weight. calculated; varies over time. // 1 represents the same amount of resources as 1 // satoshi of SYS staked. int64_t weight_ratio = 0; // resource market weight ratio: // assumed_stake_weight / (assumed_stake_weight + weight). // calculated; varies over time. 1x = 10^15. 0.01x = 10^13. int64_t assumed_stake_weight = 0; // Assumed stake weight for ratio calculations. int64_t initial_weight_ratio = rentbw_frac; // Initial weight_ratio used for linear shrinkage. int64_t target_weight_ratio = rentbw_frac / 100; // Linearly shrink the weight_ratio to this amount. time_point_sec initial_timestamp = {}; // When weight_ratio shrinkage started time_point_sec target_timestamp = {}; // Stop automatic weight_ratio shrinkage at this time. Once this // time hits, weight_ratio will be target_weight_ratio. double exponent = default_exponent; // Exponent of resource price curve. uint32_t decay_secs = default_decay_secs; // Number of seconds for the gap between adjusted resource // utilization and instantaneous utilization to shrink by 63%. asset min_price = {}; // Fee needed to rent the entire resource market weight at // the minimum price (defaults to 0). asset max_price = {}; // Fee needed to rent the entire resource market weight at // the maximum price. int64_t utilization = 0; // Instantaneous resource utilization. This is the current // amount sold. utilization <= weight. int64_t adjusted_utilization = 0; // Adjusted resource utilization. This is >= utilization and // <= weight. It grows instantly but decays exponentially. time_point_sec utilization_timestamp = {}; // When adjusted_utilization was last updated // for modeling - not to merged in code int64_t fee = 0; };

系统设置, 存储了资源模子租赁算法的一些相关参数:

struct rentbw_config_resource { std::optional<int64_t> current_weight_ratio; // Immediately set weight_ratio to this amount. 1x = 10^15. 0.01x = 10^13. // Do not specify to preserve the existing setting or use the default; // this avoids sudden price jumps. For new chains which don't need // to gradually phase out staking and REX, 0.01x (10^13) is a good // value for both current_weight_ratio and target_weight_ratio. std::optional<int64_t> target_weight_ratio; // Linearly shrink weight_ratio to this amount. 1x = 10^15. 0.01x = 10^13. // Do not specify to preserve the existing setting or use the default. std::optional<int64_t> assumed_stake_weight; // Assumed stake weight for ratio calculations. Use the sum of total // staked and total rented by REX at the time the rentbw market // is first activated. Do not specify to preserve the existing // setting (no default exists); this avoids sudden price jumps. // For new chains which don't need to phase out staking and REX, // 10^12 is probably a good value. std::optional<time_point_sec> target_timestamp; // Stop automatic weight_ratio shrinkage at this time. Once this // time hits, weight_ratio will be target_weight_ratio. Ignored // if current_weight_ratio == target_weight_ratio. Do not specify // this to preserve the existing setting (no default exists). std::optional<double> exponent; // Exponent of resource price curve. Must be >= 1. Do not specify // to preserve the existing setting or use the default. std::optional<uint32_t> decay_secs; // Number of seconds for the gap between adjusted resource // utilization and instantaneous resource utilization to shrink // by 63%. Do not specify to preserve the existing setting or // use the default. std::optional<asset> min_price; // Fee needed to rent the entire resource market weight at the // minimum price. For example, this could be set to 0.005% of // total token supply. Do not specify to preserve the existing // setting or use the default. std::optional<asset> max_price; // Fee needed to rent the entire resource market weight at the // maximum price. For example, this could be set to 10% of total // token supply. Do not specify to preserve the existing // setting (no default exists). EOSLIB_SERIALIZE( rentbw_config_resource, (current_weight_ratio)(target_weight_ratio)(assumed_stake_weight) (target_timestamp)(exponent)(decay_secs)(min_price)(max_price) ) }; struct rentbw_config { rentbw_config_resource net; // NET market configuration rentbw_config_resource cpu; // CPU market configuration std::optional<uint32_t> rent_days; // `rentbw` `days` argument must match this. Do not specify to preserve the // existing setting or use the default. std::optional<asset> min_rent_fee; // Rental fees below this amount are rejected. Do not specify to preserve the // existing setting (no default exists). EOSLIB_SERIALIZE( rentbw_config, (net)(cpu)(rent_days)(min_rent_fee) ) };

rentbw.order租赁订单数据库,用于存储小我私家的租赁信息,好比租赁几多资源、租了多久,皆从这个表举办查询:

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

相关文章阅读