aboutsummaryrefslogtreecommitdiff
path: root/src/hotstuff.cpp
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2018-08-03 13:55:31 -0400
committerDeterminant <tederminant@gmail.com>2018-08-03 13:55:31 -0400
commit7d5b607f5e4efc4ab12a5cce49bd8198d8d03fe6 (patch)
treeea94ebd41c562ccf6bd1fc5154c0410e0ac1c99b /src/hotstuff.cpp
parent4c42ac64c2ff821306609898a58126f2da32c7d4 (diff)
finish coding PMStickyProposer
Diffstat (limited to 'src/hotstuff.cpp')
-rw-r--r--src/hotstuff.cpp37
1 files changed, 24 insertions, 13 deletions
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);
}