From 11322f7eb2e29538162d2d7d4912d7687ae8eb68 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Fri, 19 Nov 2021 17:31:53 -0500 Subject: [PATCH 1/3] Add chain API endpoint and cleos command to retrieve consensus parameters --- plugins/chain_api_plugin/chain_api_plugin.cpp | 2 ++ plugins/chain_plugin/chain_plugin.cpp | 11 +++++++ .../eosio/chain_plugin/chain_plugin.hpp | 32 ++++++++++++++++++- programs/cleos/httpc.hpp | 1 + programs/cleos/main.cpp | 9 ++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/plugins/chain_api_plugin/chain_api_plugin.cpp b/plugins/chain_api_plugin/chain_api_plugin.cpp index 21571cd681..8c09b64f32 100644 --- a/plugins/chain_api_plugin/chain_api_plugin.cpp +++ b/plugins/chain_api_plugin/chain_api_plugin.cpp @@ -132,6 +132,8 @@ void chain_api_plugin::plugin_startup() { CHAIN_RW_CALL_ASYNC(push_transactions, chain_apis::read_write::push_transactions_results, 202, http_params_types::params_required), CHAIN_RW_CALL_ASYNC(send_transaction, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required), CHAIN_RW_CALL_ASYNC(send_transaction2, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required) + CHAIN_RO_CALL(get_all_accounts, 200, http_params_types::params_required), + CHAIN_RO_CALL(get_consensus_parameters, 200, http_params_types::no_params_required) }); if (chain.account_queries_enabled()) { diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 0faf6447c6..dd1f123d63 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2742,6 +2742,17 @@ chain::symbol read_only::extract_core_symbol()const { return core_symbol; } +read_only::get_consensus_parameters_results +read_only::get_consensus_parameters(const get_consensus_parameters_params& ) const { + get_consensus_parameters_results results; + + results.chain_config = db.get_global_properties().configuration; + results.kv_database_config = db.get_global_properties().kv_configuration; + results.wasm_config = db.get_global_properties().wasm_configuration; + + return results; +} + } // namespace chain_apis fc::variant chain_plugin::get_log_trx_trace(const transaction_trace_ptr& trx_trace ) const { 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 ba5719ccc5..23c71ecd6c 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -671,6 +671,33 @@ class read_only { chain::symbol extract_core_symbol()const; + struct get_all_accounts_result { + struct account_result { + chain::name name; + chain::block_timestamp_type creation_date; + }; + + std::vector accounts; + + std::optional more; + }; + + struct get_all_accounts_params { + uint32_t limit = 10; + std::optional lower_bound; + std::optional upper_bound; + bool reverse = false; + }; + + get_all_accounts_result get_all_accounts( const get_all_accounts_params& params) const; + + using get_consensus_parameters_params = empty; + struct get_consensus_parameters_results { + chain::chain_config chain_config; + chain::kv_database_config kv_database_config; + chain::wasm_config wasm_config; + }; + get_consensus_parameters_results get_consensus_parameters(const get_consensus_parameters_params&) const; }; class read_write { @@ -905,4 +932,7 @@ FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_params, (transaction FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_result, (required_keys) ) FC_REFLECT( eosio::chain_apis::read_only::compute_transaction_params, (transaction)) FC_REFLECT( eosio::chain_apis::read_only::compute_transaction_results, (transaction_id)(processed) ) - +FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_params, (limit)(lower_bound)(upper_bound)(reverse) ) +FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_result::account_result, (name)(creation_date)) +FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_result, (accounts)(more)) +FC_REFLECT( eosio::chain_apis::read_only::get_consensus_parameters_results, (chain_config)(kv_database_config)(wasm_config)) diff --git a/programs/cleos/httpc.hpp b/programs/cleos/httpc.hpp index 1acf8a67f9..522bf271d7 100644 --- a/programs/cleos/httpc.hpp +++ b/programs/cleos/httpc.hpp @@ -81,6 +81,7 @@ namespace eosio { namespace client { namespace http { const string chain_func_base = "/v1/chain"; const string get_info_func = chain_func_base + "/get_info"; const string get_transaction_status_func = chain_func_base + "/get_transaction_status"; + const string get_consensus_parameters_func = chain_func_base + "/get_consensus_parameters"; const string send_txn_func = chain_func_base + "/send_transaction"; const string push_txn_func = chain_func_base + "/push_transaction"; const string send2_txn_func = chain_func_base + "/send_transaction2"; diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 44cac9f4d1..6fd977b4e5 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -346,6 +346,10 @@ template<> fc::variant call( const std::string& url, const std::string& path) { return call( url, path, fc::variant() ); } +eosio::chain_apis::read_only::get_consensus_parameters_results get_consensus_parameters() { + return call(default_url, get_consensus_parameters_func).as(); +} + eosio::chain_apis::read_only::get_info_results get_info() { return call(url, get_info_func).as(); } @@ -2796,6 +2800,11 @@ int main( int argc, char** argv ) { std::cout << fc::json::to_pretty_string(call(get_transaction_status_func, arg)) << std::endl; }); + // get consensus parameters + get->add_subcommand("consensus_parameters", localized("Get current blockchain consensus parameters"))->callback([] { + std::cout << fc::json::to_pretty_string(get_consensus_parameters()) << std::endl; + }); + // get block string blockArg; bool get_bhs = false; From 3217b0109efb7bbe54bf86eb3c51746f7d43a418 Mon Sep 17 00:00:00 2001 From: Clayton Calabrese Date: Mon, 18 Jul 2022 17:02:22 -0500 Subject: [PATCH 2/3] remote get_all_accounts, fix build failures. --- plugins/chain_api_plugin/chain_api_plugin.cpp | 5 ++-- plugins/chain_plugin/chain_plugin.cpp | 2 +- .../eosio/chain_plugin/chain_plugin.hpp | 24 +------------------ plugins/net_api_plugin/net_api_plugin.cpp | 2 +- programs/cleos/main.cpp | 2 +- 5 files changed, 6 insertions(+), 29 deletions(-) diff --git a/plugins/chain_api_plugin/chain_api_plugin.cpp b/plugins/chain_api_plugin/chain_api_plugin.cpp index 8c09b64f32..93bf9b91ab 100644 --- a/plugins/chain_api_plugin/chain_api_plugin.cpp +++ b/plugins/chain_api_plugin/chain_api_plugin.cpp @@ -131,9 +131,8 @@ void chain_api_plugin::plugin_startup() { CHAIN_RW_CALL_ASYNC(push_transaction, chain_apis::read_write::push_transaction_results, 202, http_params_types::params_required), CHAIN_RW_CALL_ASYNC(push_transactions, chain_apis::read_write::push_transactions_results, 202, http_params_types::params_required), CHAIN_RW_CALL_ASYNC(send_transaction, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required), - CHAIN_RW_CALL_ASYNC(send_transaction2, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required) - CHAIN_RO_CALL(get_all_accounts, 200, http_params_types::params_required), - CHAIN_RO_CALL(get_consensus_parameters, 200, http_params_types::no_params_required) + CHAIN_RW_CALL_ASYNC(send_transaction2, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required), + CHAIN_RO_CALL(get_consensus_parameters, 200, http_params_types::no_params) }); if (chain.account_queries_enabled()) { diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index dd1f123d63..adb1ce4a15 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -15,7 +15,7 @@ #include #include #include - +#include #include #include 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 23c71ecd6c..4b6169ae44 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -671,26 +672,6 @@ class read_only { chain::symbol extract_core_symbol()const; - struct get_all_accounts_result { - struct account_result { - chain::name name; - chain::block_timestamp_type creation_date; - }; - - std::vector accounts; - - std::optional more; - }; - - struct get_all_accounts_params { - uint32_t limit = 10; - std::optional lower_bound; - std::optional upper_bound; - bool reverse = false; - }; - - get_all_accounts_result get_all_accounts( const get_all_accounts_params& params) const; - using get_consensus_parameters_params = empty; struct get_consensus_parameters_results { chain::chain_config chain_config; @@ -932,7 +913,4 @@ FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_params, (transaction FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_result, (required_keys) ) FC_REFLECT( eosio::chain_apis::read_only::compute_transaction_params, (transaction)) FC_REFLECT( eosio::chain_apis::read_only::compute_transaction_results, (transaction_id)(processed) ) -FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_params, (limit)(lower_bound)(upper_bound)(reverse) ) -FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_result::account_result, (name)(creation_date)) -FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_result, (accounts)(more)) FC_REFLECT( eosio::chain_apis::read_only::get_consensus_parameters_results, (chain_config)(kv_database_config)(wasm_config)) diff --git a/plugins/net_api_plugin/net_api_plugin.cpp b/plugins/net_api_plugin/net_api_plugin.cpp index 36aa5e017d..6274f1189e 100644 --- a/plugins/net_api_plugin/net_api_plugin.cpp +++ b/plugins/net_api_plugin/net_api_plugin.cpp @@ -44,7 +44,7 @@ using namespace eosio; eosio::detail::net_api_plugin_empty result; #define INVOKE_V_V(api_handle, call_name) \ - body = parse_params(body); \ + body = parse_params(body); \ api_handle.call_name(); \ eosio::detail::net_api_plugin_empty result; diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 6fd977b4e5..485df3e058 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -347,7 +347,7 @@ fc::variant call( const std::string& url, const std::string& path) { return call( url, path, fc::variant() ); } eosio::chain_apis::read_only::get_consensus_parameters_results get_consensus_parameters() { - return call(default_url, get_consensus_parameters_func).as(); + return call(url, get_consensus_parameters_func).as(); } eosio::chain_apis::read_only::get_info_results get_info() { From 830a2766e74feae5c364ef49731799140c1ad010 Mon Sep 17 00:00:00 2001 From: Clayton Calabrese Date: Tue, 19 Jul 2022 12:05:03 -0500 Subject: [PATCH 3/3] remove mentions of kv_database_config. --- plugins/chain_plugin/chain_plugin.cpp | 1 - .../chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index adb1ce4a15..9141072cde 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2747,7 +2747,6 @@ read_only::get_consensus_parameters(const get_consensus_parameters_params& ) con get_consensus_parameters_results results; results.chain_config = db.get_global_properties().configuration; - results.kv_database_config = db.get_global_properties().kv_configuration; results.wasm_config = db.get_global_properties().wasm_configuration; return results; 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 4b6169ae44..ddf4c8132c 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -675,7 +674,6 @@ class read_only { using get_consensus_parameters_params = empty; struct get_consensus_parameters_results { chain::chain_config chain_config; - chain::kv_database_config kv_database_config; chain::wasm_config wasm_config; }; get_consensus_parameters_results get_consensus_parameters(const get_consensus_parameters_params&) const; @@ -913,4 +911,4 @@ FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_params, (transaction FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_result, (required_keys) ) FC_REFLECT( eosio::chain_apis::read_only::compute_transaction_params, (transaction)) FC_REFLECT( eosio::chain_apis::read_only::compute_transaction_results, (transaction_id)(processed) ) -FC_REFLECT( eosio::chain_apis::read_only::get_consensus_parameters_results, (chain_config)(kv_database_config)(wasm_config)) +FC_REFLECT( eosio::chain_apis::read_only::get_consensus_parameters_results, (chain_config)(wasm_config))