From e41eef9d19fe3a3ab9b158c985b180a3f76f93f7 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 7 Aug 2018 20:41:53 -0400 Subject: fix bugs --- src/consensus.cpp | 26 +++++++++----------------- src/hotstuff.cpp | 20 +++++++++++++------- 2 files changed, 22 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/consensus.cpp b/src/consensus.cpp index 58c0f31..66ce05c 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -7,6 +7,7 @@ #define LOG_INFO HOTSTUFF_LOG_INFO #define LOG_DEBUG HOTSTUFF_LOG_DEBUG #define LOG_WARN HOTSTUFF_LOG_WARN +#define LOG_PROTO HOTSTUFF_LOG_PROTO namespace hotstuff { @@ -88,9 +89,7 @@ void HotStuffCore::check_commit(const block_t &_blk) { { const block_t &blk = *it; blk->decision = 1; -#ifdef HOTSTUFF_PROTO_LOG - LOG_INFO("commit %s", std::string(*blk).c_str()); -#endif + LOG_PROTO("commit %s", std::string(*blk).c_str()); size_t idx = 0; for (auto cmd: blk->cmds) do_decide(Finality(id, 1, idx, blk->height, @@ -137,9 +136,7 @@ void HotStuffCore::on_propose(const std::vector &cmds, on_deliver_blk(bnew); update(bnew_hash); Proposal prop(id, bqc->get_hash(), bnew, nullptr); -#ifdef HOTSTUFF_PROTO_LOG - LOG_INFO("propose %s", std::string(*bnew).c_str()); -#endif + LOG_PROTO("propose %s", std::string(*bnew).c_str()); /* self-vote */ on_receive_vote( Vote(id, bqc->get_hash(), bnew_hash, @@ -151,9 +148,7 @@ void HotStuffCore::on_propose(const std::vector &cmds, void HotStuffCore::on_receive_proposal(const Proposal &prop) { if (!update(prop.bqc_hash)) return; -#ifdef HOTSTUFF_PROTO_LOG - LOG_INFO("got %s", std::string(prop).c_str()); -#endif + LOG_PROTO("got %s", std::string(prop).c_str()); block_t bnew = prop.blk; sanity_check_delivered(bnew); bool opinion = false; @@ -170,10 +165,9 @@ void HotStuffCore::on_receive_proposal(const Proposal &prop) { vheight = bnew->height; } } -#ifdef HOTSTUFF_PROTO_LOG - LOG_INFO("now state: %s", std::string(*this).c_str()); -#endif - if (bnew->qc_ref) on_qc_finish(bnew->qc_ref); + LOG_PROTO("now state: %s", std::string(*this).c_str()); + if (bnew->qc_ref) + on_qc_finish(bnew->qc_ref); on_receive_proposal_(prop); do_vote(prop.proposer, Vote(id, @@ -187,10 +181,8 @@ void HotStuffCore::on_receive_proposal(const Proposal &prop) { void HotStuffCore::on_receive_vote(const Vote &vote) { if (!update(vote.bqc_hash)) return; -#ifdef HOTSTUFF_PROTO_LOG - LOG_INFO("got %s", std::string(vote).c_str()); - LOG_INFO("now state: %s", std::string(*this).c_str()); -#endif + LOG_PROTO("got %s", std::string(vote).c_str()); + LOG_PROTO("now state: %s", std::string(*this).c_str()); block_t blk = get_delivered_blk(vote.blk_hash); if (vote.cert == nullptr) return; /* otherwise the vote is positive */ diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index 04b31f8..3626f9d 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -57,17 +57,17 @@ void MsgRespBlock::postponed_parse(HotStuffCore *hsc) { } } +// TODO: improve this function promise_t HotStuffBase::exec_command(command_t cmd) { const uint256_t &cmd_hash = cmd->get_hash(); ReplicaID proposer = pmaker->get_proposer(); - /* not the proposer */ + if (proposer != get_id()) return promise_t([proposer, cmd_hash](promise_t &pm) { pm.resolve(Finality(proposer, -1, 0, 0, cmd_hash, uint256_t())); }); - auto it = decision_waiting.find(cmd_hash); if (it == decision_waiting.end()) { @@ -87,10 +87,16 @@ promise_t HotStuffBase::exec_command(command_t cmd) { if (proposer != get_id()) { for (auto &cmd: cmds) - decision_waiting - .at(cmd->get_hash()) - .resolve(Finality(proposer, -1, 0, 0, - cmd->get_hash(), uint256_t())); + { + const auto &cmd_hash = cmd->get_hash(); + auto it = decision_waiting.find(cmd_hash); + if (it != decision_waiting.end()) + { + it->second.resolve(Finality(proposer, -1, 0, 0, + cmd_hash, uint256_t())); + decision_waiting.erase(it); + } + } } else on_propose(cmds, pmaker->get_parents()); @@ -437,8 +443,8 @@ void HotStuffBase::start(bool eb_loop) { uint32_t nfaulty = pn.all_peers().size() / 3; if (nfaulty == 0) LOG_WARN("too few replicas in the system to tolerate any failure"); - pmaker->init(this); on_init(nfaulty); + pmaker->init(this); if (eb_loop) eb.dispatch(); } -- cgit v1.2.3