From 6d397482fb0f551e6c66096e603f4a01f24a01cd 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 | 6 ++++++ libraries/chain/include/eosio/chain/block_log.hpp | 1 + libraries/chain/include/eosio/chain/controller.hpp | 1 + plugins/chain_plugin/chain_plugin.cpp | 2 ++ .../include/eosio/chain_plugin/chain_plugin.hpp | 3 ++- 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index 13d4419a3bd..0ac02393056 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -574,6 +574,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 00b03f7da0c..76458b8ed4f 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -2340,6 +2340,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 ) ) { @@ -2801,6 +2806,7 @@ block_state_ptr controller::fetch_block_state_by_id( block_id_type id )const { block_state_ptr controller::fetch_block_state_by_number( uint32_t block_num )const { try { const auto& rev_blocks = my->reversible_blocks.get_index(); + auto objitr = rev_blocks.find(block_num); if( objitr == rev_blocks.end() ) { diff --git a/libraries/chain/include/eosio/chain/block_log.hpp b/libraries/chain/include/eosio/chain/block_log.hpp index 0306a48a848..73898725586 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 2bda6e6bf22..8a81a9f759e 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -205,6 +205,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 e4e527fff6e..1a91473e28e 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1705,11 +1705,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 44e35d36694..22baade8729 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -120,6 +120,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; @@ -1080,7 +1081,7 @@ class chain_plugin : public plugin { FC_REFLECT( eosio::chain_apis::permission, (perm_name)(parent)(required_auth) ) 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 a40cff536e4e4741a3b74fd4a77e40a87d3921de 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 76458b8ed4f..9b0cf1cf0c5 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -2340,7 +2340,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 8a81a9f759e..b86538300a1 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -205,7 +205,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 d63f5aaad5cd2f2f08154b29fd9d0d93b158e6b3 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 1a91473e28e..4fc9425e988 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -1711,7 +1711,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(), @@ -1727,7 +1726,8 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params db.fork_db_pending_head_block_num(), db.fork_db_pending_head_block_id(), app().full_version_string(), - db.last_irreversible_block_time() + db.last_irreversible_block_time(), + 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 22baade8729..e14c7e4a72a 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -120,7 +120,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; @@ -139,6 +138,7 @@ class read_only { std::optional fork_db_head_block_id; std::optional server_full_version_string; std::optional last_irreversible_block_time; + std::optional first_block_num; }; get_info_results get_info(const get_info_params&) const; @@ -1081,11 +1081,11 @@ class chain_plugin : public plugin { FC_REFLECT( eosio::chain_apis::permission, (perm_name)(parent)(required_auth) ) 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) ) + (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) ) 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))