diff options
author | Determinant <[email protected]> | 2019-05-10 17:36:24 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-05-10 17:36:24 -0400 |
commit | 380f6411fe4889839d470a343ebd50bdf2205531 (patch) | |
tree | 73eea58939bc5b7bd2d15983838a96d64d20397e | |
parent | a32f1af24dbc7e5d3da51d174532eaa923cd4f26 (diff) |
minor changes
-rw-r--r-- | include/hotstuff/consensus.h | 10 | ||||
-rw-r--r-- | include/hotstuff/liveness.h | 12 | ||||
-rw-r--r-- | src/consensus.cpp | 34 |
3 files changed, 30 insertions, 26 deletions
diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h index 2752912..61d9167 100644 --- a/include/hotstuff/consensus.h +++ b/include/hotstuff/consensus.h @@ -38,9 +38,9 @@ class HotStuffCore { block_t b0; /** the genesis block */ /* === state variables === */ /** block containing the QC for the highest block having one */ - std::pair<block_t, quorum_cert_bt> hqc; - block_t block; /**< locked block */ - block_t bexec; /**< last executed block */ + std::pair<block_t, quorum_cert_bt> hqc; /**< highest QC */ + block_t b_lock; /**< locked block */ + block_t b_exec; /**< last executed block */ uint32_t vheight; /**< height of the block last voted for */ /* === auxilliary variables === */ privkey_bt priv_key; /**< private key for signing votes */ @@ -53,7 +53,7 @@ class HotStuffCore { promise_t hqc_update_waiting; /* == feature switches == */ /** always vote negatively, useful for some PaceMakers */ - bool neg_vote; + bool vote_disabled; block_t get_delivered_blk(const uint256_t &blk_hash); void sanity_check_delivered(const block_t &blk); @@ -163,7 +163,7 @@ class HotStuffCore { ReplicaID get_id() const { return id; } const std::set<block_t, BlockHeightCmp> get_tails() const { return tails; } operator std::string () const; - void set_neg_vote(bool _neg_vote) { neg_vote = _neg_vote; } + void set_vote_disabled(bool f) { vote_disabled = f; } }; /** Abstraction for proposal messages. */ diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h index f4027a2..03b375e 100644 --- a/include/hotstuff/liveness.h +++ b/include/hotstuff/liveness.h @@ -404,7 +404,7 @@ class PMStickyProposer: virtual public PaceMaker { role = FOLLOWER; proposer = new_proposer; last_proposed = nullptr; - hsc->set_neg_vote(false); + hsc->set_vote_disabled(false); timer.clear(); /* redirect all pending cmds to the new proposer */ while (!pending_beats.empty()) @@ -421,7 +421,7 @@ class PMStickyProposer: virtual public PaceMaker { role = PROPOSER; proposer = hsc->get_id(); last_proposed = nullptr; - hsc->set_neg_vote(true); + hsc->set_vote_disabled(true); timer = TimerEvent(ec, [this](TimerEvent &) { /* proposer unable to get a QC in time */ to_candidate(); @@ -436,7 +436,7 @@ class PMStickyProposer: virtual public PaceMaker { role = CANDIDATE; proposer = hsc->get_id(); last_proposed = nullptr; - hsc->set_neg_vote(false); + hsc->set_vote_disabled(false); timer = TimerEvent(ec, [this](TimerEvent &) { candidate_qc_timeout(); }); @@ -660,7 +660,7 @@ class PMRoundRobinProposer: virtual public PaceMaker { clear_promises(); role = FOLLOWER; last_proposed = nullptr; - hsc->set_neg_vote(false); + hsc->set_vote_disabled(false); timer.clear(); /* redirect all pending cmds to the new proposer */ while (!pending_beats.empty()) @@ -676,7 +676,7 @@ class PMRoundRobinProposer: virtual public PaceMaker { clear_promises(); role = PROPOSER; last_proposed = nullptr; - hsc->set_neg_vote(true); + hsc->set_vote_disabled(true); timer = TimerEvent(ec, [this](TimerEvent &) { /* proposer unable to get a QC in time */ to_candidate(); @@ -689,7 +689,7 @@ class PMRoundRobinProposer: virtual public PaceMaker { clear_promises(); role = CANDIDATE; last_proposed = nullptr; - hsc->set_neg_vote(false); + hsc->set_vote_disabled(false); timer = TimerEvent(ec, [this](TimerEvent &) { candidate_qc_timeout(); }); diff --git a/src/consensus.cpp b/src/consensus.cpp index e286d9a..5dadbe0 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -33,12 +33,12 @@ namespace hotstuff { HotStuffCore::HotStuffCore(ReplicaID id, privkey_bt &&priv_key): b0(new Block(true, 1)), - block(b0), - bexec(b0), + b_lock(b0), + b_exec(b0), vheight(0), priv_key(std::move(priv_key)), tails{b0}, - neg_vote(false), + vote_disabled(false), id(id), storage(new EntityStorage()) { storage->add_blk(b0); @@ -104,7 +104,7 @@ void HotStuffCore::update(const block_t &nblk) { const block_t &blk1 = blk2->qc_ref; if (blk1 == nullptr) return; if (blk1->decision) return; - if (blk1->height > block->height) block = blk1; + if (blk1->height > b_lock->height) b_lock = blk1; const block_t &blk = blk1->qc_ref; if (blk == nullptr) return; @@ -118,7 +118,7 @@ void HotStuffCore::update(const block_t &nblk) { if (blk1 == nullptr) return; if (blk1->decision) return; update_hqc(blk1, nblk->qc); - if (blk1->height > block->height) block = blk1; + if (blk1->height > b_lock->height) b_lock = blk1; const block_t &blk = blk1->qc_ref; if (blk == nullptr) return; @@ -130,14 +130,14 @@ void HotStuffCore::update(const block_t &nblk) { /* otherwise commit */ std::vector<block_t> commit_queue; block_t b; - for (b = blk; b->height > bexec->height; b = b->parents[0]) + for (b = blk; b->height > b_exec->height; b = b->parents[0]) { /* TODO: also commit the uncles/aunts */ commit_queue.push_back(b); } - if (b != bexec) + if (b != b_exec) throw std::runtime_error("safety breached :( " + std::string(*blk) + " " + - std::string(*bexec)); + std::string(*b_exec)); for (auto it = commit_queue.rbegin(); it != commit_queue.rend(); it++) { const block_t &blk = *it; @@ -147,7 +147,7 @@ void HotStuffCore::update(const block_t &nblk) { do_decide(Finality(id, 1, i, blk->height, blk->cmds[i], blk->get_hash())); } - bexec = blk; + b_exec = blk; } void HotStuffCore::on_propose(const std::vector<uint256_t> &cmds, @@ -199,15 +199,18 @@ void HotStuffCore::on_receive_proposal(const Proposal &prop) { bool opinion = false; if (bnew->height > vheight) { - if (bnew->qc_ref && bnew->qc_ref->height > block->height) + if (bnew->qc_ref && bnew->qc_ref->height > b_lock->height) + { opinion = true; // liveness condition + vheight = bnew->height; + } else { // safety condition (extend the locked branch) block_t b; for (b = bnew; - b->height > block->height; + b->height > b_lock->height; b = b->parents[0]); - if (b == block) /* on the same branch */ + if (b == b_lock) /* on the same branch */ { opinion = true; vheight = bnew->height; @@ -218,7 +221,7 @@ void HotStuffCore::on_receive_proposal(const Proposal &prop) { if (bnew->qc_ref) on_qc_finish(bnew->qc_ref); on_receive_proposal_(prop); - if (opinion && !neg_vote) + if (opinion && !vote_disabled) do_vote(prop.proposer, Vote(id, bnew->get_hash(), create_part_cert(*priv_key, bnew->get_hash()), this)); @@ -263,7 +266,7 @@ void HotStuffCore::on_init(uint32_t nfaulty) { void HotStuffCore::prune(uint32_t staleness) { block_t start; /* skip the blocks */ - for (start = bexec; staleness; staleness--, start = start->parents[0]) + for (start = b_exec; staleness; staleness--, start = start->parents[0]) if (!start->parents.size()) return; std::stack<block_t> s; start->qc_ref = nullptr; @@ -351,7 +354,8 @@ HotStuffCore::operator std::string () const { s << "<hotstuff " << "hqc=" << get_hex10(hqc.first->get_hash()) << " " << "hqc.height=" << std::to_string(hqc.first->height) << " " - << "bexec=" << get_hex10(bexec->get_hash()) << " " + << "b_lock=" << get_hex10(b_lock->get_hash()) << " " + << "b_exec=" << get_hex10(b_exec->get_hash()) << " " << "vheight=" << std::to_string(vheight) << " " << "tails=" << std::to_string(tails.size()) << ">"; return std::move(s); |