From 32364d04eecf45b3501692a1c44f39241f4df739 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Mon, 6 Dec 2021 14:59:46 -0500 Subject: [PATCH] Add total CPU and NET to get_info --- .../chain/include/eosio/chain/resource_limits.hpp | 3 +++ libraries/chain/resource_limits.cpp | 10 ++++++++++ plugins/chain_plugin/chain_plugin.cpp | 4 +++- .../include/eosio/chain_plugin/chain_plugin.hpp | 4 +++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libraries/chain/include/eosio/chain/resource_limits.hpp b/libraries/chain/include/eosio/chain/resource_limits.hpp index 9ea8521147a..180030f46d0 100644 --- a/libraries/chain/include/eosio/chain/resource_limits.hpp +++ b/libraries/chain/include/eosio/chain/resource_limits.hpp @@ -84,6 +84,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 d834ac42420..3bbb12c4a4f 100644 --- a/libraries/chain/resource_limits.cpp +++ b/libraries/chain/resource_limits.cpp @@ -350,6 +350,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 a5cd15e9cee..5f9c0f6fe65 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1537,7 +1537,9 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params app().version_string(), db.fork_db_pending_head_block_num(), db.fork_db_pending_head_block_id(), - app().full_version_string() + app().full_version_string(), + 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 db80a8262b9..4400c423b34 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -121,6 +121,8 @@ class read_only { optional fork_db_head_block_num; optional fork_db_head_block_id; optional server_full_version_string; + optional total_cpu_weight; + optional total_net_weight; }; get_info_results get_info(const get_info_params&) const; @@ -773,7 +775,7 @@ 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) - (server_version_string)(fork_db_head_block_num)(fork_db_head_block_id)(server_full_version_string) ) + (server_version_string)(fork_db_head_block_num)(fork_db_head_block_id)(server_full_version_string)(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))