diff options
author | Determinant <[email protected]> | 2018-08-03 13:55:31 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2018-08-03 13:55:31 -0400 |
commit | 7d5b607f5e4efc4ab12a5cce49bd8198d8d03fe6 (patch) | |
tree | ea94ebd41c562ccf6bd1fc5154c0410e0ac1c99b /src | |
parent | 4c42ac64c2ff821306609898a58126f2da32c7d4 (diff) |
finish coding PMStickyProposer
Diffstat (limited to 'src')
-rw-r--r-- | src/consensus.cpp | 1 | ||||
-rw-r--r-- | src/hotstuff.cpp | 37 | ||||
-rw-r--r-- | src/hotstuff_app.cpp | 2 |
3 files changed, 25 insertions, 15 deletions
diff --git a/src/consensus.cpp b/src/consensus.cpp index 40a5e44..2cac22c 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -64,7 +64,6 @@ bool HotStuffCore::on_deliver_blk(const block_t &blk) { blk->delivered = true; LOG_DEBUG("deliver %s", std::string(*blk).c_str()); - on_deliver_blk_(blk); return true; } diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index 9a56626..2bde97e 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -66,7 +66,15 @@ promise_t HotStuffBase::exec_command(command_t cmd) { pm.resolve(Finality(proposer, -1, 0, 0, cmd_hash, uint256_t())); }); - cmd_pending.push(storage->add_cmd(cmd)); + + + auto it = decision_waiting.find(cmd_hash); + if (it == decision_waiting.end()) + { + cmd_pending.push(storage->add_cmd(cmd)); + it = decision_waiting.insert(std::make_pair(cmd_hash, promise_t())).first; + } + if (cmd_pending.size() >= blk_size) { std::vector<command_t> cmds; @@ -75,16 +83,19 @@ promise_t HotStuffBase::exec_command(command_t cmd) { cmds.push_back(cmd_pending.front()); cmd_pending.pop(); } - pmaker->beat().then([this, cmds = std::move(cmds)]() { - on_propose(cmds, pmaker->get_parents()); + pmaker->beat().then([this, cmds = std::move(cmds)](ReplicaID proposer) { + 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())); + } + else + on_propose(cmds, pmaker->get_parents()); }); } - 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; } @@ -385,10 +396,10 @@ HotStuffBase::HotStuffBase(uint32_t blk_size, part_delivery_time_max(0) { /* register the handlers for msg from replicas */ - pn.reg_handler(salticidae::handler_bind(&HotStuffBase::propose_handler, this, _1, _2)); - pn.reg_handler(salticidae::handler_bind(&HotStuffBase::vote_handler, this, _1, _2)); - pn.reg_handler(salticidae::handler_bind(&HotStuffBase::req_blk_handler, this, _1, _2)); - pn.reg_handler(salticidae::handler_bind(&HotStuffBase::resp_blk_handler, this, _1, _2)); + pn.reg_handler(salticidae::generic_bind(&HotStuffBase::propose_handler, this, _1, _2)); + pn.reg_handler(salticidae::generic_bind(&HotStuffBase::vote_handler, this, _1, _2)); + pn.reg_handler(salticidae::generic_bind(&HotStuffBase::req_blk_handler, this, _1, _2)); + pn.reg_handler(salticidae::generic_bind(&HotStuffBase::resp_blk_handler, this, _1, _2)); pn.listen(listen_addr); } diff --git a/src/hotstuff_app.cpp b/src/hotstuff_app.cpp index 9a6e5fd..f7270f2 100644 --- a/src/hotstuff_app.cpp +++ b/src/hotstuff_app.cpp @@ -211,7 +211,7 @@ HotStuffApp::HotStuffApp(uint32_t blk_size, clisten_addr(clisten_addr), parent_limit(parent_limit) { /* register the handlers for msg from clients */ - cn.reg_handler(salticidae::handler_bind(&HotStuffApp::client_request_cmd_handler, this, _1, _2)); + cn.reg_handler(salticidae::generic_bind(&HotStuffApp::client_request_cmd_handler, this, _1, _2)); cn.listen(clisten_addr); } |