Skip to content

Commit

Permalink
Code style + efficiency improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
systemzax committed Sep 25, 2023
1 parent f6d7f06 commit 4ffc264
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 179 deletions.
29 changes: 6 additions & 23 deletions libraries/hotstuff/qc_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,36 +184,20 @@ namespace eosio::hotstuff {
}

bool qc_chain::evaluate_quorum(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()){
return false;
}

fc::crypto::blslib::bls_public_key agg_key;

const auto& c_finalizers = _pacemaker->get_finalizer_set().finalizers;

EOS_ASSERT(c_finalizers.size() == finalizers.size(), chain_exception, "error : public keys size != finalizers size" );

bool first = true;
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) {
first = false;
agg_key = c_finalizers[i].public_key;
} else {
agg_key = fc::crypto::blslib::aggregate({agg_key, c_finalizers[i].public_key});
}
}
}
std::vector<fc::crypto::blslib::bls_public_key> keys;
keys.reserve(finalizers.size());
for (hs_bitset::size_type i = 0; i < finalizers.size(); ++i)
if (finalizers[i])
keys.push_back(c_finalizers[i].public_key);
fc::crypto::blslib::bls_public_key agg_key = fc::crypto::blslib::aggregate(keys);

digest_type digest = get_digest_to_sign(proposal.block_id, proposal.phase_counter, proposal.final_on_qc);

std::vector<uint8_t> h = std::vector<uint8_t>(digest.data(), digest.data() + 32);

bool ok = fc::crypto::blslib::verify(agg_key, h, agg_sig);

return ok;
}

Expand All @@ -230,7 +214,6 @@ namespace eosio::hotstuff {
}
}


qc_chain::qc_chain(std::string id,
base_pacemaker* pacemaker,
std::set<name> my_producers,
Expand Down
Loading

0 comments on commit 4ffc264

Please sign in to comment.