aboutsummaryrefslogtreecommitdiff
path: root/include/hotstuff/liveness.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/hotstuff/liveness.h')
-rw-r--r--include/hotstuff/liveness.h46
1 files changed, 35 insertions, 11 deletions
diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h
index f8d3c50..b23d4c2 100644
--- a/include/hotstuff/liveness.h
+++ b/include/hotstuff/liveness.h
@@ -7,13 +7,16 @@ namespace hotstuff {
/** Abstraction for liveness gadget (oracle). */
class PaceMaker {
+ protected:
+ HotStuffCore *hsc;
public:
virtual ~PaceMaker() = default;
+ virtual void init(HotStuffCore *_hsc) { hsc = _hsc; }
/** Get a promise resolved when the pace maker thinks it is a *good* time
- * to issue new commands. When promise is resolved with the ID of itself,
- * the replica should propose the command, otherwise it will forward the
- * command to the proposer indicated by the ID. */
+ * to issue new commands. When promise is resolved, the replica should
+ * propose the command. */
virtual promise_t beat() = 0;
+ virtual ReplicaID get_proposer() = 0;
/** Get a promise resolved when the pace maker thinks it is a *good* time
* to vote for a block. The promise is resolved with the next proposer's ID
* */
@@ -24,7 +27,6 @@ using pacemaker_bt = BoxObj<PaceMaker>;
/** A pace maker that waits for the qc of the last proposed block. */
class PaceMakerDummy: public PaceMaker {
- HotStuffCore *hsc;
std::queue<promise_t> pending_beats;
block_t last_proposed;
bool locked;
@@ -34,9 +36,8 @@ class PaceMakerDummy: public PaceMaker {
{
auto pm = pending_beats.front();
pending_beats.pop();
- hsc->async_qc_finish(last_proposed).then(
- [id = hsc->get_id(), pm]() {
- pm.resolve(id);
+ hsc->async_qc_finish(last_proposed).then([this, pm]() {
+ pm.resolve(get_proposer());
});
locked = true;
}
@@ -52,13 +53,19 @@ class PaceMakerDummy: public PaceMaker {
}
public:
- PaceMakerDummy(HotStuffCore *hsc):
- hsc(hsc),
- last_proposed(hsc->get_genesis()),
- locked(false) {
+ PaceMakerDummy() = default;
+
+ void init(HotStuffCore *hsc) override {
+ PaceMaker::init(hsc);
+ last_proposed = hsc->get_genesis();
+ locked = false;
update_last_proposed();
}
+ ReplicaID get_proposer() override {
+ return hsc->get_id();
+ }
+
promise_t beat() override {
promise_t pm;
pending_beats.push(pm);
@@ -73,6 +80,23 @@ class PaceMakerDummy: public PaceMaker {
}
};
+class PaceMakerDummyFixed: public PaceMakerDummy {
+ ReplicaID proposer;
+
+ public:
+ ReplicaID get_proposer() override {
+ return proposer;
+ }
+
+ PaceMakerDummyFixed(ReplicaID proposer): proposer(proposer) {}
+
+ promise_t next_proposer(ReplicaID) override {
+ return promise_t([this](promise_t &pm) {
+ pm.resolve(proposer);
+ });
+ }
+};
+
}
#endif