From 3aa54bae17cbde2214046b0fd63dd814a15b295c Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 2 Dec 2021 13:18:51 -0500 Subject: [PATCH 1/2] Add total CPU weight and total NET weight to get_info --- .../chain/include/eosio/chain/resource_limits.hpp | 3 +++ libraries/chain/resource_limits.cpp | 10 ++++++++++ plugins/chain_plugin/chain_plugin.cpp | 2 ++ .../include/eosio/chain_plugin/chain_plugin.hpp | 5 ++++- tests/chain_plugin_tests.cpp | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libraries/chain/include/eosio/chain/resource_limits.hpp b/libraries/chain/include/eosio/chain/resource_limits.hpp index f7b7a52ded2..89a27a1e230 100644 --- a/libraries/chain/include/eosio/chain/resource_limits.hpp +++ b/libraries/chain/include/eosio/chain/resource_limits.hpp @@ -90,6 +90,9 @@ namespace eosio { namespace chain { namespace resource_limits { void process_block_usage( uint32_t block_num ); // accessors + uint64_t get_total_cpu_weight() const; + uint64_t get_total_net_weight() const; + uint64_t get_virtual_block_cpu_limit() const; uint64_t get_virtual_block_net_limit() const; diff --git a/libraries/chain/resource_limits.cpp b/libraries/chain/resource_limits.cpp index 977a0778f5e..a5e75c1966b 100644 --- a/libraries/chain/resource_limits.cpp +++ b/libraries/chain/resource_limits.cpp @@ -448,6 +448,16 @@ void resource_limits_manager::process_block_usage(uint32_t block_num) { } +uint64_t resource_limits_manager::get_total_cpu_weight() const { + const auto& state = _db.get(); + return state.total_cpu_weight; +} + +uint64_t resource_limits_manager::get_total_net_weight() const { + const auto& state = _db.get(); + return state.total_net_weight; +} + uint64_t resource_limits_manager::get_virtual_block_cpu_limit() const { const auto& state = _db.get(); return state.virtual_cpu_limit; diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index d1bd921b325..5040f1cfbfd 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1494,6 +1494,8 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params db.head_block_id(), db.head_block_time(), db.head_block_producer(), + rm.get_total_cpu_weight(), + rm.get_total_net_weight(), rm.get_virtual_block_cpu_limit(), rm.get_virtual_block_net_limit(), rm.get_block_cpu_limit(), diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index eeb0f0f746b..06ffc06c6e0 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -123,6 +123,9 @@ class read_only { fc::time_point head_block_time; account_name head_block_producer; + uint64_t total_cpu_weight = 0; + uint64_t total_net_weight = 0; + uint64_t virtual_block_cpu_limit = 0; uint64_t virtual_block_net_limit = 0; @@ -1093,7 +1096,7 @@ FC_REFLECT(eosio::chain_apis::empty, ) FC_REFLECT(eosio::chain_apis::read_only::get_info_results, (server_version)(chain_id)(head_block_num)(last_irreversible_block_num)(last_irreversible_block_id) (head_block_id)(head_block_time)(head_block_producer) - (virtual_block_cpu_limit)(virtual_block_net_limit)(block_cpu_limit)(block_net_limit) + (total_cpu_weight)(total_net_weight)(virtual_block_cpu_limit)(virtual_block_net_limit)(block_cpu_limit)(block_net_limit) (server_version_string)(fork_db_head_block_num)(fork_db_head_block_id)(server_full_version_string) (last_irreversible_block_time) (first_block_num) ) FC_REFLECT(eosio::chain_apis::read_only::get_activated_protocol_features_params, (lower_bound)(upper_bound)(limit)(search_by_block_num)(reverse) ) diff --git a/tests/chain_plugin_tests.cpp b/tests/chain_plugin_tests.cpp index 094bd46c068..29081594bdf 100644 --- a/tests/chain_plugin_tests.cpp +++ b/tests/chain_plugin_tests.cpp @@ -148,6 +148,8 @@ BOOST_FIXTURE_TEST_CASE( get_info, TESTER ) try { BOOST_TEST(info.head_block_id == control->head_block_id()); BOOST_TEST(info.head_block_time == control->head_block_time()); BOOST_TEST(info.head_block_producer == control->head_block_producer()); + BOOST_TEST(info.total_cpu_weight == control->get_resource_limits_manager().get_total_cpu_weight()); + BOOST_TEST(info.total_net_weight == control->get_resource_limits_manager().get_total_net_weight()); BOOST_TEST(info.virtual_block_cpu_limit == control->get_resource_limits_manager().get_virtual_block_cpu_limit()); BOOST_TEST(info.virtual_block_net_limit == control->get_resource_limits_manager().get_virtual_block_net_limit()); BOOST_TEST(info.block_cpu_limit == control->get_resource_limits_manager().get_block_cpu_limit()); From 032c11b2776ab203f607e492ceac4543f647e733 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Fri, 3 Dec 2021 09:12:23 -0500 Subject: [PATCH 2/2] Make total_cpu_weight and total_net_weight optional so that different versions of cleos and nodoes can work --- plugins/chain_plugin/chain_plugin.cpp | 6 +++--- .../include/eosio/chain_plugin/chain_plugin.hpp | 10 +++++----- tests/chain_plugin_tests.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 5040f1cfbfd..2be08d6ae32 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1494,8 +1494,6 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params db.head_block_id(), db.head_block_time(), db.head_block_producer(), - rm.get_total_cpu_weight(), - rm.get_total_net_weight(), rm.get_virtual_block_cpu_limit(), rm.get_virtual_block_net_limit(), rm.get_block_cpu_limit(), @@ -1507,7 +1505,9 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params db.fork_db_pending_head_block_id(), app().full_version_string(), db.last_irreversible_block_time(), - db.get_first_block_num() + db.get_first_block_num(), + rm.get_total_cpu_weight(), + rm.get_total_net_weight() }; } diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index 06ffc06c6e0..5499c4c87e8 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -123,9 +123,6 @@ class read_only { fc::time_point head_block_time; account_name head_block_producer; - uint64_t total_cpu_weight = 0; - uint64_t total_net_weight = 0; - uint64_t virtual_block_cpu_limit = 0; uint64_t virtual_block_net_limit = 0; @@ -139,6 +136,8 @@ class read_only { std::optional server_full_version_string; std::optional last_irreversible_block_time; std::optional first_block_num; + std::optional total_cpu_weight; + std::optional total_net_weight; }; get_info_results get_info(const get_info_params&) const; @@ -1096,9 +1095,10 @@ FC_REFLECT(eosio::chain_apis::empty, ) FC_REFLECT(eosio::chain_apis::read_only::get_info_results, (server_version)(chain_id)(head_block_num)(last_irreversible_block_num)(last_irreversible_block_id) (head_block_id)(head_block_time)(head_block_producer) - (total_cpu_weight)(total_net_weight)(virtual_block_cpu_limit)(virtual_block_net_limit)(block_cpu_limit)(block_net_limit) + (virtual_block_cpu_limit)(virtual_block_net_limit)(block_cpu_limit)(block_net_limit) (server_version_string)(fork_db_head_block_num)(fork_db_head_block_id)(server_full_version_string) - (last_irreversible_block_time) (first_block_num) ) + (last_irreversible_block_time) (first_block_num) + (total_cpu_weight)(total_net_weight) ) FC_REFLECT(eosio::chain_apis::read_only::get_activated_protocol_features_params, (lower_bound)(upper_bound)(limit)(search_by_block_num)(reverse) ) FC_REFLECT(eosio::chain_apis::read_only::get_activated_protocol_features_results, (activated_protocol_features)(more) ) FC_REFLECT(eosio::chain_apis::read_only::get_block_params, (block_num_or_id)) diff --git a/tests/chain_plugin_tests.cpp b/tests/chain_plugin_tests.cpp index 29081594bdf..13de3c86b0d 100644 --- a/tests/chain_plugin_tests.cpp +++ b/tests/chain_plugin_tests.cpp @@ -148,8 +148,6 @@ BOOST_FIXTURE_TEST_CASE( get_info, TESTER ) try { BOOST_TEST(info.head_block_id == control->head_block_id()); BOOST_TEST(info.head_block_time == control->head_block_time()); BOOST_TEST(info.head_block_producer == control->head_block_producer()); - BOOST_TEST(info.total_cpu_weight == control->get_resource_limits_manager().get_total_cpu_weight()); - BOOST_TEST(info.total_net_weight == control->get_resource_limits_manager().get_total_net_weight()); BOOST_TEST(info.virtual_block_cpu_limit == control->get_resource_limits_manager().get_virtual_block_cpu_limit()); BOOST_TEST(info.virtual_block_net_limit == control->get_resource_limits_manager().get_virtual_block_net_limit()); BOOST_TEST(info.block_cpu_limit == control->get_resource_limits_manager().get_block_cpu_limit()); @@ -159,6 +157,8 @@ BOOST_FIXTURE_TEST_CASE( get_info, TESTER ) try { BOOST_TEST(*info.fork_db_head_block_id == control->fork_db_pending_head_block_id()); BOOST_TEST(*info.server_full_version_string == app().full_version_string()); BOOST_TEST(*info.last_irreversible_block_time == control->last_irreversible_block_time()); + BOOST_TEST(*info.total_cpu_weight == control->get_resource_limits_manager().get_total_cpu_weight()); + BOOST_TEST(*info.total_net_weight == control->get_resource_limits_manager().get_total_net_weight()); produce_blocks(1);