Skip to content

Commit

Permalink
Merged hotstuff_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
systemzax committed Sep 25, 2023
2 parents 4ffc264 + 5d4fb21 commit bfa240b
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 80 deletions.
37 changes: 28 additions & 9 deletions libraries/hotstuff/include/eosio/hotstuff/test_pacemaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ namespace eosio { namespace hotstuff {
class test_pacemaker : public base_pacemaker {
public:

using hotstuff_message = std::pair<std::string, std::variant<hs_proposal_message, hs_vote_message, hs_new_block_message, hs_new_view_message>>;

enum hotstuff_message_index {
hs_proposal = 0,
hs_vote = 1,
hs_new_block = 2,
hs_new_view = 3,
hs_all_messages
};

//class-specific functions

bool is_qc_chain_active(const name& qcc_name) { return _qcc_deactivated.find(qcc_name) == _qcc_deactivated.end(); }

using hotstuff_message = std::pair<std::string, std::variant<hs_proposal_message, hs_vote_message, hs_new_block_message, hs_new_view_message>>;

void set_proposer(name proposer);

void set_leader(name leader);
Expand All @@ -27,13 +35,21 @@ namespace eosio { namespace hotstuff {

void set_quorum_threshold(uint32_t threshold);

void add_message_to_queue(hotstuff_message msg);
void add_message_to_queue(const hotstuff_message& msg);

void connect(const std::vector<std::string>& nodes);

void disconnect(const std::vector<std::string>& nodes);

void pipe(std::vector<test_pacemaker::hotstuff_message> messages);
bool is_connected(std::string node1, std::string node2);

void dispatch(std::string memo, int count);
void pipe(const std::vector<test_pacemaker::hotstuff_message>& messages);

std::vector<hotstuff_message> dispatch(std::string memo);
void duplicate(hotstuff_message_index msg_type);

void dispatch(std::string memo, int count, hotstuff_message_index msg_type = hs_all_messages);

std::vector<hotstuff_message> dispatch(std::string memo, hotstuff_message_index msg_type = hs_all_messages);

void activate(name replica);
void deactivate(name replica);
Expand Down Expand Up @@ -66,6 +82,8 @@ namespace eosio { namespace hotstuff {

void send_hs_message_warning(const uint32_t sender_peer, const chain::hs_message_warning code);

private:

std::vector<hotstuff_message> _pending_message_queue;

// qc_chain id to qc_chain object
Expand All @@ -74,9 +92,10 @@ namespace eosio { namespace hotstuff {
// qc_chain ids in this set are currently deactivated
set<name> _qcc_deactivated;

private:

std::vector<hotstuff_message> _message_queue;
// network topology: key (node name) is connected to all nodes in the mapped set.
// double mapping, so if _net[a] yields b, then _net[b] yields a.
// this is a filter; messages to self won't happen even if _net[x] yields x.
map<std::string, std::set<std::string>> _net;

name _proposer;
name _leader;
Expand Down
9 changes: 9 additions & 0 deletions libraries/hotstuff/qc_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ namespace eosio::hotstuff {
auto increment_version = fc::make_scoped_exit([this]() { ++_state_version; });

const hs_bitset& finalizer_set = _current_qc.get_active_finalizers();

// if a finalizer has already aggregated a vote signature for the current QC, just discard this vote

const auto& finalizers = _pacemaker->get_finalizer_set().finalizers;
for (size_t i=0; i<finalizers.size(); ++i)
if (finalizers[i].public_key == vote.finalizer_key)
if (finalizer_set.test(i))
return;

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
Loading

0 comments on commit bfa240b

Please sign in to comment.