aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/hotstuff/consensus.h8
-rw-r--r--include/hotstuff/entity.h10
-rw-r--r--include/hotstuff/liveness.h1
-rw-r--r--src/entity.cpp12
-rw-r--r--src/hotstuff.cpp2
5 files changed, 20 insertions, 13 deletions
diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h
index e0f2ecc..8a4f5f0 100644
--- a/include/hotstuff/consensus.h
+++ b/include/hotstuff/consensus.h
@@ -44,7 +44,7 @@ class HotStuffCore {
uint32_t vheight; /**< height of the block last voted for */
/* === auxilliary variables === */
privkey_bt priv_key; /**< private key for signing votes */
- std::set<block_t, BlockHeightCmp> tails; /**< set of tail blocks */
+ std::set<block_t> tails; /**< set of tail blocks */
ReplicaConfig config; /**< replica configuration */
/* === async event queues === */
std::unordered_map<block_t, promise_t> qc_waiting;
@@ -158,11 +158,11 @@ class HotStuffCore {
promise_t async_hqc_update();
/* Other useful functions */
- const block_t &get_genesis() { return b0; }
+ const block_t &get_genesis() const { return b0; }
const block_t &get_hqc() { return hqc.first; }
- const ReplicaConfig &get_config() { return config; }
+ const ReplicaConfig &get_config() const { return config; }
ReplicaID get_id() const { return id; }
- const std::set<block_t, BlockHeightCmp> get_tails() const { return tails; }
+ const std::set<block_t> get_tails() const { return tails; }
operator std::string () const;
void set_vote_disabled(bool f) { vote_disabled = f; }
};
diff --git a/include/hotstuff/entity.h b/include/hotstuff/entity.h
index 12d92cc..b3bf6a8 100644
--- a/include/hotstuff/entity.h
+++ b/include/hotstuff/entity.h
@@ -186,15 +186,9 @@ class Block {
const uint256_t &get_hash() const { return hash; }
- bool verify(const ReplicaConfig &config) const {
- if (qc && !qc->verify(config)) return false;
- return true;
- }
+ bool verify(const HotStuffCore *hsc) const;
- promise_t verify(const ReplicaConfig &config, VeriPool &vpool) const {
- return (qc ? qc->verify(config, vpool) :
- promise_t([](promise_t &pm) { pm.resolve(true); }));
- }
+ promise_t verify(const HotStuffCore *hsc, VeriPool &vpool) const;
int8_t get_decision() const { return decision; }
diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h
index b0373ed..452ecdc 100644
--- a/include/hotstuff/liveness.h
+++ b/include/hotstuff/liveness.h
@@ -73,6 +73,7 @@ class PMHighTail: public virtual PaceMaker {
void reg_hqc_update() {
hsc->async_hqc_update().then([this](const block_t &hqc) {
+ hqc_tail = hqc;
for (const auto &tail: hsc->get_tails())
if (check_ancestry(hqc, tail) && tail->get_height() > hqc_tail->get_height())
hqc_tail = tail;
diff --git a/src/entity.cpp b/src/entity.cpp
index e90e0f2..59febac 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -62,4 +62,16 @@ void Block::unserialize(DataStream &s, HotStuffCore *hsc) {
this->hash = salticidae::get_hash(*this);
}
+bool Block::verify(const HotStuffCore *hsc) const {
+ return qc && qc->verify(hsc->get_config());
+}
+
+promise_t Block::verify(const HotStuffCore *hsc, VeriPool &vpool) const {
+ if (!qc)
+ return promise_t([](promise_t &pm) { pm.resolve(false); });
+ if (qc->get_obj_hash() == hsc->get_genesis()->get_hash())
+ return promise_t([](promise_t &pm) { pm.resolve(true); });
+ return qc->verify(hsc->get_config(), vpool);
+}
+
}
diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp
index 5ae0fe6..b584af0 100644
--- a/src/hotstuff.cpp
+++ b/src/hotstuff.cpp
@@ -184,7 +184,7 @@ promise_t HotStuffBase::async_deliver_blk(const uint256_t &blk_hash,
for (const auto &phash: blk->get_parent_hashes())
pms.push_back(async_deliver_blk(phash, replica_id));
if (blk != get_genesis())
- pms.push_back(blk->verify(get_config(), vpool));
+ pms.push_back(blk->verify(this, vpool));
promise::all(pms).then([this, blk]() {
on_deliver_blk(blk);
});