Skip to content

Commit

Permalink
GH-2175 Remove unneeded proposal_id and proposal_digest
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Feb 6, 2024
1 parent ec53840 commit 2ff87b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 65 deletions.
30 changes: 1 addition & 29 deletions libraries/chain/hotstuff/hotstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<uint8_t>& proposal_digest,
const std::vector<uint32_t>& strong_votes, // bitset encoding, following canonical order
const std::vector<uint32_t>& 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<uint32_t>{1, 0},
.active_agg_sig = _sig
};
}

} // namespace eosio::chain
33 changes: 7 additions & 26 deletions libraries/chain/include/eosio/chain/hotstuff/hotstuff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>& proposal_digest,
const std::vector<uint32_t>& strong_votes, //bitset encoding, following canonical order
valid_quorum_certificate(const std::vector<uint32_t>& strong_votes, //bitset encoding, following canonical order
const std::vector<uint32_t>& weak_votes, //bitset encoding, following canonical order
const bls_signature& sig);

Expand All @@ -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<valid_quorum_certificate>;
fc::sha256 _proposal_id; // [todo] remove
std::vector<uint8_t> _proposal_digest; // [todo] remove
std::optional<hs_bitset> _strong_votes;
std::optional<hs_bitset> _weak_votes;
bls_signature _sig;
Expand Down Expand Up @@ -174,28 +163,18 @@ namespace eosio::chain {

// thread safe
std::pair<vote_status, bool> add_vote(bool strong,
const std::vector<uint8_t>&proposal_digest,
const std::vector<uint8_t>& 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<pending_quorum_certificate>;
friend class qc_chain;
fc::sha256 _proposal_id; // only used in to_msg(). Remove eventually
std::vector<uint8_t> _proposal_digest;
std::unique_ptr<std::mutex> _mtx;
uint64_t _quorum {0};
uint64_t _max_weak_sum_before_weak_final {0}; // max weak sum before becoming weak_final
Expand Down Expand Up @@ -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));
20 changes: 10 additions & 10 deletions unittests/block_state_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) );
}
Expand All @@ -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) );
}

Expand All @@ -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) );
}
Expand All @@ -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) );
}
Expand All @@ -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") );
}
Expand All @@ -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") );
}
Expand All @@ -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") );
}
Expand All @@ -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") );
}
Expand All @@ -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") );
}

Expand All @@ -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();
Expand Down

0 comments on commit 2ff87b7

Please sign in to comment.