Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

develop -- Add total CPU weight and total NET weight to get_info #10930

Merged
merged 2 commits into from
Dec 8, 2021
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
3 changes: 3 additions & 0 deletions libraries/chain/include/eosio/chain/resource_limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions libraries/chain/resource_limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<resource_limits_state_object>();
return state.total_cpu_weight;
}

uint64_t resource_limits_manager::get_total_net_weight() const {
const auto& state = _db.get<resource_limits_state_object>();
return state.total_net_weight;
}

uint64_t resource_limits_manager::get_virtual_block_cpu_limit() const {
const auto& state = _db.get<resource_limits_state_object>();
return state.virtual_cpu_limit;
Expand Down
4 changes: 3 additions & 1 deletion plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,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()
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class read_only {
std::optional<string> server_full_version_string;
std::optional<fc::time_point> last_irreversible_block_time;
std::optional<uint32_t> first_block_num;
std::optional<uint64_t> total_cpu_weight;
std::optional<uint64_t> total_net_weight;
};
get_info_results get_info(const get_info_params&) const;

Expand Down Expand Up @@ -1095,7 +1097,8 @@ FC_REFLECT(eosio::chain_apis::read_only::get_info_results,
(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)
(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))
Expand Down
2 changes: 2 additions & 0 deletions tests/chain_plugin_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,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);

Expand Down