未验证 提交 fcde3ee6 编写于 作者: A Anton Perkov 提交者: GitHub

Merge branch 'slim' into eosio-system-test-fix-2

......@@ -880,7 +880,7 @@ struct controller_impl {
// Update resource limits:
resource_limits.process_account_limit_updates();
const auto& chain_config = self.get_global_properties().configuration;
uint32_t max_virtual_mult = 10000;
uint32_t max_virtual_mult = 1000;
uint64_t CPU_TARGET = EOS_PERCENT(chain_config.max_block_cpu_usage, chain_config.target_block_cpu_usage_pct);
resource_limits.set_block_parameters(
{ CPU_TARGET, chain_config.max_block_cpu_usage, config::block_cpu_usage_average_window_ms / config::block_interval_ms, max_virtual_mult, {99, 100}, {1000, 999}},
......
......@@ -27,9 +27,9 @@ namespace eosio { namespace chain { namespace resource_limits {
};
struct account_resource_limit {
int64_t current_per_block = 0;
int64_t max_per_block = 0;
int64_t guaranteed_per_day = 0;
int64_t used = 0; ///< quantity used in current window
int64_t available = 0; ///< quantity available in current window (based upon fractional reserve)
int64_t max_gauranteed = 0; ///< max per window under 100% congestion
};
class resource_limits_manager {
......@@ -76,4 +76,4 @@ namespace eosio { namespace chain { namespace resource_limits {
};
} } } /// eosio::chain
FC_REFLECT( eosio::chain::resource_limits::account_resource_limit, (current_per_block)(max_per_block)(guaranteed_per_day) )
FC_REFLECT( eosio::chain::resource_limits::account_resource_limit, (used)(available)(max_gauranteed) )
......@@ -342,11 +342,11 @@ int64_t resource_limits_manager::get_account_cpu_limit( const account_name& name
uint128_t window_size = config.account_cpu_usage_average_window;
auto virtual_cpuwork_capacity_in_window = state.virtual_cpu_limit * window_size;
auto virtual_cpu_capacity_in_window = state.virtual_cpu_limit * window_size;
uint128_t user_weight = cpu_weight;
uint128_t all_user_weight = state.total_cpu_weight;
auto max_user_use_in_window = (virtual_cpuwork_capacity_in_window * user_weight) / all_user_weight;
auto max_user_use_in_window = (virtual_cpu_capacity_in_window * user_weight) / all_user_weight;
auto cpu_used_in_window = (usage.cpu_usage.value_ex * window_size) / config::rate_limiting_precision;
if( max_user_use_in_window <= cpu_used_in_window ) return 0;
......@@ -382,7 +382,7 @@ int64_t resource_limits_manager::get_account_cpu_limit( const account_name& name
}
account_resource_limit resource_limits_manager::get_account_cpu_limit_ex( const account_name& name ) const {
const auto& cfg = _db.get<resource_limits_config_object>();
const auto& config = _db.get<resource_limits_config_object>();
const auto& state = _db.get<resource_limits_state_object>();
const auto& usage = _db.get<resource_usage_object, by_owner>(name);
......@@ -390,30 +390,29 @@ account_resource_limit resource_limits_manager::get_account_cpu_limit_ex( const
int64_t cpu_weight;
get_account_limits( name, x, x, cpu_weight );
if( cpu_weight < 0 ) {
if( cpu_weight < 0 || state.total_cpu_weight == 0 ) {
return { -1, -1, -1 };
}
auto total_cpu_weight = state.total_cpu_weight;
if( total_cpu_weight == 0 ) total_cpu_weight = 1;
account_resource_limit arl;
uint128_t consumed_ex = (uint128_t)usage.cpu_usage.consumed * (uint128_t)config::rate_limiting_precision;
uint128_t virtual_capacity_ex = (uint128_t)state.virtual_cpu_limit * (uint128_t)config::rate_limiting_precision;
uint128_t window_size = config.account_cpu_usage_average_window;
uint128_t usable_capacity_ex = (uint128_t)(virtual_capacity_ex * cpu_weight) / (uint128_t)total_cpu_weight;
auto virtual_cpu_capacity_in_window = state.virtual_cpu_limit * window_size;
uint128_t user_weight = cpu_weight;
uint128_t all_user_weight = state.total_cpu_weight;
uint128_t real_capacity_ex = (uint128_t)cfg.cpu_limit_parameters.target * (uint128_t)config::rate_limiting_precision;
uint128_t guaranteed_capacity_ex = (uint128_t)(real_capacity_ex * cpu_weight) / (uint128_t)total_cpu_weight;
auto max_user_use_in_window = (virtual_cpu_capacity_in_window * user_weight) / all_user_weight;
auto cpu_used_in_window = (usage.cpu_usage.value_ex * window_size) / config::rate_limiting_precision;
uint128_t blocks_per_day = 86400 * 1000 / config::block_interval_ms;
if( max_user_use_in_window <= cpu_used_in_window )
arl.available = 0;
else
arl.available = max_user_use_in_window - cpu_used_in_window;
if( usable_capacity_ex < consumed_ex ) {
consumed_ex = usable_capacity_ex;
}
return { (int64_t)(std::min(usable_capacity_ex - consumed_ex, real_capacity_ex) / (uint128_t)config::rate_limiting_precision),
(int64_t)(std::min(usable_capacity_ex, real_capacity_ex) / (uint128_t)config::rate_limiting_precision),
(int64_t)(guaranteed_capacity_ex * blocks_per_day / cfg.cpu_limit_parameters.periods / (uint128_t)config::rate_limiting_precision)
};
arl.used = cpu_used_in_window;
return arl;
}
int64_t resource_limits_manager::get_account_net_limit( const account_name& name ) const {
......@@ -441,57 +440,39 @@ int64_t resource_limits_manager::get_account_net_limit( const account_name& name
if( max_user_use_in_window <= net_used_in_window ) return 0;
return max_user_use_in_window - net_used_in_window;
/*
uint128_t consumed_ex = (uint128_t)usage.net_usage.consumed * (uint128_t)config::rate_limiting_precision;
uint128_t virtual_capacity_ex = (uint128_t)state.virtual_net_limit * (uint128_t)config::rate_limiting_precision;
auto total_net_weight = state.total_net_weight;
if( total_net_weight == 0 ) total_net_weight = 1;
uint128_t usable_capacity_ex = (uint128_t)(virtual_capacity_ex * net_weight) / (uint128_t)total_net_weight; // max
if( usable_capacity_ex < consumed_ex ) {
return 0;
}
return (int64_t)((usable_capacity_ex - consumed_ex) / (uint128_t)config::rate_limiting_precision);
*/
}
account_resource_limit resource_limits_manager::get_account_net_limit_ex( const account_name& name ) const {
const auto& cfg = _db.get<resource_limits_config_object>();
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>();
const auto& state = _db.get<resource_limits_state_object>();
const auto& usage = _db.get<resource_usage_object, by_owner>(name);
int64_t x;
int64_t net_weight;
get_account_limits( name, x, net_weight, x );
if( net_weight < 0 ) {
if( net_weight < 0 || state.total_net_weight == 0) {
return { -1, -1, -1 };
}
auto total_net_weight = state.total_net_weight;
if( total_net_weight == 0 ) total_net_weight = 1;
account_resource_limit arl;
uint128_t consumed_ex = (uint128_t)usage.net_usage.consumed * (uint128_t)config::rate_limiting_precision;
uint128_t virtual_capacity_ex = (uint128_t)state.virtual_net_limit * (uint128_t)config::rate_limiting_precision;
uint128_t window_size = config.account_net_usage_average_window;
uint128_t usable_capacity_ex = (uint128_t)(virtual_capacity_ex * net_weight) / (uint128_t)total_net_weight; // max
auto virtual_network_capacity_in_window = state.virtual_net_limit * window_size;
uint128_t user_weight = net_weight;
uint128_t all_user_weight = state.total_net_weight;
uint128_t real_capacity_ex = (uint128_t)cfg.net_limit_parameters.target * (uint128_t)config::rate_limiting_precision;
uint128_t guaranteed_capacity_ex = (uint128_t)(real_capacity_ex * net_weight) / (uint128_t)total_net_weight;
auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;
auto net_used_in_window = (usage.net_usage.value_ex * window_size) / config::rate_limiting_precision;
uint128_t blocks_per_day = 86400 * 1000 / config::block_interval_ms;
if( max_user_use_in_window <= net_used_in_window )
arl.available = 0;
else
arl.available = max_user_use_in_window - net_used_in_window;
if( usable_capacity_ex < consumed_ex ) {
consumed_ex = usable_capacity_ex;
}
return { (int64_t)(std::min(usable_capacity_ex - consumed_ex, real_capacity_ex) / (uint128_t)config::rate_limiting_precision),
(int64_t)(std::min(usable_capacity_ex, real_capacity_ex) / (uint128_t)config::rate_limiting_precision),
(int64_t)(guaranteed_capacity_ex * blocks_per_day / cfg.net_limit_parameters.periods / (uint128_t)config::rate_limiting_precision)
};
arl.used = net_used_in_window;
return arl;
}
......
......@@ -942,6 +942,7 @@ struct delegate_bandwidth_subcommand {
string stake_net_amount;
string stake_cpu_amount;
string stake_storage_amount;
bool transfer = false;
delegate_bandwidth_subcommand(CLI::App* actionRoot) {
auto delegate_bandwidth = actionRoot->add_subcommand("delegatebw", localized("Delegate bandwidth"));
......@@ -949,6 +950,7 @@ struct delegate_bandwidth_subcommand {
delegate_bandwidth->add_option("receiver", receiver_str, localized("The account to receive the delegated bandwidth"))->required();
delegate_bandwidth->add_option("stake_net_quantity", stake_net_amount, localized("The amount of EOS to stake for network bandwidth"))->required();
delegate_bandwidth->add_option("stake_cpu_quantity", stake_cpu_amount, localized("The amount of EOS to stake for CPU bandwidth"))->required();
delegate_bandwidth->add_flag("--transfer", transfer, localized("specify to stake in name of receiver rather than in name of from"))->required();
add_standard_transaction_options(delegate_bandwidth);
delegate_bandwidth->set_callback([this] {
......@@ -956,7 +958,9 @@ struct delegate_bandwidth_subcommand {
("from", from_str)
("receiver", receiver_str)
("stake_net_quantity", to_asset(stake_net_amount))
("stake_cpu_quantity", to_asset(stake_cpu_amount));
("stake_cpu_quantity", to_asset(stake_cpu_amount))
("transfer", transfer)
;
wdump((act_payload));
send_actions({create_action({permission_level{from_str,config::active_name}}, config::system_account_name, N(delegatebw), act_payload)});
});
......@@ -1164,16 +1168,50 @@ void get_account( const string& accountName, bool json_format ) {
<< indent << "delegated:" << std::setw(17) << net_others
<< std::string(11, ' ') << "(total staked delegated to account from others)" << std::endl;
}
std::cout << indent << "current:" << std::setw(15) << ("~"+std::to_string(res.net_limit.current_per_block)) << " bytes/block"
string unit = "bytes";
double net_usage = res.net_limit.available;
if( res.net_limit.available >= 1024*1024*1024 ){
unit = "Gb";
net_usage /= 1024*1024*1024;
} else if( res.net_limit.available >= 1024*1024 ){
unit = "Mb";
net_usage /= 1024*1024;
} else if( res.net_limit.available >= 1024 ) {
unit = "Kb";
net_usage /= 1024;
}
std::cout << std::fixed << setprecision(3);
std::cout << indent << "used:" << std::setw(15) << ("~"+std::to_string(res.net_limit.used)) << " bytes (past 3 days)"
<< std::string(3, ' ') << "(assuming current congestion and current usage)" << std::endl
<< indent << "max:" << std::setw(19) << ("~"+std::to_string(res.net_limit.max_per_block)) << " bytes/block"
<< indent << "available:" << std::setw(19) << ("~"+std::to_string(net_usage)) << " "<<unit
<< std::string(3, ' ') << "(assuming current congestion and 0 usage in current window)" << std::endl
/*
<< indent << "guaranteed: " << std::setw(11) << res.net_limit.guaranteed_per_day << " bytes/day"
<< std::string(5, ' ') << "(assuming 100% congestion and 0 usage in current window)" << std::endl
*/
<< std::endl;
std::cout << "cpu bandwidth:" << std::endl;
double cpu_avail = res.cpu_limit.available/1000000.;
string cunit = "sec";
if( cpu_avail > 60*60*24 ) {
cunit = "days";
cpu_avail /= 60*60*24;
} else if( cpu_avail > 60*60 ) {
cunit = "hr";
cpu_avail /= 60*60;
} else if( cpu_avail > 60 ) {
cunit = "min";
cpu_avail /= 60;
}
if ( res.total_resources.is_object() ) {
asset cpu_own( res.delegated_bandwidth.is_object() ? stoll( res.delegated_bandwidth.get_object()["cpu_weight"].as_string() ) : 0 );
auto cpu_others = to_asset(res.total_resources.get_object()["cpu_weight"].as_string()) - cpu_own;
......@@ -1183,12 +1221,12 @@ void get_account( const string& accountName, bool json_format ) {
<< std::string(11, ' ') << "(total staked delegated to account from others)" << std::endl;
}
std::cout << indent << "current:" << std::setw(15) << ("~"+std::to_string(res.cpu_limit.current_per_block/1024)) << " kcycle/block"
<< std::string(2, ' ') << "(assuming current congestion and current usage)" << std::endl
<< indent << "max:" << std::setw(19) << ("~"+std::to_string(res.cpu_limit.max_per_block/1024)) << " kcycle/block"
<< std::string(2, ' ') << "(assuming current congestion and 0 usage in current window)" << std::endl
std::cout << indent << "used:" << std::setw(15) << ("~"+std::to_string(double(res.cpu_limit.used/1000000.))) << " sec (past 3 days)\n"
<< indent << "available:" << std::setw(19) << ("~"+std::to_string(cpu_avail) )<< " " << cunit <<"\n"
/*
<< indent << "guaranteed:" << std::setw(12) << res.cpu_limit.guaranteed_per_day/1024 << " kcycle/day"
<< std::string(4, ' ') << "(assuming 100% congestion and 0 usage in current window)" << std::endl
*/
<< std::endl;
if ( res.voter_info.is_object() ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册