aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2019-04-07 16:10:23 -0400
committerDeterminant <ted.sybil@gmail.com>2019-04-07 16:10:23 -0400
commit2757995cb91dd02ebd6ede693cc6c02c4e359afe (patch)
treed5d3acfe2bae5907c2d949358acfc9659604495b /include
parent49225da30a16a81f5e07c499af88c95da68b45b1 (diff)
clean up consensus code
Diffstat (limited to 'include')
-rw-r--r--include/hotstuff/consensus.h53
-rw-r--r--include/hotstuff/liveness.h36
2 files changed, 32 insertions, 57 deletions
diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h
index 5f781c5..a59c02f 100644
--- a/include/hotstuff/consensus.h
+++ b/include/hotstuff/consensus.h
@@ -38,7 +38,7 @@ class HotStuffCore {
block_t b0; /** the genesis block */
/* === state variables === */
/** block containing the QC for the highest block having one */
- block_t bqc;
+ std::pair<block_t, quorum_cert_bt> hqc;
block_t bexec; /**< last executed block */
uint32_t vheight; /**< height of the block last voted for */
/* === auxilliary variables === */
@@ -49,16 +49,16 @@ class HotStuffCore {
std::unordered_map<block_t, promise_t> qc_waiting;
promise_t propose_waiting;
promise_t receive_proposal_waiting;
- promise_t bqc_update_waiting;
+ promise_t hqc_update_waiting;
/* == feature switches == */
/** always vote negatively, useful for some PaceMakers */
bool neg_vote;
block_t get_delivered_blk(const uint256_t &blk_hash);
void sanity_check_delivered(const block_t &blk);
- void check_commit(const block_t &_bqc);
- bool update(const uint256_t &bqc_hash);
- void on_bqc_update();
+ void update(const block_t &nblk);
+ void update_hqc(const block_t &_hqc, const quorum_cert_bt &qc);
+ void on_hqc_update();
void on_qc_finish(const block_t &blk);
void on_propose_(const Proposal &prop);
void on_receive_proposal_(const Proposal &prop);
@@ -152,12 +152,12 @@ class HotStuffCore {
promise_t async_wait_proposal();
/** Get a promise resolved when a new proposal is received. */
promise_t async_wait_receive_proposal();
- /** Get a promise resolved when bqc is updated. */
- promise_t async_bqc_update();
+ /** Get a promise resolved when hqc is updated. */
+ promise_t async_hqc_update();
/* Other useful functions */
const block_t &get_genesis() { return b0; }
- const block_t &get_bqc() { return bqc; }
+ const block_t &get_hqc() { return hqc.first; }
const ReplicaConfig &get_config() { return config; }
ReplicaID get_id() const { return id; }
const std::set<block_t, BlockHeightCmp> get_tails() const { return tails; }
@@ -168,34 +168,27 @@ class HotStuffCore {
/** Abstraction for proposal messages. */
struct Proposal: public Serializable {
ReplicaID proposer;
- /** hash for the block containing the highest QC */
- uint256_t bqc_hash;
/** block being proposed */
block_t blk;
-
/** handle of the core object to allow polymorphism. The user should use
* a pointer to the object of the class derived from HotStuffCore */
HotStuffCore *hsc;
Proposal(): blk(nullptr), hsc(nullptr) {}
Proposal(ReplicaID proposer,
- const uint256_t &bqc_hash,
const block_t &blk,
HotStuffCore *hsc):
proposer(proposer),
- bqc_hash(bqc_hash),
blk(blk), hsc(hsc) {}
void serialize(DataStream &s) const override {
s << proposer
- << bqc_hash
<< *blk;
}
void unserialize(DataStream &s) override {
assert(hsc != nullptr);
- s >> proposer
- >> bqc_hash;
+ s >> proposer;
Block _blk;
_blk.unserialize(s, hsc);
blk = hsc->storage->add_blk(std::move(_blk), hsc->get_config());
@@ -205,7 +198,6 @@ struct Proposal: public Serializable {
DataStream s;
s << "<proposal "
<< "rid=" << std::to_string(proposer) << " "
- << "bqc=" << get_hex10(bqc_hash) << " "
<< "blk=" << get_hex10(blk->get_hash()) << ">";
return std::move(s);
}
@@ -214,11 +206,9 @@ struct Proposal: public Serializable {
/** Abstraction for vote messages. */
struct Vote: public Serializable {
ReplicaID voter;
- /** hash for the block containing the highest QC */
- uint256_t bqc_hash;
/** block being voted */
uint256_t blk_hash;
- /** proof of validity for the vote (nullptr for a negative vote) */
+ /** proof of validity for the vote */
part_cert_bt cert;
/** handle of the core object to allow polymorphism */
@@ -226,18 +216,15 @@ struct Vote: public Serializable {
Vote(): cert(nullptr), hsc(nullptr) {}
Vote(ReplicaID voter,
- const uint256_t &bqc_hash,
const uint256_t &blk_hash,
part_cert_bt &&cert,
HotStuffCore *hsc):
voter(voter),
- bqc_hash(bqc_hash),
blk_hash(blk_hash),
cert(std::move(cert)), hsc(hsc) {}
Vote(const Vote &other):
voter(other.voter),
- bqc_hash(other.bqc_hash),
blk_hash(other.blk_hash),
cert(other.cert ? other.cert->clone() : nullptr),
hsc(other.hsc) {}
@@ -245,23 +232,13 @@ struct Vote: public Serializable {
Vote(Vote &&other) = default;
void serialize(DataStream &s) const override {
- s << voter
- << bqc_hash
- << blk_hash;
- if (cert == nullptr)
- s << (uint8_t)0;
- else
- s << (uint8_t)1 << *cert;
+ s << voter << blk_hash << *cert;
}
void unserialize(DataStream &s) override {
assert(hsc != nullptr);
- uint8_t has_cert;
- s >> voter
- >> bqc_hash
- >> blk_hash
- >> has_cert;
- cert = has_cert ? hsc->parse_part_cert(s) : nullptr;
+ s >> voter >> blk_hash;
+ cert = hsc->parse_part_cert(s);
}
bool verify() const {
@@ -281,9 +258,7 @@ struct Vote: public Serializable {
DataStream s;
s << "<vote "
<< "rid=" << std::to_string(voter) << " "
- << "bqc=" << get_hex10(bqc_hash) << " "
- << "blk=" << get_hex10(blk_hash) << " "
- << "cert=" << (cert ? "yes" : "no") << ">";
+ << "blk=" << get_hex10(blk_hash) << ">";
return std::move(s);
}
};
diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h
index 903ac83..6d3c3cf 100644
--- a/include/hotstuff/liveness.h
+++ b/include/hotstuff/liveness.h
@@ -60,42 +60,42 @@ using pacemaker_bt = BoxObj<PaceMaker>;
* direct parent, while including other tail blocks (up to parent_limit) as
* uncles/aunts. */
class PMAllParents: public virtual PaceMaker {
- block_t bqc_tail;
+ block_t hqc_tail;
const int32_t parent_limit; /**< maximum number of parents */
- void reg_bqc_update() {
- hsc->async_bqc_update().then([this](const block_t &bqc) {
- const auto &pref = bqc->get_qc_ref();
+ void reg_hqc_update() {
+ hsc->async_hqc_update().then([this](const block_t &hqc) {
+ const auto &pref = hqc;
for (const auto &blk: hsc->get_tails())
{
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;
+ if (b == pref && blk->get_height() > hqc_tail->get_height())
+ hqc_tail = blk;
}
- reg_bqc_update();
+ reg_hqc_update();
});
}
void reg_proposal() {
hsc->async_wait_proposal().then([this](const Proposal &prop) {
- bqc_tail = prop.blk;
+ hqc_tail = prop.blk;
reg_proposal();
});
}
void reg_receive_proposal() {
hsc->async_wait_receive_proposal().then([this](const Proposal &prop) {
- const auto &pref = hsc->get_bqc()->get_qc_ref();
+ const auto &pref = hsc->get_hqc();
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;
+ if (b == pref && blk->get_height() > hqc_tail->get_height())
+ hqc_tail = blk;
reg_receive_proposal();
});
}
@@ -103,15 +103,15 @@ class PMAllParents: public virtual PaceMaker {
public:
PMAllParents(int32_t parent_limit): parent_limit(parent_limit) {}
void init() {
- bqc_tail = hsc->get_genesis();
- reg_bqc_update();
+ hqc_tail = hsc->get_genesis();
+ reg_hqc_update();
reg_proposal();
reg_receive_proposal();
}
std::vector<block_t> get_parents() override {
const auto &tails = hsc->get_tails();
- std::vector<block_t> parents{bqc_tail};
+ std::vector<block_t> parents{hqc_tail};
auto nparents = tails.size();
if (parent_limit > 0)
nparents = std::min(nparents, (size_t)parent_limit);
@@ -119,7 +119,7 @@ class PMAllParents: public virtual PaceMaker {
/* add the rest of tails as "uncles/aunts" */
for (const auto &blk: tails)
{
- if (blk != bqc_tail)
+ if (blk != hqc_tail)
{
parents.push_back(blk);
if (!--nparents) break;
@@ -386,7 +386,7 @@ class PMStickyProposer: virtual public PaceMaker {
HOTSTUFF_LOG_PROTO("got block %s from %d", std::string(*prop.blk).c_str(), _proposer);
p.reject();
(p = hsc->async_qc_finish(prop.blk)).then([this, blk=prop.blk, _proposer]() {
- if (hsc->get_bqc()->get_qc_ref() == blk)
+ if (hsc->get_hqc() == blk)
to_follower(_proposer);
});
reg_cp_receive_proposal();
@@ -423,7 +423,7 @@ class PMStickyProposer: virtual public PaceMaker {
to_candidate();
});
reg_cp_receive_proposal();
- proposer_propose(Proposal(-1, uint256_t(), hsc->get_genesis(), nullptr));
+ proposer_propose(Proposal(-1, hsc->get_genesis(), nullptr));
}
void to_candidate() {
@@ -675,7 +675,7 @@ class PMRoundRobinProposer: virtual public PaceMaker {
/* proposer unable to get a QC in time */
to_candidate();
});
- proposer_propose(Proposal(-1, uint256_t(), hsc->get_genesis(), nullptr));
+ proposer_propose(Proposal(-1, hsc->get_genesis(), nullptr));
}
void to_candidate() {