From 2ff87b73ea3a90fad41b31a02a940d53fdf24a0c Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 6 Feb 2024 12:06:53 -0600 Subject: [PATCH] GH-2175 Remove unneeded proposal_id and proposal_digest --- libraries/chain/hotstuff/hotstuff.cpp | 30 +---------------- .../include/eosio/chain/hotstuff/hotstuff.hpp | 33 ++++--------------- unittests/block_state_tests.cpp | 20 +++++------ 3 files changed, 18 insertions(+), 65 deletions(-) diff --git a/libraries/chain/hotstuff/hotstuff.cpp b/libraries/chain/hotstuff/hotstuff.cpp index 93642aebf7..ca43590ab9 100644 --- a/libraries/chain/hotstuff/hotstuff.cpp +++ b/libraries/chain/hotstuff/hotstuff.cpp @@ -140,8 +140,6 @@ valid_quorum_certificate pending_quorum_certificate::to_valid_quorum_certificate valid_quorum_certificate valid_qc; - valid_qc._proposal_id = _proposal_id; - valid_qc._proposal_digest = _proposal_digest; if( _state == state_t::strong ) { valid_qc._strong_votes = _strong_votes._bitset; valid_qc._sig = _strong_votes._sig; @@ -155,41 +153,15 @@ valid_quorum_certificate pending_quorum_certificate::to_valid_quorum_certificate return valid_qc; } -// ================== begin compatibility functions ======================= -// these are present just to make the tests still work. will be removed. -// these assume *only* strong votes. -quorum_certificate_message pending_quorum_certificate::to_msg() const { - return {.proposal_id = _proposal_id, - .strong_votes = bitset_to_vector(_strong_votes._bitset), - .active_agg_sig = _strong_votes._sig}; -} - -std::string pending_quorum_certificate::get_votes_string() const { - return std::string("strong(\"") + bitset_to_string(_strong_votes._bitset) + "\", weak(\"" + - bitset_to_string(_weak_votes._bitset) + "\""; -} -// ================== end compatibility functions ======================= - valid_quorum_certificate::valid_quorum_certificate( - const fc::sha256& proposal_id, const std::vector& proposal_digest, const std::vector& strong_votes, // bitset encoding, following canonical order const std::vector& weak_votes, // bitset encoding, following canonical order const bls_signature& sig) - : _proposal_id(proposal_id) - , _proposal_digest(proposal_digest) - , _sig(sig) { + : _sig(sig) { if (!strong_votes.empty()) _strong_votes = vector_to_bitset(strong_votes); if (!weak_votes.empty()) _weak_votes = vector_to_bitset(weak_votes); } -quorum_certificate_message valid_quorum_certificate::to_msg() const { - return { - .proposal_id = _proposal_id, - .strong_votes = _strong_votes ? bitset_to_vector(*_strong_votes) : std::vector{1, 0}, - .active_agg_sig = _sig - }; -} - } // namespace eosio::chain diff --git a/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp index e2003fa313..2650260b9d 100644 --- a/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp +++ b/libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp @@ -107,9 +107,7 @@ namespace eosio::chain { // -------------------- valid_quorum_certificate ------------------------------------------------- class valid_quorum_certificate { public: - valid_quorum_certificate(const fc::sha256& proposal_id, - const std::vector& proposal_digest, - const std::vector& strong_votes, //bitset encoding, following canonical order + valid_quorum_certificate(const std::vector& strong_votes, //bitset encoding, following canonical order const std::vector& weak_votes, //bitset encoding, following canonical order const bls_signature& sig); @@ -119,16 +117,7 @@ namespace eosio::chain { bool is_weak() const { return !!_weak_votes; } bool is_strong() const { return !_weak_votes; } - // ================== begin compatibility functions ======================= - // these are present just to make the tests still work. will be removed. - // these assume *only* strong votes. - quorum_certificate_message to_msg() const; - const fc::sha256& get_proposal_id() const { return _proposal_id; } - // ================== end compatibility functions ======================= - friend struct fc::reflector; - fc::sha256 _proposal_id; // [todo] remove - std::vector _proposal_digest; // [todo] remove std::optional _strong_votes; std::optional _weak_votes; bls_signature _sig; @@ -174,28 +163,18 @@ namespace eosio::chain { // thread safe std::pair add_vote(bool strong, - const std::vector&proposal_digest, + const std::vector& proposal_digest, size_t index, - const bls_public_key&pubkey, - const bls_signature&sig, + const bls_public_key& pubkey, + const bls_signature& sig, uint64_t weight); state_t state() const { std::lock_guard g(*_mtx); return _state; }; valid_quorum_certificate to_valid_quorum_certificate() const; - // ================== begin compatibility functions ======================= - // these are present just to make the tests still work. will be removed. - // these assume *only* strong votes. - quorum_certificate_message to_msg() const; - const fc::sha256& get_proposal_id() const { return _proposal_id; } - std::string get_votes_string() const; - // ================== end compatibility functions ======================= - private: friend struct fc::reflector; friend class qc_chain; - fc::sha256 _proposal_id; // only used in to_msg(). Remove eventually - std::vector _proposal_digest; std::unique_ptr _mtx; uint64_t _quorum {0}; uint64_t _max_weak_sum_before_weak_final {0}; // max weak sum before becoming weak_final @@ -228,5 +207,7 @@ FC_REFLECT(eosio::chain::vote_message, (proposal_id)(strong)(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::hs_message, (msg)); -FC_REFLECT(eosio::chain::valid_quorum_certificate, (_proposal_id)(_proposal_digest)(_strong_votes)(_weak_votes)(_sig)); +FC_REFLECT(eosio::chain::valid_quorum_certificate, (_strong_votes)(_weak_votes)(_sig)); +FC_REFLECT(eosio::chain::pending_quorum_certificate, (_quorum)(_max_weak_sum_before_weak_final)(_state)(_strong_sum)(_weak_sum)(_weak_votes)(_strong_votes)); +FC_REFLECT(eosio::chain::pending_quorum_certificate::votes_t, (_bitset)(_sig)); FC_REFLECT(eosio::chain::quorum_certificate, (block_num)(qc)); diff --git a/unittests/block_state_tests.cpp b/unittests/block_state_tests.cpp index dfe074afa4..2092e63b78 100644 --- a/unittests/block_state_tests.cpp +++ b/unittests/block_state_tests.cpp @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { agg_sig = fc::crypto::blslib::aggregate({agg_sig, sig_2}); // create a valid_quorum_certificate - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), {}, agg_sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), {}, agg_sig); BOOST_REQUIRE_NO_THROW( bsp->verify_qc(qc) ); } @@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { agg_sig = fc::crypto::blslib::aggregate({agg_sig, strong_sig}); agg_sig = fc::crypto::blslib::aggregate({agg_sig, weak_sig}); - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), bitset_to_vector(weak_votes), agg_sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), bitset_to_vector(weak_votes), agg_sig); BOOST_REQUIRE_NO_THROW( bsp->verify_qc(qc) ); } @@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { } // create a valid_quorum_certificate - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), {}, agg_sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), {}, agg_sig); BOOST_REQUIRE_NO_THROW( bsp->verify_qc(qc) ); } @@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { } // create a valid_quorum_certificate - valid_quorum_certificate qc({}, {}, {}, bitset_to_vector(weak_votes), agg_sig); + valid_quorum_certificate qc({}, bitset_to_vector(weak_votes), agg_sig); BOOST_REQUIRE_NO_THROW( bsp->verify_qc(qc) ); } @@ -303,7 +303,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { agg_sig = fc::crypto::blslib::aggregate({agg_sig, sig_2}); // create a valid_quorum_certificate - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), {}, agg_sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), {}, agg_sig); BOOST_CHECK_EXCEPTION( bsp->verify_qc(qc), block_validate_exception, eosio::testing::fc_exception_message_starts_with("strong quorum is not met") ); } @@ -317,7 +317,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { agg_sig = fc::crypto::blslib::aggregate({agg_sig, sig_2}); // create a valid_quorum_certificate - valid_quorum_certificate qc({}, {}, {}, bitset_to_vector(weak_votes), agg_sig); + valid_quorum_certificate qc({}, bitset_to_vector(weak_votes), agg_sig); BOOST_CHECK_EXCEPTION( bsp->verify_qc(qc), block_validate_exception, eosio::testing::fc_exception_message_starts_with("weak quorum is not met") ); } @@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { sig = fc::crypto::blslib::aggregate({sig, sig_2}); // create a valid_quorum_certificate - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), {}, sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), {}, sig); BOOST_CHECK_EXCEPTION( bsp->verify_qc(qc), block_validate_exception, eosio::testing::fc_exception_message_is("signature validation failed") ); } @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { sig = fc::crypto::blslib::aggregate({sig, sig_2}); // create a valid_quorum_certificate - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), {}, sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), {}, sig); BOOST_CHECK_EXCEPTION( bsp->verify_qc(qc), block_validate_exception, eosio::testing::fc_exception_message_is("signature validation failed") ); } @@ -369,7 +369,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { sig = fc::crypto::blslib::aggregate({sig, strong_sig}); sig = fc::crypto::blslib::aggregate({sig, weak_sig}); - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), bitset_to_vector(weak_votes), sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), bitset_to_vector(weak_votes), sig); BOOST_CHECK_EXCEPTION( bsp->verify_qc(qc), block_validate_exception, eosio::testing::fc_exception_message_is("signature validation failed") ); } @@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(verify_qc_test) try { sig = fc::crypto::blslib::aggregate({sig, strong_sig}); sig = fc::crypto::blslib::aggregate({sig, weak_sig}); - valid_quorum_certificate qc({}, {}, bitset_to_vector(strong_votes), bitset_to_vector(weak_votes), sig); + valid_quorum_certificate qc(bitset_to_vector(strong_votes), bitset_to_vector(weak_votes), sig); BOOST_CHECK_EXCEPTION( bsp->verify_qc(qc), block_validate_exception, eosio::testing::fc_exception_message_is("signature validation failed") ); } } FC_LOG_AND_RETHROW();