diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index f2d2af5315..030c738794 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -3332,7 +3333,7 @@ void controller::get_finalizer_state( hotstuff::finalizer_state& fs ) const { my->pacemaker->get_state(fs); } -void controller::create_pacemaker(std::set my_producers, hotstuff::bls_key_map_t finalizer_keys, fc::logger& hotstuff_logger) { +void controller::create_pacemaker(std::set my_producers, std::map 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); } @@ -3342,7 +3343,7 @@ void controller::register_pacemaker_bcast_function(std::functionpacemaker->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)); } diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index a8d4bd13b5..9951537425 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include @@ -22,6 +21,12 @@ namespace boost { namespace asio { namespace eosio { namespace vm { class wasm_allocator; }} +namespace eosio::hotstuff { + struct hs_message; + struct finalizer_state; + enum class hs_message_warning; +} + namespace eosio { namespace chain { struct finalizer_set; @@ -302,9 +307,9 @@ namespace eosio { namespace chain { void get_finalizer_state( hotstuff::finalizer_state& fs ) const; // called from net threads void notify_hs_message( const uint32_t connection_id, const hotstuff::hs_message& msg ); - void create_pacemaker(std::set my_producers, hotstuff::bls_key_map_t finalizer_keys, fc::logger& hotstuff_logger); + void create_pacemaker(std::set my_producers, std::map 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 register_pacemaker_warn_function(std::function warn_hs_message); bool light_validation_allowed() const; bool skip_auth_check()const; diff --git a/libraries/hotstuff/chain_pacemaker.cpp b/libraries/hotstuff/chain_pacemaker.cpp index 210a581247..ad638808aa 100644 --- a/libraries/hotstuff/chain_pacemaker.cpp +++ b/libraries/hotstuff/chain_pacemaker.cpp @@ -104,7 +104,7 @@ namespace eosio { namespace hotstuff { #warning TODO get a data directory str passed into the chain_pacemaker ctor and use it to compose the absolute filepathname that is passed to qc_chain ctor chain_pacemaker::chain_pacemaker(controller* chain, std::set my_producers, - bls_key_map_t finalizer_keys, + std::map finalizer_keys, fc::logger& logger) : _chain(chain), _qc_chain("default", this, std::move(my_producers), std::move(finalizer_keys), logger, eosio::chain::config::safetydb_filename), @@ -221,15 +221,15 @@ namespace eosio { namespace hotstuff { } void chain_pacemaker::send_hs_proposal_msg(const hs_proposal_message& msg, const std::string& id, const std::optional& exclude_peer) { - bcast_hs_message(exclude_peer, msg); + bcast_hs_message(exclude_peer, {msg}); } void chain_pacemaker::send_hs_vote_msg(const hs_vote_message& msg, const std::string& id, const std::optional& exclude_peer) { - bcast_hs_message(exclude_peer, msg); + bcast_hs_message(exclude_peer, {msg}); } void chain_pacemaker::send_hs_new_view_msg(const hs_new_view_message& msg, const std::string& id, const std::optional& exclude_peer) { - bcast_hs_message(exclude_peer, msg); + bcast_hs_message(exclude_peer, {msg}); } void chain_pacemaker::send_hs_message_warning(uint32_t sender_peer, const hs_message_warning code) { @@ -243,7 +243,7 @@ namespace eosio { namespace hotstuff { [this, connection_id](const hs_vote_message& m) { on_hs_vote_msg(connection_id, m); }, [this, connection_id](const hs_proposal_message& m) { on_hs_proposal_msg(connection_id, m); }, [this, connection_id](const hs_new_view_message& m) { on_hs_new_view_msg(connection_id, m); }, - }, msg); + }, msg.msg); } // called from net threads diff --git a/libraries/hotstuff/include/eosio/hotstuff/chain_pacemaker.hpp b/libraries/hotstuff/include/eosio/hotstuff/chain_pacemaker.hpp index c6b73ef99b..18fbf003be 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/chain_pacemaker.hpp +++ b/libraries/hotstuff/include/eosio/hotstuff/chain_pacemaker.hpp @@ -20,7 +20,7 @@ namespace eosio::hotstuff { chain_pacemaker(controller* chain, std::set my_producers, - bls_key_map_t finalizer_keys, + std::map finalizer_keys, fc::logger& logger); void register_bcast_function(std::function&, const hs_message&)> broadcast_hs_message); void register_warn_function(std::function warning_hs_message); diff --git a/libraries/hotstuff/include/eosio/hotstuff/hotstuff.hpp b/libraries/hotstuff/include/eosio/hotstuff/hotstuff.hpp index a23ee82006..62c5cacae4 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/hotstuff.hpp +++ b/libraries/hotstuff/include/eosio/hotstuff/hotstuff.hpp @@ -77,7 +77,9 @@ namespace eosio::hotstuff { quorum_certificate_message high_qc; //justification }; - using hs_message = std::variant; + struct hs_message { + std::variant msg; + }; enum class hs_message_warning { discarded, // default code for dropped messages (irrelevant, redundant, ...) @@ -118,3 +120,4 @@ 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, (chained_mode)(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)); diff --git a/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp b/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp index de3be8f4d9..04afcd2ea8 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp +++ b/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp @@ -153,7 +153,7 @@ namespace eosio::hotstuff { qc_chain(std::string id, base_pacemaker* pacemaker, std::set my_producers, - bls_key_map_t finalizer_keys, + std::map finalizer_keys, fc::logger& logger, std::string safety_state_file); diff --git a/libraries/hotstuff/qc_chain.cpp b/libraries/hotstuff/qc_chain.cpp index 3746be6133..937c28310c 100644 --- a/libraries/hotstuff/qc_chain.cpp +++ b/libraries/hotstuff/qc_chain.cpp @@ -165,18 +165,21 @@ namespace eosio::hotstuff { qc_chain::qc_chain(std::string id, base_pacemaker* pacemaker, std::set my_producers, - bls_key_map_t finalizer_keys, + std::map finalizer_keys, fc::logger& logger, std::string safety_state_file) : _pacemaker(pacemaker), _my_producers(std::move(my_producers)), - _my_finalizer_keys(std::move(finalizer_keys)), _id(std::move(id)), _safety_state_file(safety_state_file), _logger(logger) { //todo : read liveness state / select initialization heuristics ? + for (const auto& kp : finalizer_keys) { + _my_finalizer_keys[fc::crypto::blslib::bls_public_key{kp.first}] = fc::crypto::blslib::bls_private_key{kp.second}; + } + if (!_safety_state_file.empty()) { _safety_state_file_handle.set_file_path(safety_state_file); state_db_manager::read(_safety_state_file, _safety_state); diff --git a/libraries/hotstuff/test/test_hotstuff.cpp b/libraries/hotstuff/test/test_hotstuff.cpp index ff9dbe452d..a6c2964cae 100644 --- a/libraries/hotstuff/test/test_hotstuff.cpp +++ b/libraries/hotstuff/test/test_hotstuff.cpp @@ -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]); - bls_key_map_t keys{{sk.get_public_key(), sk}}; + std::map 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/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 37edcd90c7..fdf0beeb53 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -4293,7 +4293,7 @@ namespace eosio { my->bcast_hs_message(c, s); } ); cc.register_pacemaker_warn_function( - [my = shared_from_this()](uint32_t c, const hotstuff::hs_message_warning& s) { + [my = shared_from_this()](uint32_t c, hotstuff::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 a12fa8d980..d52634c925 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_key_map_t _finalizer_keys; + std::map _finalizer_keys; // public, private std::set _producers; boost::asio::deadline_timer _timer; block_timing_util::producer_watermarks _producer_watermarks; @@ -1138,7 +1138,7 @@ void producer_plugin_impl::plugin_initialize(const boost::program_options::varia const auto bls = app().get_plugin().bls_public_key_for_specification(key_spec_pair); if (bls) { const auto& [pubkey, privkey] = *bls; - _finalizer_keys[pubkey] = privkey; + _finalizer_keys[pubkey.to_string()] = privkey.to_string(); } } catch(secure_enclave_exception& e) { elog("Error with Secure Enclave signature provider: ${e}; ignoring ${val}", ("e", e.top_message())("val", key_spec_pair));