From 3c355d7f9e7b491b9fc5af4516286ab4100238c6 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 19 Jul 2018 17:51:15 -0400 Subject: ... --- src/hotstuff.cpp | 52 +++++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) (limited to 'src/hotstuff.cpp') diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index a37e872..687e21d 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -72,12 +72,13 @@ void MsgHotStuff::parse_rfetchblk(std::vector &blks, HotStuffCore *hsc) } 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](promise_t &pm) { - pm.resolve(Finality(proposer, -1, - cmd->get_hash(), uint256_t())); + return promise_t([proposer, cmd_hash](promise_t &pm) { + pm.resolve(Finality(proposer, -1, 0, 0, + cmd_hash, uint256_t())); }); cmd_pending.push(storage->add_cmd(cmd)); if (cmd_pending.size() >= blk_size) @@ -92,13 +93,13 @@ promise_t HotStuffBase::exec_command(command_t cmd) { on_propose(cmds, pmaker->get_parents()); }); } - return async_decide(cmd->get_hash()).then([this](const command_t &cmd) { - block_t blk = cmd->get_container(); - return Finality(get_id(), - cmd->get_decision(), - cmd->get_hash(), - blk->get_hash()); - }); + auto it = decision_waiting.find(cmd_hash); + if (it == decision_waiting.end()) + { + promise_t pm{[](promise_t){}}; + it = decision_waiting.insert(std::make_pair(cmd_hash, pm)).first; + } + return it->second; } void HotStuffBase::add_replica(ReplicaID idx, const NetAddr &addr, @@ -380,21 +381,6 @@ void HotStuffBase::print_stat() const { #endif } -promise_t HotStuffBase::async_decide(const uint256_t &cmd_hash) { - if (get_cmd_decision(cmd_hash)) - return promise_t([this, cmd_hash](promise_t pm){ - pm.resolve(storage->find_cmd(cmd_hash)); - }); - /* otherwise the do_decide will resolve the promise */ - auto it = decision_waiting.find(cmd_hash); - if (it == decision_waiting.end()) - { - promise_t pm{[](promise_t){}}; - it = decision_waiting.insert(std::make_pair(cmd_hash, pm)).first; - } - return it->second; -} - HotStuffBase::HotStuffBase(uint32_t blk_size, ReplicaID rid, privkey_bt &&priv_key, @@ -448,20 +434,12 @@ void HotStuffBase::do_vote(ReplicaID last_proposer, const Vote &vote) { }); } -void HotStuffBase::do_decide(const command_t &cmd) { - auto it = decision_waiting.find(cmd->get_hash()); - if (it != decision_waiting.end()) - { - it->second.resolve(cmd); - decision_waiting.erase(it); - } -} - -void HotStuffBase::do_forward(const uint256_t &cmd_hash, ReplicaID rid) { - auto it = decision_waiting.find(cmd_hash); +void HotStuffBase::do_decide(Finality &&fin) { + state_machine_execute(fin); + auto it = decision_waiting.find(fin.cmd_hash); if (it != decision_waiting.end()) { - it->second.reject(rid); + it->second.resolve(std::move(fin)); decision_waiting.erase(it); } } -- cgit v1.2.3