From f8e685d442ce631527b6eddb87b4ee64606f0620 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:18:41 -0500 Subject: [PATCH 1/2] always set socket to blocking mode before read_message_with_fds's recvmsg() --- .../webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp b/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp index 15353d2e64..da1ee268b2 100644 --- a/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp +++ b/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp @@ -7,6 +7,16 @@ static constexpr size_t max_message_size = 8192; static constexpr size_t max_num_fds = 4; std::tuple> read_message_with_fds(boost::asio::local::datagram_protocol::socket& s) { + // read_message_with_fds() is intended to be blocking, and sockets it is used with are never explicitly set to non-blocking mode. + // But when doing an async_wait() on an asio socket, asio will set the underlying file descriptor to non-blocking mode. + // It's not clear why, but in some cases after async_wait() indicates readiness, a recvmsg() on the socket can fail with + // EAGAIN if the file descriptor is still in non-blocking mode (as asio had set it to). + // Always set the file descriptor to blocking mode before performing the recvmsg() + boost::system::error_code ec; + s.native_non_blocking(false, ec); + if(ec) + wlog("Failed to set socket's native blocking mode"); + return read_message_with_fds(s.native_handle()); } From 390004f58affb7bfbb405458f15eb1d32880ea3d Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Tue, 30 Jan 2024 15:33:19 -0500 Subject: [PATCH 2/2] remove get_finalizer_state RPC API related code --- libraries/chain/controller.cpp | 6 --- .../chain/include/eosio/chain/controller.hpp | 1 - .../include/eosio/chain/hotstuff/hotstuff.hpp | 28 ------------- plugins/chain_api_plugin/chain_api_plugin.cpp | 6 +-- plugins/chain_plugin/chain_plugin.cpp | 24 ----------- .../eosio/chain_plugin/chain_plugin.hpp | 41 ------------------- programs/cleos/httpc.hpp | 1 - programs/cleos/main.cpp | 9 ---- 8 files changed, 1 insertion(+), 115 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 0b3be942a3..344192d7a4 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -4385,12 +4385,6 @@ void controller::set_proposed_finalizers( const finalizer_policy& fin_pol ) { my->set_proposed_finalizers(fin_pol); } -void controller::get_finalizer_state( finalizer_state& fs ) const { - // TODO: determine what should be returned from chain_api_plugin get_finalizer_state -// EOS_ASSERT( my->pacemaker, misc_exception, "chain_pacemaker not created" ); -// my->pacemaker->get_state(fs); -} - // called from net threads bool controller::process_vote_message( const vote_message& vote ) { auto do_vote = [&vote](auto& forkdb) -> std::pair> { diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index a8f16bb1c1..931a3070b1 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -325,7 +325,6 @@ namespace eosio::chain { // called by host function set_finalizers void set_proposed_finalizers( const finalizer_policy& fin_set ); - void get_finalizer_state( finalizer_state& fs ) const; // called from net threads bool process_vote_message( const vote_message& msg ); diff --git a/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp index 7f3b21e653..a11e32653d 100644 --- a/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp @@ -42,11 +42,6 @@ namespace eosio::chain { uint8_t pcounter; }; - struct extended_schedule { - producer_authority_schedule producer_schedule; - std::map bls_pub_keys; - }; - struct quorum_certificate_message { fc::sha256 proposal_id; std::vector strong_votes; //bitset encoding, following canonical order @@ -97,27 +92,6 @@ namespace eosio::chain { invalid // invalid message (other reason) }; - struct finalizer_state { - fc::sha256 b_leaf; - fc::sha256 b_lock; - fc::sha256 b_exec; - fc::sha256 b_finality_violation; - block_id_type block_exec; - block_id_type pending_proposal_block; - view_number v_height; - quorum_certificate_message high_qc; - quorum_certificate_message current_qc; - extended_schedule schedule; - std::map proposals; - - const hs_proposal_message* get_proposal(const fc::sha256& id) const { - auto it = proposals.find(id); - if (it == proposals.end()) - return nullptr; - return & it->second; - } - }; - using bls_public_key = fc::crypto::blslib::bls_public_key; using bls_signature = fc::crypto::blslib::bls_signature; using bls_private_key = fc::crypto::blslib::bls_private_key; @@ -242,11 +216,9 @@ namespace eosio::chain { FC_REFLECT(eosio::chain::view_number, (bheight)(pcounter)); FC_REFLECT(eosio::chain::quorum_certificate_message, (proposal_id)(strong_votes)(weak_votes)(active_agg_sig)); -FC_REFLECT(eosio::chain::extended_schedule, (producer_schedule)(bls_pub_keys)); FC_REFLECT(eosio::chain::vote_message, (proposal_id)(strong)(finalizer_key)(sig)); FC_REFLECT(eosio::chain::hs_proposal_message, (proposal_id)(block_id)(parent_id)(final_on_qc)(justify)(phase_counter)); FC_REFLECT(eosio::chain::hs_new_view_message, (high_qc)); -FC_REFLECT(eosio::chain::finalizer_state, (b_leaf)(b_lock)(b_exec)(b_finality_violation)(block_exec)(pending_proposal_block)(v_height)(high_qc)(current_qc)(schedule)(proposals)); FC_REFLECT(eosio::chain::hs_message, (msg)); FC_REFLECT(eosio::chain::valid_quorum_certificate, (_proposal_id)(_proposal_digest)(_strong_votes)(_weak_votes)(_sig)); FC_REFLECT(eosio::chain::quorum_certificate, (block_num)(qc)); diff --git a/plugins/chain_api_plugin/chain_api_plugin.cpp b/plugins/chain_api_plugin/chain_api_plugin.cpp index 4d5b6c85c8..fc558536f5 100644 --- a/plugins/chain_api_plugin/chain_api_plugin.cpp +++ b/plugins/chain_api_plugin/chain_api_plugin.cpp @@ -179,12 +179,8 @@ void chain_api_plugin::plugin_startup() { CHAIN_RO_CALL_WITH_400(get_transaction_status, 200, http_params_types::params_required), }, appbase::exec_queue::read_only); } - - _http_plugin.add_api({ - CHAIN_RO_CALL(get_finalizer_state, 200, http_params_types::no_params) - }, appbase::exec_queue::read_only); } void chain_api_plugin::plugin_shutdown() {} -} \ No newline at end of file +} diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 33d5e03af2..6f66342c5a 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2598,30 +2598,6 @@ read_only::get_consensus_parameters(const get_consensus_parameters_params&, cons return results; } -read_only::get_finalizer_state_results -read_only::get_finalizer_state(const get_finalizer_state_params&, const fc::time_point& deadline ) const { - get_finalizer_state_results results; - - chain::finalizer_state fs; - db.get_finalizer_state( fs ); - results.b_leaf = fs.b_leaf; - results.b_lock = fs.b_lock; - results.b_exec = fs.b_exec; - results.b_finality_violation = fs.b_finality_violation; - results.block_exec = fs.block_exec; - results.pending_proposal_block = fs.pending_proposal_block; - results.v_height = fs.v_height; - results.high_qc = fs.high_qc; - results.current_qc = fs.current_qc; - results.schedule = fs.schedule; - results.proposals.reserve( fs.proposals.size() ); - for (const auto& proposal : fs.proposals) { - const chain::hs_proposal_message& p = proposal.second; - results.proposals.push_back( hs_complete_proposal_message( p ) ); - } - 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 e1fdf812c9..45576abe0e 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -823,45 +823,6 @@ class read_only : public api_base { std::optional wasm_config; }; get_consensus_parameters_results get_consensus_parameters(const get_consensus_parameters_params&, const fc::time_point& deadline) const; - - struct hs_complete_proposal_message { - fc::sha256 proposal_id; - chain::block_id_type block_id; - fc::sha256 parent_id; - fc::sha256 final_on_qc; - chain::quorum_certificate_message justify; - uint8_t phase_counter = 0; - uint32_t block_height = 0; - uint64_t view_number = 0; - explicit hs_complete_proposal_message( const chain::hs_proposal_message& p ) { - proposal_id = p.proposal_id; - block_id = p.block_id; - parent_id = p.parent_id; - final_on_qc = p.final_on_qc; - justify = p.justify; - phase_counter = p.phase_counter; - block_height = p.block_num(); - view_number = p.get_key(); - } - hs_complete_proposal_message() = default; // cleos requires this - }; - - using get_finalizer_state_params = empty; - struct get_finalizer_state_results { - fc::sha256 b_leaf; - fc::sha256 b_lock; - fc::sha256 b_exec; - fc::sha256 b_finality_violation; - chain::block_id_type block_exec; - chain::block_id_type pending_proposal_block; - chain::view_number v_height; - chain::quorum_certificate_message high_qc; - chain::quorum_certificate_message current_qc; - chain::extended_schedule schedule; - vector proposals; - }; - - get_finalizer_state_results get_finalizer_state(const get_finalizer_state_params&, const fc::time_point& deadline) const; }; class read_write : public api_base { @@ -1113,5 +1074,3 @@ FC_REFLECT( eosio::chain_apis::read_only::compute_transaction_results, (transact FC_REFLECT( eosio::chain_apis::read_only::send_read_only_transaction_params, (transaction)) FC_REFLECT( eosio::chain_apis::read_only::send_read_only_transaction_results, (transaction_id)(processed) ) FC_REFLECT( eosio::chain_apis::read_only::get_consensus_parameters_results, (chain_config)(wasm_config)) -FC_REFLECT( eosio::chain_apis::read_only::hs_complete_proposal_message, (proposal_id)(block_id)(parent_id)(final_on_qc)(justify)(phase_counter)(block_height)(view_number)) -FC_REFLECT( eosio::chain_apis::read_only::get_finalizer_state_results, (b_leaf)(b_lock)(b_exec)(b_finality_violation)(block_exec)(pending_proposal_block)(v_height)(high_qc)(current_qc)(schedule)(proposals)) diff --git a/programs/cleos/httpc.hpp b/programs/cleos/httpc.hpp index bae87d2b8d..d2bdf3079b 100644 --- a/programs/cleos/httpc.hpp +++ b/programs/cleos/httpc.hpp @@ -21,7 +21,6 @@ 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_finalizer_state_func = chain_func_base + "/get_finalizer_state"; 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"; diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index cc3e0484f2..b272f156f1 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -2367,10 +2367,6 @@ protocol_features_t get_supported_protocol_features() { return results; }; -eosio::chain_apis::read_only::get_finalizer_state_results get_finalizer_state() { - return call(::default_url, get_finalizer_state_func).as(); -} - struct activate_subcommand { string feature_name_str; std::string account_str = "eosio"; @@ -3417,11 +3413,6 @@ int main( int argc, char** argv ) { std::cout << supported_features.names << std::endl; }); - // get finalizer state - get->add_subcommand("finalizer_state", localized("Get finalizer state"))->callback([] { - std::cout << fc::json::to_pretty_string(get_finalizer_state()) << std::endl; - }); - // set subcommand auto setSubcommand = app.add_subcommand("set", localized("Set or update blockchain state")); setSubcommand->require_subcommand();