Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions libraries/chain/resource_limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,45 +87,49 @@ void resource_limits_manager::add_transaction_usage(const flat_set<account_name>
for( const auto& a : accounts ) {

const auto& usage = _db.get<resource_usage_object,by_owner>( a );
const auto& limits = _db.get<resource_limits_object,by_owner>( boost::make_tuple(false, a));
int64_t unused;
int64_t net_weight;
int64_t cpu_weight;
get_account_limits( a, unused, net_weight, cpu_weight );

_db.modify( usage, [&]( auto& bu ){
bu.net_usage.add( net_usage, time_slot, config.account_net_usage_average_window );
bu.cpu_usage.add( cpu_usage, time_slot, config.account_cpu_usage_average_window );
});

if (limits.cpu_weight >= 0 && state.total_cpu_weight > 0 ) {
if( cpu_weight >= 0 && state.total_cpu_weight > 0 ) {
uint128_t window_size = config.account_cpu_usage_average_window;
auto virtual_network_capacity_in_window = state.virtual_cpu_limit * window_size;
auto cpu_used_in_window = (usage.cpu_usage.value_ex * window_size) / config::rate_limiting_precision;

uint128_t user_weight = limits.cpu_weight;
uint128_t user_weight = cpu_weight;
uint128_t all_user_weight = state.total_cpu_weight;

auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;

EOS_ASSERT( cpu_used_in_window <= max_user_use_in_window,
EOS_ASSERT( cpu_used_in_window <= max_user_use_in_window,
tx_cpu_usage_exceeded,
"authorizing account '${n}' has insufficient cpu resources for this transaction",
"authorizing account '${n}' has insufficient cpu resources for this transaction",
("n", name(a))
("cpu_used_in_window",cpu_used_in_window)
("max_user_use_in_window",max_user_use_in_window) );

}

if( limits.net_weight >= 0 && state.total_net_weight > 0) {
if( net_weight >= 0 && state.total_net_weight > 0) {

uint128_t window_size = config.account_net_usage_average_window;
auto virtual_network_capacity_in_window = state.virtual_net_limit * window_size;
auto net_used_in_window = (usage.net_usage.value_ex * window_size) / config::rate_limiting_precision;

uint128_t user_weight = limits.net_weight;
uint128_t user_weight = net_weight;
uint128_t all_user_weight = state.total_net_weight;

auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;

EOS_ASSERT( net_used_in_window <= max_user_use_in_window,
EOS_ASSERT( net_used_in_window <= max_user_use_in_window,
tx_net_usage_exceeded,
"authorizing account '${n}' has insufficient net resources for this transaction",
"authorizing account '${n}' has insufficient net resources for this transaction",
("n", name(a))
("net_used_in_window",net_used_in_window)
("max_user_use_in_window",max_user_use_in_window) );
Expand Down
4 changes: 2 additions & 2 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ add_dependencies(unit_test asserter test_api test_api_mem test_api_db test_api_m
#Manually run unit_test for all supported runtimes
#To run unit_test with all log from blockchain displayed, put --verbose after --, i.e. unit_test -- --verbose
add_test(NAME unit_test_binaryen COMMAND unit_test
-t \!eosio_system_tests/*
-t \!eosio_system_tests/elect_producers
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output -- --binaryen)
add_test(NAME unit_test_wavm COMMAND unit_test
-t \!eosio_system_tests/*
-t \!eosio_system_tests/elect_producers
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output --catch_system_errors=no -- --wavm)

Expand Down