From 86c4305ffc4aa618f141b085b0602773ed380a34 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 26 Aug 2023 14:43:05 -0500 Subject: [PATCH] GH-1547 Minor cleanup --- .../hotstuff/include/eosio/hotstuff/qc_chain.hpp | 11 +++++------ libraries/hotstuff/qc_chain.cpp | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp b/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp index 63da359ba5..7c759ea044 100644 --- a/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp +++ b/libraries/hotstuff/include/eosio/hotstuff/qc_chain.hpp @@ -32,7 +32,7 @@ namespace eosio::hotstuff { class quorum_certificate { public: - explicit quorum_certificate(uint32_t finalizer_size = 0) { + explicit quorum_certificate(size_t finalizer_size = 0) { active_finalizers.resize(finalizer_size); } @@ -48,17 +48,16 @@ namespace eosio::hotstuff { .active_agg_sig = active_agg_sig}; } - void reset(const fc::sha256& proposal, uint32_t finalizer_size) { + void reset(const fc::sha256& proposal, size_t finalizer_size) { proposal_id = proposal; - active_finalizers.clear(); - active_finalizers.resize(finalizer_size); + active_finalizers = boost::dynamic_bitset<>{finalizer_size}; active_agg_sig = fc::crypto::blslib::bls_signature(); quorum_met = false; } - boost::dynamic_bitset<> get_active_finalizers() const { + const boost::dynamic_bitset<>& get_active_finalizers() const { assert(!active_finalizers.empty()); - return boost::dynamic_bitset(active_finalizers); + return active_finalizers; } void set_active_finalizers(const boost::dynamic_bitset<>& bs) { assert(!bs.empty()); diff --git a/libraries/hotstuff/qc_chain.cpp b/libraries/hotstuff/qc_chain.cpp index 35be416d52..afd156f8e9 100644 --- a/libraries/hotstuff/qc_chain.cpp +++ b/libraries/hotstuff/qc_chain.cpp @@ -225,7 +225,6 @@ namespace eosio { namespace hotstuff { bool qc_chain::evaluate_quorum(const extended_schedule& es, const boost::dynamic_bitset<>& finalizers, const fc::crypto::blslib::bls_signature& agg_sig, const hs_proposal_message& proposal) { - bool first = true; if (positive_bits_count(finalizers) < _pacemaker->get_quorum_threshold()){ return false; @@ -233,7 +232,8 @@ namespace eosio { namespace hotstuff { fc::crypto::blslib::bls_public_key agg_key; - for (boost::dynamic_bitset<>::size_type i = 0; i < finalizers.size(); i++) { + bool first = true; + for (boost::dynamic_bitset<>::size_type i = 0; i < finalizers.size(); ++i) { if (finalizers[i]){ //adding finalizer's key to the aggregate pub key if (first) { @@ -493,7 +493,7 @@ namespace eosio { namespace hotstuff { auto increment_version = fc::make_scoped_exit([this]() { ++_state_version; }); - boost::dynamic_bitset finalizer_set = _current_qc.get_active_finalizers(); + const boost::dynamic_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