Skip to content

Commit

Permalink
GH-1547 Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Aug 28, 2023
1 parent 863033f commit c2c0446
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/hotstuff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace eosio::chain {
const block_id_type NULL_BLOCK_ID = block_id_type("00");
const fc::sha256 NULL_PROPOSAL_ID = fc::sha256("00");

using hs_dynamic_bitset = boost::dynamic_bitset<uint32_t>;
using hs_bitset = boost::dynamic_bitset<uint32_t>;

inline uint64_t compute_height(uint32_t block_height, uint32_t phase_counter) {
return (uint64_t{block_height} << 32) | phase_counter;
Expand Down
17 changes: 8 additions & 9 deletions libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ namespace eosio::hotstuff {

explicit quorum_certificate(const quorum_certificate_message& msg)
: proposal_id(msg.proposal_id)
, active_finalizers()
, active_finalizers(msg.active_finalizers.cbegin(), msg.active_finalizers.cend())
, active_agg_sig(msg.active_agg_sig) {
active_finalizers.append(msg.active_finalizers.cbegin(), msg.active_finalizers.cend());
}

quorum_certificate_message to_msg() const {
Expand All @@ -56,16 +55,16 @@ namespace eosio::hotstuff {

void reset(const fc::sha256& proposal, size_t finalizer_size) {
proposal_id = proposal;
active_finalizers = hs_dynamic_bitset{finalizer_size};
active_finalizers = hs_bitset{finalizer_size};
active_agg_sig = fc::crypto::blslib::bls_signature();
quorum_met = false;
}

const hs_dynamic_bitset& get_active_finalizers() const {
const hs_bitset& get_active_finalizers() const {
assert(!active_finalizers.empty());
return active_finalizers;
}
void set_active_finalizers(const hs_dynamic_bitset& bs) {
void set_active_finalizers(const hs_bitset& bs) {
assert(!bs.empty());
active_finalizers = bs;
}
Expand All @@ -84,7 +83,7 @@ namespace eosio::hotstuff {
private:
friend struct fc::reflector<quorum_certificate>;
fc::sha256 proposal_id = NULL_PROPOSAL_ID;
hs_dynamic_bitset active_finalizers; //bitset encoding, following canonical order
hs_bitset active_finalizers; //bitset encoding, following canonical order
fc::crypto::blslib::bls_signature active_agg_sig;
bool quorum_met = false; // not serialized across network
};
Expand Down Expand Up @@ -120,15 +119,15 @@ namespace eosio::hotstuff {
// returns false if proposal with that same ID already exists at the store of its height
bool insert_proposal(const hs_proposal_message& proposal);

uint32_t positive_bits_count(const hs_dynamic_bitset& finalizers);
uint32_t positive_bits_count(const hs_bitset& finalizers);

hs_dynamic_bitset update_bitset(const hs_dynamic_bitset& finalizer_set, name finalizer);
hs_bitset update_bitset(const hs_bitset& finalizer_set, name finalizer);

digest_type get_digest_to_sign(const block_id_type& block_id, uint8_t phase_counter, const fc::sha256& final_on_qc); //get digest to sign from proposal data

void reset_qc(const fc::sha256& proposal_id); //reset current internal qc

bool evaluate_quorum(const extended_schedule& es, const hs_dynamic_bitset& finalizers, const fc::crypto::blslib::bls_signature& agg_sig, const hs_proposal_message& proposal); //evaluate quorum for a proposal
bool evaluate_quorum(const extended_schedule& es, const hs_bitset& finalizers, const fc::crypto::blslib::bls_signature& agg_sig, const hs_proposal_message& proposal); //evaluate quorum for a proposal

// qc.quorum_met has to be updated by the caller (if it wants to) based on the return value of this method
bool is_quorum_met(const quorum_certificate& qc, const extended_schedule& schedule, const hs_proposal_message& proposal); //check if quorum has been met over a proposal
Expand Down
12 changes: 6 additions & 6 deletions libraries/hotstuff/qc_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ namespace eosio { namespace hotstuff {
#endif
}

uint32_t qc_chain::positive_bits_count(const hs_dynamic_bitset& finalizers) {
uint32_t qc_chain::positive_bits_count(const hs_bitset& finalizers) {
return finalizers.count(); // the number of bits in this bitset that are set.
}

hs_dynamic_bitset qc_chain::update_bitset(const hs_dynamic_bitset& finalizer_set, name finalizer ) {
hs_bitset qc_chain::update_bitset(const hs_bitset& finalizer_set, name finalizer ) {

hs_dynamic_bitset b( finalizer_set );
hs_bitset b(finalizer_set );
vector<name> finalizers = _pacemaker->get_finalizers();
for (size_t i = 0; i < finalizers.size();i++) {
if (finalizers[i] == finalizer) {
Expand Down Expand Up @@ -223,7 +223,7 @@ namespace eosio { namespace hotstuff {
return b;
}

bool qc_chain::evaluate_quorum(const extended_schedule& es, const hs_dynamic_bitset& finalizers, const fc::crypto::blslib::bls_signature& agg_sig, const hs_proposal_message& proposal) {
bool qc_chain::evaluate_quorum(const extended_schedule& es, const hs_bitset& finalizers, const fc::crypto::blslib::bls_signature& agg_sig, const hs_proposal_message& proposal) {


if (positive_bits_count(finalizers) < _pacemaker->get_quorum_threshold()){
Expand All @@ -233,7 +233,7 @@ namespace eosio { namespace hotstuff {
fc::crypto::blslib::bls_public_key agg_key;

bool first = true;
for (hs_dynamic_bitset::size_type i = 0; i < finalizers.size(); ++i) {
for (hs_bitset::size_type i = 0; i < finalizers.size(); ++i) {
if (finalizers[i]){
//adding finalizer's key to the aggregate pub key
if (first) {
Expand Down Expand Up @@ -493,7 +493,7 @@ namespace eosio { namespace hotstuff {

auto increment_version = fc::make_scoped_exit([this]() { ++_state_version; });

const hs_dynamic_bitset& finalizer_set = _current_qc.get_active_finalizers();
const hs_bitset& finalizer_set = _current_qc.get_active_finalizers();
if (finalizer_set.any())
_current_qc.set_active_agg_sig(fc::crypto::blslib::aggregate({_current_qc.get_active_agg_sig(), vote.sig }));
else
Expand Down

0 comments on commit c2c0446

Please sign in to comment.