diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 7dd6f9f084..c1b9f9df04 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -240,7 +240,7 @@ struct controller_impl { std::optional pending; block_state_ptr head; fork_database fork_db; - std::optional pacemaker; + std::optional pacemaker; std::atomic hs_irreversible_block_num{0}; resource_limits_manager resource_limits; subjective_billing subjective_bill; @@ -3324,17 +3324,17 @@ int64_t controller::set_proposed_producers( vector producers return version; } -void controller::create_pacemaker(std::set my_producers, chain::bls_pub_priv_key_map_t finalizer_keys, fc::logger& hotstuff_logger) { +void controller::create_pacemaker(std::set my_producers, bls_pub_priv_key_map_t finalizer_keys, fc::logger& hotstuff_logger) { EOS_ASSERT( !my->pacemaker, misc_exception, "duplicate chain_pacemaker initialization" ); my->pacemaker.emplace(this, std::move(my_producers), std::move(finalizer_keys), hotstuff_logger); } -void controller::register_pacemaker_bcast_function(std::function&, const chain::hs_message&)> bcast_hs_message) { +void controller::register_pacemaker_bcast_function(std::function&, const hs_message&)> bcast_hs_message) { EOS_ASSERT( my->pacemaker, misc_exception, "chain_pacemaker not created" ); my->pacemaker->register_bcast_function(std::move(bcast_hs_message)); } -void controller::register_pacemaker_warn_function(std::function warn_hs_message) { +void controller::register_pacemaker_warn_function(std::function warn_hs_message) { EOS_ASSERT( my->pacemaker, misc_exception, "chain_pacemaker not created" ); my->pacemaker->register_warn_function(std::move(warn_hs_message)); } @@ -3343,13 +3343,13 @@ void controller::set_proposed_finalizers( const finalizer_set& fin_set ) { my->set_proposed_finalizers(fin_set); } -void controller::get_finalizer_state( chain::finalizer_state& fs ) const { +void controller::get_finalizer_state( finalizer_state& fs ) const { EOS_ASSERT( my->pacemaker, misc_exception, "chain_pacemaker not created" ); my->pacemaker->get_state(fs); } // called from net threads -void controller::notify_hs_message( const uint32_t connection_id, const chain::hs_message& msg ) { +void controller::notify_hs_message( const uint32_t connection_id, const hs_message& msg ) { my->pacemaker->on_hs_msg(connection_id, msg); }; diff --git a/libraries/chain/hotstuff/chain_pacemaker.cpp b/libraries/chain/hotstuff/chain_pacemaker.cpp index ceeb11bae5..a832700b56 100644 --- a/libraries/chain/hotstuff/chain_pacemaker.cpp +++ b/libraries/chain/hotstuff/chain_pacemaker.cpp @@ -5,7 +5,7 @@ // comment this out to remove the core profiler #define HS_CORE_PROFILER -namespace eosio { namespace chain { +namespace eosio::chain { // ======================== Core profiling instrumentation ========================= #ifdef HS_CORE_PROFILER @@ -273,4 +273,4 @@ namespace eosio { namespace chain { prof.core_out(); } -}} +} // namespace eosio::chain diff --git a/libraries/chain/hotstuff/test/hotstuff_tools.cpp b/libraries/chain/hotstuff/test/hotstuff_tools.cpp index 49326990ec..26247cb398 100644 --- a/libraries/chain/hotstuff/test/hotstuff_tools.cpp +++ b/libraries/chain/hotstuff/test/hotstuff_tools.cpp @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(qc_state_transitions) try { { pending_quorum_certificate qc2(qc); - // add a strong vote + // add a strong votegi // ----------------- strong_vote(qc2, digest, 2); BOOST_CHECK_EQUAL(qc2._state, state_t::strong); diff --git a/libraries/chain/hotstuff/test/test_hotstuff_state.cpp b/libraries/chain/hotstuff/test/test_hotstuff_state.cpp index 173ba5e82e..1a3e871b9e 100644 --- a/libraries/chain/hotstuff/test/test_hotstuff_state.cpp +++ b/libraries/chain/hotstuff/test/test_hotstuff_state.cpp @@ -11,6 +11,7 @@ #include using std::cout; +using namespace eosio::chain; BOOST_AUTO_TEST_SUITE(test_hotstuff_state) @@ -19,27 +20,27 @@ const std::string file_path_1("temp_hs_safety"); BOOST_AUTO_TEST_CASE(write_safety_state_to_file) try { - eosio::chain::hs_proposal_message hspm_1; - eosio::chain::hs_proposal_message hspm_2; + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; - hspm_1.block_id = eosio::chain::block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217067 - hspm_1.final_on_qc = eosio::chain::block_id_type(); + hspm_1.block_id = block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217067 + hspm_1.final_on_qc = block_id_type(); hspm_1.phase_counter = 2; - eosio::chain::view_number v_height = hspm_1.get_view_number(); + view_number v_height = hspm_1.get_view_number(); - hspm_2.block_id = eosio::chain::block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 - hspm_2.final_on_qc = eosio::chain::block_id_type(); + hspm_2.block_id = block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 + hspm_2.final_on_qc = block_id_type(); hspm_2.phase_counter = 0; - fc::sha256 b_lock = eosio::chain::get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); + fc::sha256 b_lock = get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); - eosio::chain::safety_state ss; + safety_state ss; ss.set_v_height(fc::crypto::blslib::bls_public_key{}, v_height); ss.set_b_lock(fc::crypto::blslib::bls_public_key{}, b_lock); - BOOST_CHECK( eosio::chain::state_db_manager::write(file_path_1, ss) ); + BOOST_CHECK( state_db_manager::write(file_path_1, ss) ); //fc::cfile pfile; //pfile.set_file_path(file_path_1); @@ -51,29 +52,29 @@ BOOST_AUTO_TEST_CASE(write_safety_state_to_file) try { BOOST_AUTO_TEST_CASE(read_safety_state_from_file) try { - eosio::chain::safety_state ss; + safety_state ss; - BOOST_CHECK( eosio::chain::state_db_manager::read(file_path_1, ss) ); + BOOST_CHECK( state_db_manager::read(file_path_1, ss) ); std::remove(file_path_1.c_str()); //test correct values - eosio::chain::hs_proposal_message hspm_1; - eosio::chain::hs_proposal_message hspm_2; + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; - hspm_1.block_id = eosio::chain::block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217067 - hspm_1.final_on_qc = eosio::chain::block_id_type(); + hspm_1.block_id = block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217067 + hspm_1.final_on_qc = block_id_type(); hspm_1.phase_counter = 2; - eosio::chain::view_number v_height = hspm_1.get_view_number(); + view_number v_height = hspm_1.get_view_number(); - hspm_2.block_id = eosio::chain::block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 - hspm_2.final_on_qc = eosio::chain::block_id_type(); + hspm_2.block_id = block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 + hspm_2.final_on_qc = block_id_type(); hspm_2.phase_counter = 0; - fc::sha256 b_lock = eosio::chain::get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); + fc::sha256 b_lock = get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); - //std::pair ss = get_safety_state(eosio::chain::name{""}); + //std::pair ss = get_safety_state(name{""}); BOOST_CHECK_EQUAL(ss.get_v_height(fc::crypto::blslib::bls_public_key{}), v_height); BOOST_CHECK_EQUAL(ss.get_b_lock(fc::crypto::blslib::bls_public_key{}), b_lock); @@ -83,61 +84,61 @@ BOOST_AUTO_TEST_CASE(read_safety_state_from_file) try { #warning TODO decide on liveness state file then implement it in qc_chain and then test it here /*BOOST_AUTO_TEST_CASE(write_liveness_state_to_file) try { - eosio::chain::hs_proposal_message hspm_1; - eosio::chain::hs_proposal_message hspm_2; + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; - hspm_1.block_id = eosio::chain::block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217068 - hspm_1.final_on_qc = eosio::chain::block_id_type(); + hspm_1.block_id = block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217068 + hspm_1.final_on_qc = block_id_type(); hspm_1.phase_counter = 2; - fc::sha256 b_exec = eosio::chain::get_digest_to_sign(hspm_1.block_id, hspm_1.phase_counter, hspm_1.final_on_qc); + fc::sha256 b_exec = get_digest_to_sign(hspm_1.block_id, hspm_1.phase_counter, hspm_1.final_on_qc); - hspm_2.block_id = eosio::chain::block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 - hspm_2.final_on_qc = eosio::chain::block_id_type(); + hspm_2.block_id = block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 + hspm_2.final_on_qc = block_id_type(); hspm_2.phase_counter = 1; - fc::sha256 b_leaf = eosio::chain::get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); + fc::sha256 b_leaf = get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); //mock quorum_certificate - eosio::chain::quorum_certificate high_qc; + quorum_certificate high_qc; high_qc.proposal_id = fc::sha256("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); high_qc.active_finalizers = 1245; high_qc.active_agg_sig = fc::crypto::blslib::bls_signature("SIG_BLS_23PuSu1B72cPe6wxGkKjAaaZqA1Ph79zSoW7omsKKUrnprbA3cJCJVhT48QKUG6ofjYTTg4BA4TrVENWyrxjTomwLX6TGdVg2RYhKH7Kk9X23K5ohuhKQcWQ6AwJJGVSbSp4"); - eosio::chain::liveness_state ls(high_qc, b_leaf, b_exec); + liveness_state ls(high_qc, b_leaf, b_exec); - eosio::chain::write_state(file_path_2, ls); + write_state(file_path_2, ls); } FC_LOG_AND_RETHROW(); BOOST_AUTO_TEST_CASE(read_liveness_state_from_file) try { - eosio::chain::liveness_state ls; + liveness_state ls; - eosio::chain::read_state(file_path_2, ls); + read_state(file_path_2, ls); std::remove(file_path_2.c_str()); //test correct values - eosio::chain::hs_proposal_message hspm_1; - eosio::chain::hs_proposal_message hspm_2; + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; - hspm_1.block_id = eosio::chain::block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217067 - hspm_1.final_on_qc = eosio::chain::block_id_type(); + hspm_1.block_id = block_id_type("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); //UX Network block #194217067 + hspm_1.final_on_qc = block_id_type(); hspm_1.phase_counter = 2; fc::sha256 b_exec = eosio::hotstuff::get_digest_to_sign(hspm_1.block_id, hspm_1.phase_counter, hspm_1.final_on_qc); - hspm_2.block_id = eosio::chain::block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 - hspm_2.final_on_qc = eosio::chain::block_id_type(); + hspm_2.block_id = block_id_type("0b93846ba73bdfdc9b2383863b64f8f921c8a2379d6dde4e05bdd2e434e9392a"); //UX Network block #194217067 + hspm_2.final_on_qc = block_id_type(); hspm_2.phase_counter = 1; fc::sha256 b_leaf = eosio::hotstuff::get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); //mock quorum_certificate - eosio::chain::quorum_certificate high_qc; + quorum_certificate high_qc; high_qc.proposal_id = fc::sha256("0b93846cf55a3ecbcd8f9bd86866b1aecc2e8bd981e40c92609ce3a68dbd0824"); high_qc.active_finalizers = 1245; diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 5d4a0ed4b7..bf33ab9351 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -15,21 +15,18 @@ namespace chainbase { class database; } -namespace boost { namespace asio { +namespace boost::asio { class thread_pool; -}} +} -namespace eosio { namespace vm { class wasm_allocator; }} +namespace eosio::vm { class wasm_allocator; } namespace eosio::chain { + struct hs_message; struct finalizer_state; enum class hs_message_warning; using bls_pub_priv_key_map_t = std::map; -} - -namespace eosio { namespace chain { - struct finalizer_set; class authorization_manager; @@ -303,14 +300,14 @@ namespace eosio { namespace chain { int64_t set_proposed_producers( vector producers ); - void create_pacemaker(std::set my_producers, chain::bls_pub_priv_key_map_t finalizer_keys, fc::logger& hotstuff_logger); - void register_pacemaker_bcast_function(std::function&, const chain::hs_message&)> bcast_hs_message); - void register_pacemaker_warn_function(std::function warn_hs_message); + void create_pacemaker(std::set my_producers, bls_pub_priv_key_map_t finalizer_keys, fc::logger& hotstuff_logger); + void register_pacemaker_bcast_function(std::function&, const hs_message&)> bcast_hs_message); + void register_pacemaker_warn_function(std::function warn_hs_message); // called by host function set_finalizers void set_proposed_finalizers( const finalizer_set& fin_set ); - void get_finalizer_state( chain::finalizer_state& fs ) const; + void get_finalizer_state( finalizer_state& fs ) const; // called from net threads - void notify_hs_message( const uint32_t connection_id, const chain::hs_message& msg ); + void notify_hs_message( const uint32_t connection_id, const hs_message& msg ); bool light_validation_allowed() const; bool skip_auth_check()const; @@ -389,4 +386,4 @@ namespace eosio { namespace chain { std::unique_ptr my; }; -} } /// eosio::chain +} /// eosio::chain diff --git a/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp index 3082a98819..577955e079 100644 --- a/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp @@ -116,7 +116,7 @@ namespace eosio::chain { } }; -} //eosio::hotstuff +} //eosio::chain FC_REFLECT(eosio::chain::view_number, (bheight)(pcounter));