aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/hotstuff/consensus.h3
-rw-r--r--include/hotstuff/liveness.h18
-rw-r--r--src/consensus.cpp3
3 files changed, 16 insertions, 8 deletions
diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h
index d27f8c5..65ffff2 100644
--- a/include/hotstuff/consensus.h
+++ b/include/hotstuff/consensus.h
@@ -139,7 +139,8 @@ class HotStuffCore {
promise_t async_bqc_update();
/* Other useful functions */
- block_t get_genesis() { return b0; }
+ const block_t &get_genesis() { return b0; }
+ const block_t &get_bqc() { return bqc; }
const ReplicaConfig &get_config() { return config; }
ReplicaID get_id() const { return id; }
const std::set<block_t, BlockHeightCmp> get_tails() const { return tails; }
diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h
index 6396fe3..59306ab 100644
--- a/include/hotstuff/liveness.h
+++ b/include/hotstuff/liveness.h
@@ -46,13 +46,14 @@ class PMAllParents: public virtual PaceMaker {
void reg_bqc_update() {
hsc->async_bqc_update().then([this](const block_t &bqc) {
+ const auto &pref = bqc->get_qc_ref();
for (const auto &blk: hsc->get_tails())
{
block_t b;
for (b = blk;
- b->get_height() > bqc->get_height();
+ b->get_height() > pref->get_height();
b = b->get_parents()[0]);
- if (b == bqc && blk->get_height() > bqc_tail->get_height())
+ if (b == pref && blk->get_height() > bqc_tail->get_height())
bqc_tail = blk;
}
reg_bqc_update();
@@ -61,16 +62,21 @@ class PMAllParents: public virtual PaceMaker {
void reg_proposal() {
hsc->async_wait_proposal().then([this](const Proposal &prop) {
- if (prop.blk->get_parents()[0] == bqc_tail)
- bqc_tail = prop.blk;
+ bqc_tail = prop.blk;
reg_proposal();
});
}
void reg_receive_proposal() {
hsc->async_wait_receive_proposal().then([this](const Proposal &prop) {
- if (prop.blk->get_parents()[0] == bqc_tail)
- bqc_tail = prop.blk;
+ const auto &pref = hsc->get_bqc()->get_qc_ref();
+ const auto &blk = prop.blk;
+ block_t b;
+ for (b = blk;
+ b->get_height() > pref->get_height();
+ b = b->get_parents()[0]);
+ if (b == pref && blk->get_height() > bqc_tail->get_height())
+ bqc_tail = blk;
reg_receive_proposal();
});
}
diff --git a/src/consensus.cpp b/src/consensus.cpp
index 1c02585..d19d790 100644
--- a/src/consensus.cpp
+++ b/src/consensus.cpp
@@ -145,7 +145,8 @@ void HotStuffCore::on_propose(const std::vector<command_t> &cmds,
Proposal prop(id, bqc->get_hash(), bnew, nullptr);
LOG_PROTO("propose %s", std::string(*bnew).c_str());
/* self-vote */
- assert(bnew->height > vheight);
+ if (bnew->height <= vheight)
+ throw std::runtime_error("new block should be higher than vheight");
vheight = bnew->height;
on_receive_vote(
Vote(id, bqc->get_hash(), bnew_hash,