From 6cc68200e69600688881241626c6b47ae88d4c31 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 16 Apr 2024 13:50:02 -0500 Subject: [PATCH] GH-3 Simplify by adding a vote_signal_t type --- libraries/chain/controller.cpp | 16 ++++++++-------- .../chain/include/eosio/chain/controller.hpp | 3 ++- .../chain/include/eosio/chain/vote_processor.hpp | 15 ++++++--------- unittests/vote_processor_tests.cpp | 2 +- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index c172e1dc08..643ed231ec 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -947,14 +947,14 @@ struct controller_impl { signal accepted_block; signal irreversible_block; signal)> applied_transaction; - signal voted_block; + vote_signal_t voted_block; - vote_processor_t vote_processor{voted_block, - [this](const block_id_type& id) -> block_state_ptr { - return fork_db.apply_s([&](const auto& forkdb) { - return forkdb.get_block(id); - }); - }}; + vote_processor_t vote_processor{voted_block, + [this](const block_id_type& id) -> block_state_ptr { + return fork_db.apply_s([&](const auto& forkdb) { + return forkdb.get_block(id); + }); + }}; int64_t set_proposed_producers( vector producers ); int64_t set_proposed_producers_legacy( vector producers ); @@ -5548,7 +5548,7 @@ signal& controller::accepted_block_header() { signal& controller::accepted_block() { return my->accepted_block; } signal& controller::irreversible_block() { return my->irreversible_block; } signal)>& controller::applied_transaction() { return my->applied_transaction; } -signal& controller::voted_block() { return my->voted_block; } +vote_signal_t& controller::voted_block() { return my->voted_block; } chain_id_type controller::extract_chain_id(snapshot_reader& snapshot) { chain_snapshot_header header; diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 490b69b540..e8d1a5d1e3 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -60,6 +60,7 @@ namespace eosio::chain { using block_signal_params = std::tuple; // connection_id, vote result status, vote_message processed using vote_signal_params = std::tuple; + using vote_signal_t = signal; enum class db_read_mode { HEAD, @@ -377,7 +378,7 @@ namespace eosio::chain { signal& irreversible_block(); signal)>& applied_transaction(); // Unlike other signals, voted_block is signaled from other threads than the main thread. - signal& voted_block(); + vote_signal_t& voted_block(); const apply_handler* find_apply_handler( account_name contract, scope_name scope, action_name act )const; wasm_interface& get_wasm_interface(); diff --git a/libraries/chain/include/eosio/chain/vote_processor.hpp b/libraries/chain/include/eosio/chain/vote_processor.hpp index 8d8417cc16..1f53ca6212 100644 --- a/libraries/chain/include/eosio/chain/vote_processor.hpp +++ b/libraries/chain/include/eosio/chain/vote_processor.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -9,7 +10,7 @@ #include #include -namespace eosio { namespace chain { +namespace eosio::chain { /** * Process votes in a dedicated thread pool. @@ -32,8 +33,6 @@ class vote_processor_t { block_num_type block_num() const { return block_header::num_from_id(msg->block_id); } }; - using vote_signal_type = decltype(controller({},chain_id_type::empty_chain_id()).voted_block()); - using vote_index_type = boost::multi_index_container< vote, indexed_by< ordered_non_unique, @@ -48,7 +47,7 @@ class vote_processor_t { using fetch_block_func_t = std::function; - vote_signal_type& vote_signal; + vote_signal_t& vote_signal; fetch_block_func_t fetch_block_func; std::mutex mtx; @@ -119,7 +118,7 @@ class vote_processor_t { } public: - explicit vote_processor_t(vote_signal_type& vote_signal, fetch_block_func_t&& get_block) + explicit vote_processor_t(vote_signal_t& vote_signal, fetch_block_func_t&& get_block) : vote_signal(vote_signal) , fetch_block_func(get_block) {} @@ -148,9 +147,7 @@ class vote_processor_t { while (!stopped) { std::unique_lock g(mtx); cv.wait(g, [&]() { - if (!index.empty() || stopped) - return true; - return false; + return !index.empty() || stopped; }); if (stopped) break; @@ -240,4 +237,4 @@ class vote_processor_t { }; -} } //eosio::chain +} // namespace eosio::chain diff --git a/unittests/vote_processor_tests.cpp b/unittests/vote_processor_tests.cpp index 60f3964cd9..223e89de83 100644 --- a/unittests/vote_processor_tests.cpp +++ b/unittests/vote_processor_tests.cpp @@ -123,7 +123,7 @@ vote_message_ptr make_vote_message(const block_state_ptr& bsp) { BOOST_AUTO_TEST_SUITE(vote_processor_tests) BOOST_AUTO_TEST_CASE( vote_processor_test ) { - boost::signals2::signal voted_block; + vote_signal_t voted_block; uint32_t received_connection_id = 0; vote_status received_vote_status = vote_status::unknown_block;