diff --git a/CMakeModules/EosioTester.cmake.in b/CMakeModules/EosioTester.cmake.in index f7816310ac..155819b03f 100644 --- a/CMakeModules/EosioTester.cmake.in +++ b/CMakeModules/EosioTester.cmake.in @@ -47,7 +47,6 @@ find_library(libfc fc @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH) find_library(libsecp256k1 secp256k1 @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH) find_library(libbn256 bn256 @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH) find_library(libbls12-381 bls12-381 @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH) -find_library(libhotstuff hotstuff @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH) find_library(libwasm WASM @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH) find_library(libwast WAST @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH) @@ -73,7 +72,6 @@ add_library(EosioChain INTERFACE) target_link_libraries(EosioChain INTERFACE ${libchain} - ${libhotstuff} ${libfc} ${libwast} ${libwasm} diff --git a/CMakeModules/EosioTesterBuild.cmake.in b/CMakeModules/EosioTesterBuild.cmake.in index 06002a3d71..91828dc700 100644 --- a/CMakeModules/EosioTesterBuild.cmake.in +++ b/CMakeModules/EosioTesterBuild.cmake.in @@ -44,7 +44,6 @@ find_library(libfc fc @CMAKE_BINARY_DIR@/libraries/libfc NO_DEFAULT_PATH) find_library(libsecp256k1 secp256k1 @CMAKE_BINARY_DIR@/libraries/libfc/secp256k1 NO_DEFAULT_PATH) find_library(libbn256 bn256 @CMAKE_BINARY_DIR@/libraries/libfc/libraries/bn256/src NO_DEFAULT_PATH) find_library(libbls12-381 bls12-381 @CMAKE_BINARY_DIR@/libraries/libfc/libraries/bls12-381 NO_DEFAULT_PATH) -find_library(libhotstuff hotstuff @CMAKE_BINARY_DIR@/libraries/hotstuff NO_DEFAULT_PATH) find_library(libwasm WASM @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/WASM NO_DEFAULT_PATH) find_library(libwast WAST @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/WAST NO_DEFAULT_PATH) @@ -70,7 +69,6 @@ add_library(EosioChain INTERFACE) target_link_libraries(EosioChain INTERFACE ${libchain} - ${libhotstuff} ${libfc} ${libwast} ${libwasm} diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index a3a5df16c4..c7b83238de 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -24,7 +24,6 @@ add_subdirectory( testing ) add_subdirectory( version ) add_subdirectory( state_history ) add_subdirectory( cli11 ) -add_subdirectory( hotstuff ) set(USE_EXISTING_SOFTFLOAT ON CACHE BOOL "use pre-exisiting softfloat lib") set(ENABLE_TOOLS OFF CACHE BOOL "Build tools") diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 9948f04656..c58fc31141 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -3,6 +3,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/genesis_state_root_key.cpp.in ${CMAKE file(GLOB HEADERS "include/eosio/chain/*.hpp" "include/eosio/chain/webassembly/*.hpp" + "include/eosio/chain/hotstuff/*.hpp" "${CMAKE_CURRENT_BINARY_DIR}/include/eosio/chain/core_symbol.hpp" ) if((APPLE AND UNIX) OR (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")) @@ -78,6 +79,11 @@ set(CHAIN_WEBASSEMBLY_SOURCES webassembly/transaction.cpp ) +set(CHAIN_HOTSTUFF_SOURCES + hotstuff/chain_pacemaker.cpp + hotstuff/qc_chain.cpp +) + add_library(eosio_rapidjson INTERFACE) target_include_directories(eosio_rapidjson INTERFACE ../rapidjson/include) @@ -119,6 +125,7 @@ add_library( eosio_chain ${CHAIN_EOSVMOC_SOURCES} ${CHAIN_EOSVM_SOURCES} ${CHAIN_WEBASSEMBLY_SOURCES} + ${CHAIN_HOTSTUFF_SOURCES} authority.cpp finalizer_set.cpp @@ -144,7 +151,7 @@ add_library( eosio_chain add_library(boost_numeric_ublas INTERFACE) add_library(Boost::numeric_ublas ALIAS boost_numeric_ublas) -target_link_libraries( eosio_chain PUBLIC hotstuff bn256 fc chainbase eosio_rapidjson Logging IR WAST WASM +target_link_libraries( eosio_chain PUBLIC bn256 fc chainbase eosio_rapidjson Logging IR WAST WASM softfloat builtins ${CHAIN_EOSVM_LIBRARIES} ${LLVM_LIBS} ${CHAIN_RT_LINKAGE} Boost::signals2 Boost::hana Boost::property_tree Boost::multi_index Boost::asio Boost::lockfree Boost::assign Boost::accumulators @@ -172,6 +179,8 @@ if(EOSVMOC_ENABLE_DEVELOPER_OPTIONS) target_compile_definitions(eosio_chain PUBLIC EOSIO_EOS_VM_OC_DEVELOPER) endif() +add_subdirectory(hotstuff/test) + install( TARGETS eosio_chain RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT dev EXCLUDE_FROM_ALL LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT dev EXCLUDE_FROM_ALL diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 6532409859..c1b9f9df04 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -28,8 +28,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -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, hotstuff::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 hotstuff::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( hotstuff::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 hotstuff::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/hotstuff/chain_pacemaker.cpp b/libraries/chain/hotstuff/chain_pacemaker.cpp similarity index 99% rename from libraries/hotstuff/chain_pacemaker.cpp rename to libraries/chain/hotstuff/chain_pacemaker.cpp index 1002a22718..a832700b56 100644 --- a/libraries/hotstuff/chain_pacemaker.cpp +++ b/libraries/chain/hotstuff/chain_pacemaker.cpp @@ -1,11 +1,11 @@ -#include +#include #include #include // comment this out to remove the core profiler #define HS_CORE_PROFILER -namespace eosio { namespace hotstuff { +namespace eosio::chain { // ======================== Core profiling instrumentation ========================= #ifdef HS_CORE_PROFILER @@ -273,4 +273,4 @@ namespace eosio { namespace hotstuff { prof.core_out(); } -}} +} // namespace eosio::chain diff --git a/libraries/hotstuff/qc_chain.cpp b/libraries/chain/hotstuff/qc_chain.cpp similarity index 99% rename from libraries/hotstuff/qc_chain.cpp rename to libraries/chain/hotstuff/qc_chain.cpp index 7589497abc..c5ff49b6c6 100644 --- a/libraries/hotstuff/qc_chain.cpp +++ b/libraries/chain/hotstuff/qc_chain.cpp @@ -1,8 +1,8 @@ -#include +#include #include #include -namespace eosio::hotstuff { +namespace eosio::chain { void qc_chain::write_safety_state_file() { if (_safety_state_file.empty()) diff --git a/libraries/hotstuff/test/CMakeLists.txt b/libraries/chain/hotstuff/test/CMakeLists.txt similarity index 76% rename from libraries/hotstuff/test/CMakeLists.txt rename to libraries/chain/hotstuff/test/CMakeLists.txt index eda3efb0c5..1ebb5d3810 100644 --- a/libraries/hotstuff/test/CMakeLists.txt +++ b/libraries/chain/hotstuff/test/CMakeLists.txt @@ -1,6 +1,6 @@ -add_executable( test_hotstuff test_hotstuff.cpp test_hotstuff_state.cpp hotstuff_tools.cpp test_pacemaker.cpp) -target_link_libraries( test_hotstuff hotstuff fc Boost::unit_test_framework) - -add_test(NAME test_hotstuff COMMAND test_hotstuff WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -set_property(TEST test_hotstuff PROPERTY LABELS nonparallelizable_tests) - +add_executable( test_hotstuff test_hotstuff.cpp test_hotstuff_state.cpp hotstuff_tools.cpp test_pacemaker.cpp) +target_link_libraries( test_hotstuff eosio_chain fc Boost::unit_test_framework) + +add_test(NAME test_hotstuff COMMAND test_hotstuff WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +set_property(TEST test_hotstuff PROPERTY LABELS nonparallelizable_tests) + diff --git a/libraries/hotstuff/test/hotstuff_tools.cpp b/libraries/chain/hotstuff/test/hotstuff_tools.cpp similarity index 97% rename from libraries/hotstuff/test/hotstuff_tools.cpp rename to libraries/chain/hotstuff/test/hotstuff_tools.cpp index ba1131c9c7..49326990ec 100644 --- a/libraries/hotstuff/test/hotstuff_tools.cpp +++ b/libraries/chain/hotstuff/test/hotstuff_tools.cpp @@ -6,13 +6,11 @@ #include #include -#include - +#include BOOST_AUTO_TEST_CASE(view_number_tests) try { - using namespace eosio::hotstuff; - using eosio::chain::block_id_type; - + using namespace eosio::chain; + hs_proposal_message hspm_1; hs_proposal_message hspm_2; hs_proposal_message hspm_3; @@ -65,7 +63,7 @@ BOOST_AUTO_TEST_CASE(view_number_tests) try { // Allow boost to print `pending_quorum_certificate::state_t` // ----------------------------------------------------------------------------- namespace std { - using state_t = eosio::hotstuff::pending_quorum_certificate::state_t; + using state_t = eosio::chain::pending_quorum_certificate::state_t; std::ostream& operator<<(std::ostream& os, state_t s) { switch(s) { @@ -80,7 +78,6 @@ namespace std { } BOOST_AUTO_TEST_CASE(qc_state_transitions) try { - using namespace eosio::hotstuff; using namespace eosio::chain; using namespace fc::crypto::blslib; using state_t = pending_quorum_certificate::state_t; diff --git a/libraries/hotstuff/test/test_hotstuff.cpp b/libraries/chain/hotstuff/test/test_hotstuff.cpp similarity index 99% rename from libraries/hotstuff/test/test_hotstuff.cpp rename to libraries/chain/hotstuff/test/test_hotstuff.cpp index b1ab5ae8c0..d176cf24d4 100644 --- a/libraries/hotstuff/test/test_hotstuff.cpp +++ b/libraries/chain/hotstuff/test/test_hotstuff.cpp @@ -8,8 +8,8 @@ #include -#include -#include +#include "test_pacemaker.hpp" +#include #include #include @@ -17,7 +17,7 @@ #include #include -using namespace eosio::hotstuff; +using namespace eosio::chain; using std::cout; @@ -75,7 +75,7 @@ class hotstuff_test_handler { for (size_t i = 0 ; i < replicas.size() ; i++){ fc::crypto::blslib::bls_private_key sk = fc::crypto::blslib::bls_private_key(replica_keys[i]); - eosio::hotstuff::bls_pub_priv_key_map_t keys{{sk.get_public_key().to_string(), sk.to_string()}}; + bls_pub_priv_key_map_t keys{{sk.get_public_key().to_string(), sk.to_string()}}; qc_chain *qcc_ptr = new qc_chain(replica_keys[i].to_string(), &tpm, {replicas[i]}, keys, hotstuff_logger, std::string()); std::shared_ptr qcc_shared_ptr(qcc_ptr); _qc_chains.push_back( std::make_pair(replicas[i], qcc_shared_ptr) ); diff --git a/libraries/chain/hotstuff/test/test_hotstuff_state.cpp b/libraries/chain/hotstuff/test/test_hotstuff_state.cpp new file mode 100644 index 0000000000..1a3e871b9e --- /dev/null +++ b/libraries/chain/hotstuff/test/test_hotstuff_state.cpp @@ -0,0 +1,153 @@ +#include + +#include +#include + +#include + +#include +#include + +#include + +using std::cout; +using namespace eosio::chain; + +BOOST_AUTO_TEST_SUITE(test_hotstuff_state) + +const std::string file_path_1("temp_hs_safety"); +//const std::string file_path_2("temp_hs_liveness"); + +BOOST_AUTO_TEST_CASE(write_safety_state_to_file) try { + + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; + + 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; + + view_number v_height = hspm_1.get_view_number(); + + 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 = get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); + + 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( state_db_manager::write(file_path_1, ss) ); + + //fc::cfile pfile; + //pfile.set_file_path(file_path_1); + //pfile.open(fc::cfile::truncate_rw_mode); + //pfile.write("force garbage to fail read_safety_state_from_file", 20); + //pfile.close(); + +} FC_LOG_AND_RETHROW(); + +BOOST_AUTO_TEST_CASE(read_safety_state_from_file) try { + + safety_state ss; + + BOOST_CHECK( state_db_manager::read(file_path_1, ss) ); + + std::remove(file_path_1.c_str()); + + //test correct values + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; + + 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; + + view_number v_height = hspm_1.get_view_number(); + + 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 = get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); + + //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); + +} FC_LOG_AND_RETHROW(); + +#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 { + + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; + + 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 = get_digest_to_sign(hspm_1.block_id, hspm_1.phase_counter, hspm_1.final_on_qc); + + 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 = get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); + + //mock quorum_certificate + 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"); + + liveness_state ls(high_qc, b_leaf, b_exec); + + write_state(file_path_2, ls); + +} FC_LOG_AND_RETHROW(); + +BOOST_AUTO_TEST_CASE(read_liveness_state_from_file) try { + + liveness_state ls; + + read_state(file_path_2, ls); + + std::remove(file_path_2.c_str()); + + //test correct values + + hs_proposal_message hspm_1; + hs_proposal_message hspm_2; + + 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 = 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 + 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"); + + BOOST_CHECK(ls.high_qc == high_qc); + BOOST_CHECK(ls.b_exec == b_exec); + BOOST_CHECK(ls.b_leaf == b_leaf); + +} FC_LOG_AND_RETHROW();*/ + +BOOST_AUTO_TEST_SUITE_END() diff --git a/libraries/hotstuff/test/test_pacemaker.cpp b/libraries/chain/hotstuff/test/test_pacemaker.cpp similarity index 99% rename from libraries/hotstuff/test/test_pacemaker.cpp rename to libraries/chain/hotstuff/test/test_pacemaker.cpp index 3ffb8587b5..2f748c0b45 100644 --- a/libraries/hotstuff/test/test_pacemaker.cpp +++ b/libraries/chain/hotstuff/test/test_pacemaker.cpp @@ -1,7 +1,7 @@ -#include +#include "test_pacemaker.hpp" #include -namespace eosio::hotstuff { +namespace eosio::chain { void test_pacemaker::set_proposer(name proposer) { _proposer = proposer; diff --git a/libraries/hotstuff/include/eosio/hotstuff/test_pacemaker.hpp b/libraries/chain/hotstuff/test/test_pacemaker.hpp similarity index 96% rename from libraries/hotstuff/include/eosio/hotstuff/test_pacemaker.hpp rename to libraries/chain/hotstuff/test/test_pacemaker.hpp index 9feaa15b15..169bbcbc3c 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/test_pacemaker.hpp +++ b/libraries/chain/hotstuff/test/test_pacemaker.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include //#include -namespace eosio { namespace hotstuff { +namespace eosio::chain { class test_pacemaker : public base_pacemaker { public: @@ -106,4 +106,4 @@ namespace eosio { namespace hotstuff { uint32_t _quorum_threshold = 15; //todo : calculate from schedule }; -}} +} // eosio::chain diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 451b5ec3af..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::vm { class wasm_allocator; } -namespace eosio { namespace vm { class wasm_allocator; }} +namespace eosio::chain { -namespace eosio::hotstuff { 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, hotstuff::bls_pub_priv_key_map_t finalizer_keys, fc::logger& hotstuff_logger); - void register_pacemaker_bcast_function(std::function&, const hotstuff::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( hotstuff::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 hotstuff::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/hotstuff/include/eosio/hotstuff/base_pacemaker.hpp b/libraries/chain/include/eosio/chain/hotstuff/base_pacemaker.hpp similarity index 80% rename from libraries/hotstuff/include/eosio/hotstuff/base_pacemaker.hpp rename to libraries/chain/include/eosio/chain/hotstuff/base_pacemaker.hpp index c9b0edb3f9..1e547da5da 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/base_pacemaker.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/base_pacemaker.hpp @@ -1,11 +1,11 @@ #pragma once -#include +#include #include #include #include -namespace eosio::hotstuff { +namespace eosio::chain { // Abstract pacemaker; a reference of this type will only be used by qc_chain, as qc_chain // cannot know which environment it is in. @@ -21,12 +21,12 @@ namespace eosio::hotstuff { #warning discuss virtual uint32_t get_quorum_threshold() = 0; - virtual chain::block_id_type get_current_block_id() = 0; + virtual block_id_type get_current_block_id() = 0; - virtual chain::name get_proposer() = 0; - virtual chain::name get_leader() = 0; - virtual chain::name get_next_leader() = 0; - virtual const chain::finalizer_set& get_finalizer_set() = 0; + virtual name get_proposer() = 0; + virtual name get_leader() = 0; + virtual name get_next_leader() = 0; + virtual const finalizer_set& get_finalizer_set() = 0; //outbound communications; 'id' is the producer name (can be ignored if/when irrelevant to the implementer) virtual void send_hs_proposal_msg(const hs_proposal_message& msg, const std::string& id, const std::optional& exclude_peer = std::nullopt) = 0; diff --git a/libraries/hotstuff/include/eosio/hotstuff/chain_pacemaker.hpp b/libraries/chain/include/eosio/chain/hotstuff/chain_pacemaker.hpp similarity index 97% rename from libraries/hotstuff/include/eosio/hotstuff/chain_pacemaker.hpp rename to libraries/chain/include/eosio/chain/hotstuff/chain_pacemaker.hpp index d1b82a27ac..b016795f10 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/chain_pacemaker.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/chain_pacemaker.hpp @@ -1,17 +1,15 @@ #pragma once -#include -#include +#include +#include #include #include namespace eosio::chain { - class controller; -} -namespace eosio::hotstuff { + class controller; class chain_pacemaker : public base_pacemaker { public: diff --git a/libraries/hotstuff/include/eosio/hotstuff/hotstuff.hpp b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp similarity index 65% rename from libraries/hotstuff/include/eosio/hotstuff/hotstuff.hpp rename to libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp index 89acc1ce09..577955e079 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/hotstuff.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp @@ -7,14 +7,14 @@ #include -namespace eosio::hotstuff { +namespace eosio::chain { using hs_bitset = boost::dynamic_bitset; using bls_key_map_t = std::map; - inline chain::digest_type get_digest_to_sign(const chain::block_id_type& block_id, uint8_t phase_counter, const fc::sha256& final_on_qc) { - chain::digest_type h1 = chain::digest_type::hash( std::make_pair( std::cref(block_id), phase_counter ) ); - chain::digest_type h2 = chain::digest_type::hash( std::make_pair( std::cref(h1), std::cref(final_on_qc) ) ); + inline digest_type get_digest_to_sign(const block_id_type& block_id, uint8_t phase_counter, const fc::sha256& final_on_qc) { + digest_type h1 = digest_type::hash( std::make_pair( std::cref(block_id), phase_counter ) ); + digest_type h2 = digest_type::hash( std::make_pair( std::cref(h1), std::cref(final_on_qc) ) ); return h2; } @@ -41,8 +41,8 @@ namespace eosio::hotstuff { }; struct extended_schedule { - chain::producer_authority_schedule producer_schedule; - std::map bls_pub_keys; + producer_authority_schedule producer_schedule; + std::map bls_pub_keys; }; struct quorum_certificate_message { @@ -61,23 +61,23 @@ namespace eosio::hotstuff { struct hs_proposal_message { fc::sha256 proposal_id; //vote on proposal - chain::block_id_type block_id; + block_id_type block_id; fc::sha256 parent_id; //new proposal fc::sha256 final_on_qc; quorum_certificate_message justify; //justification uint8_t phase_counter = 0; - mutable std::optional digest; + mutable std::optional digest; - chain::digest_type get_proposal_digest() const { + digest_type get_proposal_digest() const { if (!digest) digest.emplace(get_digest_to_sign(block_id, phase_counter, final_on_qc)); return *digest; }; - uint32_t block_num() const { return chain::block_header::num_from_id(block_id); } - uint64_t get_key() const { return compute_height(chain::block_header::num_from_id(block_id), phase_counter); }; + uint32_t block_num() const { return block_header::num_from_id(block_id); } + uint64_t get_key() const { return compute_height(block_header::num_from_id(block_id), phase_counter); }; - view_number get_view_number() const { return view_number(chain::block_header::num_from_id(block_id), phase_counter); }; + view_number get_view_number() const { return view_number(block_header::num_from_id(block_id), phase_counter); }; }; struct hs_new_view_message { @@ -100,8 +100,8 @@ namespace eosio::hotstuff { 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; + 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; @@ -116,14 +116,14 @@ namespace eosio::hotstuff { } }; -} //eosio::hotstuff +} //eosio::chain -FC_REFLECT(eosio::hotstuff::view_number, (bheight)(pcounter)); -FC_REFLECT(eosio::hotstuff::quorum_certificate_message, (proposal_id)(strong_votes)(weak_votes)(active_agg_sig)); -FC_REFLECT(eosio::hotstuff::extended_schedule, (producer_schedule)(bls_pub_keys)); -FC_REFLECT(eosio::hotstuff::hs_vote_message, (proposal_id)(finalizer_key)(sig)); -FC_REFLECT(eosio::hotstuff::hs_proposal_message, (proposal_id)(block_id)(parent_id)(final_on_qc)(justify)(phase_counter)); -FC_REFLECT(eosio::hotstuff::hs_new_view_message, (high_qc)); -FC_REFLECT(eosio::hotstuff::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::hotstuff::hs_message, (msg)); +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::hs_vote_message, (proposal_id)(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)); diff --git a/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp b/libraries/chain/include/eosio/chain/hotstuff/qc_chain.hpp similarity index 98% rename from libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp rename to libraries/chain/include/eosio/chain/hotstuff/qc_chain.hpp index 3c1113536c..dbc4b0a325 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/qc_chain.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include @@ -17,16 +17,12 @@ #include #include #include -#include #include #include -#include -#include - -namespace eosio::hotstuff { +namespace eosio::chain { template class state_db_manager { public: diff --git a/libraries/hotstuff/include/eosio/hotstuff/state.hpp b/libraries/chain/include/eosio/chain/hotstuff/state.hpp similarity index 93% rename from libraries/hotstuff/include/eosio/hotstuff/state.hpp rename to libraries/chain/include/eosio/chain/hotstuff/state.hpp index b016efb7e3..fc899cafaf 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/state.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/state.hpp @@ -1,6 +1,6 @@ -#include +#include -namespace eosio::hotstuff { +namespace eosio::chain { using namespace eosio::chain; @@ -56,4 +56,4 @@ namespace eosio::hotstuff { }; } -FC_REFLECT(eosio::hotstuff::safety_state, (_states)) +FC_REFLECT(eosio::chain::safety_state, (_states)) diff --git a/libraries/hotstuff/CMakeLists.txt b/libraries/hotstuff/CMakeLists.txt deleted file mode 100644 index 6fd8501988..0000000000 --- a/libraries/hotstuff/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -file(GLOB HEADERS "include/eosio/hotstuff/*.hpp") - -add_library( hotstuff - chain_pacemaker.cpp - qc_chain.cpp - ${HEADERS} - ) - -target_link_libraries( hotstuff - PUBLIC eosio_chain fc - ) - -target_include_directories( hotstuff - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" - ) - -add_subdirectory( test ) - -install(TARGETS hotstuff - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT dev EXCLUDE_FROM_ALL - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT dev EXCLUDE_FROM_ALL) -install(DIRECTORY include/eosio/hotstuff/ - DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/hotstuff - COMPONENT dev EXCLUDE_FROM_ALL) diff --git a/libraries/hotstuff/test/test_hotstuff_state.cpp b/libraries/hotstuff/test/test_hotstuff_state.cpp deleted file mode 100644 index 97c2a3cb4e..0000000000 --- a/libraries/hotstuff/test/test_hotstuff_state.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include - -#include -#include - -#include - -#include -#include - -#include - -using std::cout; - -BOOST_AUTO_TEST_SUITE(test_hotstuff_state) - -const std::string file_path_1("temp_hs_safety"); -//const std::string file_path_2("temp_hs_liveness"); - -BOOST_AUTO_TEST_CASE(write_safety_state_to_file) try { - - eosio::hotstuff::hs_proposal_message hspm_1; - eosio::hotstuff::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.phase_counter = 2; - - eosio::hotstuff::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.phase_counter = 0; - - fc::sha256 b_lock = eosio::hotstuff::get_digest_to_sign(hspm_2.block_id, hspm_2.phase_counter, hspm_2.final_on_qc); - - eosio::hotstuff::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::hotstuff::state_db_manager::write(file_path_1, ss) ); - - //fc::cfile pfile; - //pfile.set_file_path(file_path_1); - //pfile.open(fc::cfile::truncate_rw_mode); - //pfile.write("force garbage to fail read_safety_state_from_file", 20); - //pfile.close(); - -} FC_LOG_AND_RETHROW(); - -BOOST_AUTO_TEST_CASE(read_safety_state_from_file) try { - - eosio::hotstuff::safety_state ss; - - BOOST_CHECK( eosio::hotstuff::state_db_manager::read(file_path_1, ss) ); - - std::remove(file_path_1.c_str()); - - //test correct values - eosio::hotstuff::hs_proposal_message hspm_1; - eosio::hotstuff::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.phase_counter = 2; - - eosio::hotstuff::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.phase_counter = 0; - - fc::sha256 b_lock = eosio::hotstuff::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{""}); - - 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); - -} FC_LOG_AND_RETHROW(); - -#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::hotstuff::hs_proposal_message hspm_1; - eosio::hotstuff::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.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.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::hotstuff::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::hotstuff::liveness_state ls(high_qc, b_leaf, b_exec); - - eosio::hotstuff::write_state(file_path_2, ls); - -} FC_LOG_AND_RETHROW(); - -BOOST_AUTO_TEST_CASE(read_liveness_state_from_file) try { - - eosio::hotstuff::liveness_state ls; - - eosio::hotstuff::read_state(file_path_2, ls); - - std::remove(file_path_2.c_str()); - - //test correct values - - eosio::hotstuff::hs_proposal_message hspm_1; - eosio::hotstuff::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.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.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::hotstuff::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"); - - BOOST_CHECK(ls.high_qc == high_qc); - BOOST_CHECK(ls.b_exec == b_exec); - BOOST_CHECK(ls.b_leaf == b_leaf); - -} FC_LOG_AND_RETHROW();*/ - -BOOST_AUTO_TEST_SUITE_END() diff --git a/libraries/testing/CMakeLists.txt b/libraries/testing/CMakeLists.txt index cf6476f9d7..491a868536 100644 --- a/libraries/testing/CMakeLists.txt +++ b/libraries/testing/CMakeLists.txt @@ -50,7 +50,7 @@ add_library( eosio_testing ${HEADERS} ) -target_link_libraries( eosio_testing eosio_testing_contracts eosio_chain hotstuff fc chainbase Logging IR WAST WASM) +target_link_libraries( eosio_testing eosio_testing_contracts eosio_chain fc chainbase Logging IR WAST WASM) target_include_directories( eosio_testing PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include" diff --git a/plugins/chain_plugin/CMakeLists.txt b/plugins/chain_plugin/CMakeLists.txt index 71a85e4f67..ae21541990 100644 --- a/plugins/chain_plugin/CMakeLists.txt +++ b/plugins/chain_plugin/CMakeLists.txt @@ -11,7 +11,7 @@ if(EOSIO_ENABLE_DEVELOPER_OPTIONS) target_compile_definitions(chain_plugin PUBLIC EOSIO_DEVELOPER) endif() -target_link_libraries( chain_plugin eosio_chain custom_appbase appbase resource_monitor_plugin hotstuff Boost::bimap ) +target_link_libraries( chain_plugin eosio_chain custom_appbase appbase resource_monitor_plugin Boost::bimap ) target_include_directories( chain_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../chain_interface/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/appbase/include" "${CMAKE_CURRENT_SOURCE_DIR}/../resource_monitor_plugin/include") add_subdirectory( test ) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 97986484ec..5d02f9b4af 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2641,7 +2641,7 @@ 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; - hotstuff::finalizer_state fs; + chain::finalizer_state fs; db.get_finalizer_state( fs ); results.b_leaf = fs.b_leaf; results.b_lock = fs.b_lock; @@ -2655,7 +2655,7 @@ read_only::get_finalizer_state(const get_finalizer_state_params&, const fc::time results.schedule = fs.schedule; results.proposals.reserve( fs.proposals.size() ); for (const auto& proposal : fs.proposals) { - const hotstuff::hs_proposal_message& p = proposal.second; + const chain::hs_proposal_message& p = proposal.second; results.proposals.push_back( hs_complete_proposal_message( p ) ); } 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 3a45fcd152..b23c83acf2 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -835,11 +835,11 @@ class read_only : public api_base { chain::block_id_type block_id; fc::sha256 parent_id; fc::sha256 final_on_qc; - hotstuff::quorum_certificate_message justify; + 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 hotstuff::hs_proposal_message& p ) { + 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; @@ -860,10 +860,10 @@ class read_only : public api_base { fc::sha256 b_finality_violation; chain::block_id_type block_exec; chain::block_id_type pending_proposal_block; - hotstuff::view_number v_height; - hotstuff::quorum_certificate_message high_qc; - hotstuff::quorum_certificate_message current_qc; - hotstuff::extended_schedule schedule; + chain::view_number v_height; + chain::quorum_certificate_message high_qc; + chain::quorum_certificate_message current_qc; + chain::extended_schedule schedule; vector proposals; }; diff --git a/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp b/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp index ef7a2d488a..4862b226a3 100644 --- a/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp +++ b/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include namespace eosio { @@ -143,7 +143,7 @@ namespace eosio { sync_request_message, signed_block, packed_transaction, - hotstuff::hs_message>; + hs_message>; } // namespace eosio diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index fdf0beeb53..907a098514 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -538,8 +538,8 @@ namespace eosio { void transaction_ack(const std::pair&); void on_irreversible_block( const block_state_ptr& block ); - void bcast_hs_message( const std::optional& exclude_peer, const hotstuff::hs_message& msg ); - void warn_hs_message( uint32_t sender_peer, const hotstuff::hs_message_warning& code ); + void bcast_hs_message( const std::optional& exclude_peer, const chain::hs_message& msg ); + void warn_hs_message( uint32_t sender_peer, const chain::hs_message_warning& code ); void start_conn_timer(boost::asio::steady_timer::duration du, std::weak_ptr from_connection); void start_expire_timer(); @@ -1095,7 +1095,7 @@ namespace eosio { void handle_message( const block_id_type& id, signed_block_ptr ptr ); void handle_message( const packed_transaction& msg ) = delete; // packed_transaction_ptr overload used instead void handle_message( packed_transaction_ptr trx ); - void handle_message( const hotstuff::hs_message& msg ); + void handle_message( const chain::hs_message& msg ); // returns calculated number of blocks combined latency uint32_t calc_block_latency(); @@ -1177,7 +1177,7 @@ namespace eosio { c->handle_message( msg ); } - void operator()( const hotstuff::hs_message& msg ) const { + void operator()( const chain::hs_message& msg ) const { // continue call to handle_message on connection strand peer_dlog( c, "handle hs_message" ); c->handle_message( msg ); @@ -3666,7 +3666,7 @@ namespace eosio { } } - void connection::handle_message( const hotstuff::hs_message& msg ) { + void connection::handle_message( const chain::hs_message& msg ) { peer_dlog(this, "received hs: ${msg}", ("msg", msg)); controller& cc = my_impl->chain_plug->chain(); cc.notify_hs_message(connection_id, msg); @@ -3926,7 +3926,7 @@ namespace eosio { on_active_schedule(chain_plug->chain().active_producers()); } - void net_plugin_impl::bcast_hs_message( const std::optional& exclude_peer, const hotstuff::hs_message& msg ) { + void net_plugin_impl::bcast_hs_message( const std::optional& exclude_peer, const chain::hs_message& msg ) { fc_dlog(logger, "sending hs msg: ${msg}", ("msg", msg)); buffer_factory buff_factory; @@ -3937,7 +3937,7 @@ namespace eosio { }); } - void net_plugin_impl::warn_hs_message( uint32_t sender_peer, const hotstuff::hs_message_warning& code ) { + void net_plugin_impl::warn_hs_message( uint32_t sender_peer, const chain::hs_message_warning& code ) { // potentially react to (repeated) receipt of invalid, irrelevant, duplicate, etc. hotstuff messages from sender_peer (connection ID) here } @@ -4289,11 +4289,11 @@ namespace eosio { controller& cc = chain_plug->chain(); cc.register_pacemaker_bcast_function( - [my = shared_from_this()](const std::optional& c, const hotstuff::hs_message& s) { + [my = shared_from_this()](const std::optional& c, const chain::hs_message& s) { my->bcast_hs_message(c, s); } ); cc.register_pacemaker_warn_function( - [my = shared_from_this()](uint32_t c, hotstuff::hs_message_warning s) { + [my = shared_from_this()](uint32_t c, chain::hs_message_warning s) { my->warn_hs_message(c, s); } ); diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 2927db7357..70d15c4a31 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -492,7 +492,7 @@ class producer_plugin_impl : public std::enable_shared_from_this _signature_providers; - hotstuff::bls_pub_priv_key_map_t _finalizer_keys; // public, private + chain::bls_pub_priv_key_map_t _finalizer_keys; // public, private std::set _producers; boost::asio::deadline_timer _timer; block_timing_util::producer_watermarks _producer_watermarks; diff --git a/tests/chain_plugin_tests.cpp b/tests/chain_plugin_tests.cpp index b40d38e5c9..f3a18e2e10 100644 --- a/tests/chain_plugin_tests.cpp +++ b/tests/chain_plugin_tests.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include diff --git a/tests/get_producers_tests.cpp b/tests/get_producers_tests.cpp index 3655defaaf..faf641b8e7 100644 --- a/tests/get_producers_tests.cpp +++ b/tests/get_producers_tests.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/tests/get_table_seckey_tests.cpp b/tests/get_table_seckey_tests.cpp index 0ee0990577..a7b28eac1c 100644 --- a/tests/get_table_seckey_tests.cpp +++ b/tests/get_table_seckey_tests.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include diff --git a/tests/get_table_tests.cpp b/tests/get_table_tests.cpp index eb6640d538..504f34a39f 100644 --- a/tests/get_table_tests.cpp +++ b/tests/get_table_tests.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/test_chain_plugin.cpp b/tests/test_chain_plugin.cpp index 9332bbd8c6..de9dbcb13e 100644 --- a/tests/test_chain_plugin.cpp +++ b/tests/test_chain_plugin.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include