Skip to content

Commit

Permalink
Merge pull request #1934 from AntelopeIO/GH-1916-move-hotstuff
Browse files Browse the repository at this point in the history
IF: Move hotstuff lib into chain lib
  • Loading branch information
heifner authored Nov 28, 2023
2 parents 60835eb + 24348dc commit 06f8c43
Show file tree
Hide file tree
Showing 33 changed files with 275 additions and 306 deletions.
2 changes: 0 additions & 2 deletions CMakeModules/EosioTester.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -73,7 +72,6 @@ add_library(EosioChain INTERFACE)

target_link_libraries(EosioChain INTERFACE
${libchain}
${libhotstuff}
${libfc}
${libwast}
${libwasm}
Expand Down
2 changes: 0 additions & 2 deletions CMakeModules/EosioTesterBuild.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -70,7 +69,6 @@ add_library(EosioChain INTERFACE)

target_link_libraries(EosioChain INTERFACE
${libchain}
${libhotstuff}
${libfc}
${libwast}
${libwasm}
Expand Down
1 change: 0 additions & 1 deletion libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <eosio/chain/deep_mind.hpp>
#include <eosio/chain/finalizer_set.hpp>
#include <eosio/chain/finalizer_authority.hpp>
#include <eosio/hotstuff/hotstuff.hpp>
#include <eosio/hotstuff/chain_pacemaker.hpp>
#include <eosio/chain/hotstuff/hotstuff.hpp>
#include <eosio/chain/hotstuff/chain_pacemaker.hpp>

#include <chainbase/chainbase.hpp>
#include <eosio/vm/allocator.hpp>
Expand Down Expand Up @@ -240,7 +240,7 @@ struct controller_impl {
std::optional<pending_state> pending;
block_state_ptr head;
fork_database fork_db;
std::optional<hotstuff::chain_pacemaker> pacemaker;
std::optional<chain_pacemaker> pacemaker;
std::atomic<uint32_t> hs_irreversible_block_num{0};
resource_limits_manager resource_limits;
subjective_billing subjective_bill;
Expand Down Expand Up @@ -3324,17 +3324,17 @@ int64_t controller::set_proposed_producers( vector<producer_authority> producers
return version;
}

void controller::create_pacemaker(std::set<chain::account_name> my_producers, hotstuff::bls_pub_priv_key_map_t finalizer_keys, fc::logger& hotstuff_logger) {
void controller::create_pacemaker(std::set<account_name> 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<void(const std::optional<uint32_t>&, const hotstuff::hs_message&)> bcast_hs_message) {
void controller::register_pacemaker_bcast_function(std::function<void(const std::optional<uint32_t>&, 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<void(uint32_t, hotstuff::hs_message_warning)> warn_hs_message) {
void controller::register_pacemaker_warn_function(std::function<void(uint32_t, hs_message_warning)> warn_hs_message) {
EOS_ASSERT( my->pacemaker, misc_exception, "chain_pacemaker not created" );
my->pacemaker->register_warn_function(std::move(warn_hs_message));
}
Expand All @@ -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);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <eosio/hotstuff/chain_pacemaker.hpp>
#include <eosio/chain/hotstuff/chain_pacemaker.hpp>
#include <eosio/chain/finalizer_authority.hpp>
#include <iostream>

// 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
Expand Down Expand Up @@ -273,4 +273,4 @@ namespace eosio { namespace hotstuff {
prof.core_out();
}

}}
} // namespace eosio::chain
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <eosio/hotstuff/qc_chain.hpp>
#include <eosio/chain/hotstuff/qc_chain.hpp>
#include <fc/scoped_exit.hpp>
#include <boost/range/adaptor/reversed.hpp>

namespace eosio::hotstuff {
namespace eosio::chain {

void qc_chain::write_safety_state_file() {
if (_safety_state_file.empty())
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
#include <fc/crypto/bls_private_key.hpp>
#include <fc/crypto/bls_utils.hpp>

#include <eosio/hotstuff/qc_chain.hpp>

#include <eosio/chain/hotstuff/qc_chain.hpp>

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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

#include <boost/dynamic_bitset.hpp>

#include <eosio/hotstuff/test_pacemaker.hpp>
#include <eosio/hotstuff/qc_chain.hpp>
#include "test_pacemaker.hpp"
#include <eosio/chain/hotstuff/qc_chain.hpp>
#include <eosio/chain/finalizer_set.hpp>
#include <eosio/chain/finalizer_authority.hpp>

#include <eosio/chain/finalizer_set.hpp>
#include <fc/crypto/bls_private_key.hpp>
#include <fc/crypto/bls_utils.hpp>

using namespace eosio::hotstuff;
using namespace eosio::chain;

using std::cout;

Expand Down Expand Up @@ -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<qc_chain> qcc_shared_ptr(qcc_ptr);
_qc_chains.push_back( std::make_pair(replicas[i], qcc_shared_ptr) );
Expand Down
Loading

0 comments on commit 06f8c43

Please sign in to comment.