diff options
author | Determinant <[email protected]> | 2019-07-06 22:36:51 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-07-06 22:36:51 -0400 |
commit | b5d5e8375373eaed6a5544860336a74bbd96446d (patch) | |
tree | bc37729f46e0c60804861ae9eb390697fdf1db43 | |
parent | 7a52e54b14eed096acce1c224ab46626f7c8cbaf (diff) |
improve RR Pacemaker
-rw-r--r-- | include/hotstuff/liveness.h | 19 | ||||
-rw-r--r-- | src/consensus.cpp | 15 | ||||
-rw-r--r-- | src/hotstuff_client.cpp | 12 |
3 files changed, 14 insertions, 32 deletions
diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h index a2705d1..b0373ed 100644 --- a/include/hotstuff/liveness.h +++ b/include/hotstuff/liveness.h @@ -244,6 +244,7 @@ class PMRoundRobinProposer: virtual public PaceMaker { bool locked; promise_t pm_qc_finish; promise_t pm_wait_propose; + promise_t pm_qc_manual; void reg_proposal() { hsc->async_wait_proposal().then([this](const Proposal &prop) { @@ -287,24 +288,24 @@ class PMRoundRobinProposer: virtual public PaceMaker { }); } - void do_new_consensus(int x) { - auto dummy = hsc->on_propose(std::vector<uint256_t>{}, get_parents(), bytearray_t()); - pm_qc_finish.reject(); - (pm_qc_finish = hsc->async_qc_finish(dummy)) + void do_new_consensus(int x, const std::vector<uint256_t> &cmds) { + auto blk = hsc->on_propose(cmds, get_parents(), bytearray_t()); + pm_qc_manual.reject(); + (pm_qc_manual = hsc->async_qc_finish(blk)) .then([this, x]() { + HOTSTUFF_LOG_PROTO("Pacemaker: got QC for block %d", x); #ifdef HOTSTUFF_TWO_STEP if (x >= 2) return; #else if (x >= 3) return; #endif - HOTSTUFF_LOG_PROTO("Pacemaker: got QC for dummy block %d", x); - do_new_consensus(x + 1); + do_new_consensus(x + 1, std::vector<uint256_t>{}); }); } void on_exp_timeout(TimerEvent &) { if (proposer == hsc->get_id()) - do_new_consensus(0); + do_new_consensus(0, std::vector<uint256_t>{}); timer = TimerEvent(ec, [this](TimerEvent &){ rotate(); }); timer.add(prop_delay); } @@ -320,6 +321,7 @@ class PMRoundRobinProposer: virtual public PaceMaker { HOTSTUFF_LOG_PROTO("Pacemaker: rotate to %d", proposer); pm_qc_finish.reject(); pm_wait_propose.reject(); + pm_qc_manual.reject(); // start timer timer = TimerEvent(ec, salticidae::generic_bind(&PMRoundRobinProposer::on_exp_timeout, this, _1)); timer.add(exp_timeout); @@ -331,6 +333,7 @@ class PMRoundRobinProposer: virtual public PaceMaker { HOTSTUFF_LOG_PROTO("Pacemaker: stop rotation at %d", proposer); pm_qc_finish.reject(); pm_wait_propose.reject(); + pm_qc_manual.reject(); rotating = false; locked = false; last_proposed = hsc->get_genesis(); @@ -346,7 +349,7 @@ class PMRoundRobinProposer: virtual public PaceMaker { std::vector<uint256_t> cmds; for (auto &p: pending) cmds.push_back(p.first); - hs->on_propose(cmds, get_parents()); + do_new_consensus(0, cmds); }); } } diff --git a/src/consensus.cpp b/src/consensus.cpp index 70c1876..d9c1f64 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -157,21 +157,12 @@ block_t HotStuffCore::on_propose(const std::vector<uint256_t> &cmds, if (parents.empty()) throw std::runtime_error("empty parents"); for (const auto &_: parents) tails.erase(_); - block_t p = parents[0]; - quorum_cert_bt qc = nullptr; - block_t qc_ref = nullptr; - /* a block can optionally carray a QC */ - if (p->voted.size() >= config.nmajority) - { - qc = p->self_qc->clone(); - qc_ref = p; - } /* create the new block */ block_t bnew = storage->add_blk( new Block(parents, cmds, - std::move(qc), std::move(extra), - p->height + 1, - qc_ref, + hqc.second->clone(), std::move(extra), + parents[0]->height + 1, + hqc.first, nullptr )); const uint256_t bnew_hash = bnew->get_hash(); diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index 7914125..831b7ff 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -108,18 +108,9 @@ void client_resp_cmd_handler(MsgRespCmd &&msg, const Net::conn_t &) { elapsed.push_back(std::make_pair(tv, et.elapsed_sec)); #endif waiting.erase(it); -#ifndef HOTSTUFF_AUTOCLI while (try_send()); -#endif } -//#ifdef HOTSTUFF_AUTOCLI -//void client_demand_cmd_handler(hotstuff::MsgDemandCmd &&msg, const Net::conn_t &) { -// for (size_t i = 0; i < msg.ncmd; i++) -// try_send(false); -//} -//#endif - std::pair<std::string, std::string> split_ip_port_cport(const std::string &s) { auto ret = salticidae::trim_all(salticidae::split(s, ";")); return std::make_pair(ret[0], ret[1]); @@ -141,9 +132,6 @@ int main(int argc, char **argv) { ev_sigterm.add(SIGTERM); mn.reg_handler(client_resp_cmd_handler); -//#ifdef HOTSTUFF_AUTOCLI -// mn.reg_handler(client_demand_cmd_handler); -//#endif mn.start(); config.add_opt("idx", opt_idx, Config::SET_VAL); |