From 9c686ca217942c8f76785385663f1aa77100ba7f Mon Sep 17 00:00:00 2001 From: Keke Li Date: Wed, 24 Feb 2021 11:43:24 -0800 Subject: [PATCH 1/3] Add first_block_num field in get_info_result and fill first block num for it when get_info is called. --- libraries/chain/block_log.cpp | 1 + libraries/chain/controller.cpp | 5 +++++ libraries/chain/include/eosio/chain/block_log.hpp | 1 + libraries/chain/include/eosio/chain/controller.hpp | 1 + plugins/chain_plugin/chain_plugin.cpp | 2 ++ .../chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp | 3 ++- 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index d647dc172d1..21c16bcaa30 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -570,6 +570,7 @@ namespace eosio { namespace chain { void block_log::set_version(uint32_t ver) { detail::block_log_impl::default_version = ver; } uint32_t block_log::version() const { return my->preamble.version; } + uint32_t block_log::get_first_block_num() const { return my->preamble.first_block_num; } detail::block_log_impl::block_log_impl(const block_log::config_type& config) : stride( config.stride ) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 41841792a11..2f03a387f20 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -2296,6 +2296,11 @@ const controller::config& controller::get_config()const return my->conf; } +const uint32_t controller::get_first_block_num()const +{ + return my->blog.get_first_block_num(); +} + controller::controller( const controller::config& cfg, const chain_id_type& chain_id ) :my( new controller_impl( cfg, *this, protocol_feature_set{}, chain_id ) ) { diff --git a/libraries/chain/include/eosio/chain/block_log.hpp b/libraries/chain/include/eosio/chain/block_log.hpp index 7858df0fe50..aead6e8e465 100644 --- a/libraries/chain/include/eosio/chain/block_log.hpp +++ b/libraries/chain/include/eosio/chain/block_log.hpp @@ -97,6 +97,7 @@ namespace eosio { namespace chain { // used for unit test to generate older version blocklog static void set_version(uint32_t); uint32_t version() const; + uint32_t get_first_block_num() const; /** * @param n Only test 1 block out of every n blocks. If n is 0, it is maximum between 1 and the ceiling of the total number blocks divided by 8. diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index d65182ee64d..173fd3aa828 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -206,6 +206,7 @@ namespace eosio { namespace chain { const protocol_feature_manager& get_protocol_feature_manager()const; uint32_t get_max_nonprivileged_inline_action_size()const; const config& get_config()const; + const uint32_t get_first_block_num() const; const flat_set& get_actor_whitelist() const; const flat_set& get_actor_blacklist() const; diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 20c6a2827af..fca1f6db711 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1485,11 +1485,13 @@ std::string itoh(I n, size_t hlen = sizeof(I)<<1) { } read_only::get_info_results read_only::get_info(const read_only::get_info_params&) const { + const auto& rm = db.get_resource_limits_manager(); return { itoh(static_cast(app().version())), db.get_chain_id(), db.head_block_num(), + db.get_first_block_num(), db.last_irreversible_block_num(), db.last_irreversible_block_id(), db.head_block_id(), 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 e1817fb7464..a510a607760 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,7 @@ class read_only { string server_version; chain::chain_id_type chain_id; uint32_t head_block_num = 0; + uint32_t first_block_num = 0; uint32_t last_irreversible_block_num = 0; chain::block_id_type last_irreversible_block_id; chain::block_id_type head_block_id; @@ -1104,7 +1105,7 @@ FC_REFLECT( eosio::chain_apis::linked_action, (account)(action) ) FC_REFLECT( eosio::chain_apis::permission, (perm_name)(parent)(required_auth)(linked_actions) ) 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) + (server_version)(chain_id)(head_block_num)(first_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) From 62be3801fc0a9f42d6c68bb081befcfab5eb2851 Mon Sep 17 00:00:00 2001 From: Keke Li Date: Thu, 25 Feb 2021 18:29:05 -0800 Subject: [PATCH 2/3] using uint32_t instead of const uint32_t first_block_num --- libraries/chain/controller.cpp | 2 +- libraries/chain/include/eosio/chain/controller.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 2f03a387f20..10c279b9ee5 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -2296,7 +2296,7 @@ const controller::config& controller::get_config()const return my->conf; } -const uint32_t controller::get_first_block_num()const +uint32_t controller::get_first_block_num()const { return my->blog.get_first_block_num(); } diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 173fd3aa828..d0665f9c716 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -206,7 +206,7 @@ namespace eosio { namespace chain { const protocol_feature_manager& get_protocol_feature_manager()const; uint32_t get_max_nonprivileged_inline_action_size()const; const config& get_config()const; - const uint32_t get_first_block_num() const; + uint32_t get_first_block_num() const; const flat_set& get_actor_whitelist() const; const flat_set& get_actor_blacklist() const; From e4d0e139963920723664e57e88e32d1a8f34cc8e Mon Sep 17 00:00:00 2001 From: Keke Li Date: Fri, 26 Feb 2021 16:31:53 -0800 Subject: [PATCH 3/3] Using std::optional for the first_block_num so as to keep compatible with old nodeos --- plugins/chain_plugin/chain_plugin.cpp | 4 ++-- .../include/eosio/chain_plugin/chain_plugin.hpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index fca1f6db711..1a9a8c5ec77 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1491,7 +1491,6 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params itoh(static_cast(app().version())), db.get_chain_id(), db.head_block_num(), - db.get_first_block_num(), db.last_irreversible_block_num(), db.last_irreversible_block_id(), db.head_block_id(), @@ -1509,7 +1508,8 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params app().full_version_string(), db.last_irreversible_block_time(), rm.get_total_cpu_weight(), - rm.get_total_net_weight() + rm.get_total_net_weight(), + db.get_first_block_num() }; } 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 a510a607760..50b6ca3cb4e 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -123,7 +123,6 @@ class read_only { string server_version; chain::chain_id_type chain_id; uint32_t head_block_num = 0; - uint32_t first_block_num = 0; uint32_t last_irreversible_block_num = 0; chain::block_id_type last_irreversible_block_id; chain::block_id_type head_block_id; @@ -144,6 +143,7 @@ class read_only { std::optional last_irreversible_block_time; std::optional total_cpu_weight; std::optional total_net_weight; + std::optional first_block_num; }; get_info_results get_info(const get_info_params&) const; @@ -1105,11 +1105,11 @@ FC_REFLECT( eosio::chain_apis::linked_action, (account)(action) ) FC_REFLECT( eosio::chain_apis::permission, (perm_name)(parent)(required_auth)(linked_actions) ) FC_REFLECT(eosio::chain_apis::empty, ) FC_REFLECT(eosio::chain_apis::read_only::get_info_results, - (server_version)(chain_id)(head_block_num)(first_block_num)(last_irreversible_block_num)(last_irreversible_block_id) + (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) - (last_irreversible_block_time)(total_cpu_weight)(total_net_weight) ) + (last_irreversible_block_time)(total_cpu_weight)(total_net_weight)(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) ) 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))