aboutsummaryrefslogtreecommitdiff
path: root/src/consensus.cpp
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2018-08-16 15:57:06 -0400
committerDeterminant <[email protected]>2018-08-16 15:57:06 -0400
commita5f0a7198334caf95bff0bf1c6c5a2c30eb32795 (patch)
treeb3d7ce958ddec7fc05fcf0f703eadd5dea40d719 /src/consensus.cpp
parenta95e4362fa197b44138616c8e1c8a05d192b0a82 (diff)
fix bugs in PaceMaker
Diffstat (limited to 'src/consensus.cpp')
-rw-r--r--src/consensus.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/consensus.cpp b/src/consensus.cpp
index 66ce05c..c9ceb9b 100644
--- a/src/consensus.cpp
+++ b/src/consensus.cpp
@@ -21,6 +21,7 @@ HotStuffCore::HotStuffCore(ReplicaID id,
vheight(0),
priv_key(std::move(priv_key)),
tails{bqc},
+ neg_vote(false),
id(id),
storage(new EntityStorage()) {
storage->add_blk(b0);
@@ -103,7 +104,10 @@ bool HotStuffCore::update(const uint256_t &bqc_hash) {
if (_bqc->qc_ref == nullptr) return false;
check_commit(_bqc);
if (_bqc->qc_ref->height > bqc->qc_ref->height)
+ {
bqc = _bqc;
+ on_bqc_update();
+ }
return true;
}
@@ -141,7 +145,7 @@ void HotStuffCore::on_propose(const std::vector<command_t> &cmds,
on_receive_vote(
Vote(id, bqc->get_hash(), bnew_hash,
create_part_cert(*priv_key, bnew_hash), this));
- on_propose_(bnew);
+ on_propose_(prop);
/* boradcast to other replicas */
do_broadcast_proposal(prop);
}
@@ -173,7 +177,7 @@ void HotStuffCore::on_receive_proposal(const Proposal &prop) {
Vote(id,
bqc->get_hash(),
bnew->get_hash(),
- (opinion ?
+ ((opinion && !neg_vote) ?
create_part_cert(*priv_key, bnew->get_hash()) :
nullptr),
this));
@@ -262,9 +266,9 @@ void HotStuffCore::on_qc_finish(const block_t &blk) {
}
}
-promise_t HotStuffCore::async_wait_propose() {
- return propose_waiting.then([](const block_t &blk) {
- return blk;
+promise_t HotStuffCore::async_wait_proposal() {
+ return propose_waiting.then([](const Proposal &prop) {
+ return prop;
});
}
@@ -274,10 +278,16 @@ promise_t HotStuffCore::async_wait_receive_proposal() {
});
}
-void HotStuffCore::on_propose_(const block_t &blk) {
+promise_t HotStuffCore::async_bqc_update() {
+ return bqc_update_waiting.then([bqc=this->bqc]() {
+ return bqc;
+ });
+}
+
+void HotStuffCore::on_propose_(const Proposal &prop) {
auto t = std::move(propose_waiting);
propose_waiting = promise_t();
- t.resolve(blk);
+ t.resolve(prop);
}
void HotStuffCore::on_receive_proposal_(const Proposal &prop) {
@@ -286,6 +296,12 @@ void HotStuffCore::on_receive_proposal_(const Proposal &prop) {
t.resolve(prop);
}
+void HotStuffCore::on_bqc_update() {
+ auto t = std::move(bqc_update_waiting);
+ bqc_update_waiting = promise_t();
+ t.resolve();
+}
+
HotStuffCore::operator std::string () const {
DataStream s;
s << "<hotstuff "