aboutsummaryrefslogtreecommitdiff
path: root/include/hotstuff/consensus.h
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2018-07-19 17:51:15 -0400
committerDeterminant <tederminant@gmail.com>2018-07-19 17:51:15 -0400
commit3c355d7f9e7b491b9fc5af4516286ab4100238c6 (patch)
tree7806e385c3c35be4deb82d4a799fc504ed6e90b3 /include/hotstuff/consensus.h
parent3c1cac7136b6fbc378c5bc86a50537794f2b6437 (diff)
...
Diffstat (limited to 'include/hotstuff/consensus.h')
-rw-r--r--include/hotstuff/consensus.h50
1 files changed, 48 insertions, 2 deletions
diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h
index a3a1f25..475f1f2 100644
--- a/include/hotstuff/consensus.h
+++ b/include/hotstuff/consensus.h
@@ -14,6 +14,7 @@ namespace hotstuff {
struct Proposal;
struct Vote;
+struct Finality;
/** Abstraction for HotStuff protocol state machine (without network implementation). */
class HotStuffCore {
@@ -86,7 +87,7 @@ class HotStuffCore {
* the events. */
protected:
/** Called by HotStuffCore upon the decision being made for cmd. */
- virtual void do_decide(const command_t &cmd) = 0;
+ virtual void do_decide(Finality &&fin) = 0;
/** Called by HotStuffCore upon broadcasting a new proposal.
* The user should send the proposal message to all replicas except for
* itself. */
@@ -127,7 +128,6 @@ class HotStuffCore {
/* Other useful functions */
block_t get_genesis() { return b0; }
const ReplicaConfig &get_config() { return config; }
- int8_t get_cmd_decision(const uint256_t &cmd_hash);
ReplicaID get_id() const { return id; }
const std::set<block_t, BlockHeightCmp> get_tails() const { return tails; }
operator std::string () const;
@@ -249,6 +249,52 @@ struct Vote: public Serializable {
}
};
+struct Finality: public Serializable {
+ ReplicaID rid;
+ int8_t decision;
+ uint32_t cmd_idx;
+ uint32_t cmd_height;
+ uint256_t cmd_hash;
+ uint256_t blk_hash;
+
+ public:
+ Finality() = default;
+ Finality(ReplicaID rid,
+ int8_t decision,
+ uint32_t cmd_idx,
+ uint32_t cmd_height,
+ uint256_t cmd_hash,
+ uint256_t blk_hash):
+ rid(rid), decision(decision),
+ cmd_idx(cmd_idx), cmd_height(cmd_height),
+ cmd_hash(cmd_hash), blk_hash(blk_hash) {}
+
+ void serialize(DataStream &s) const override {
+ s << rid << decision
+ << cmd_idx << cmd_height
+ << cmd_hash;
+ if (decision == 1) s << blk_hash;
+ }
+
+ void unserialize(DataStream &s) override {
+ s >> rid >> decision
+ >> cmd_idx >> cmd_height
+ >> cmd_hash;
+ if (decision == 1) s >> blk_hash;
+ }
+
+ operator std::string () const {
+ DataStream s;
+ s << "<fin "
+ << "decision=" << std::to_string(decision) << " "
+ << "cmd_idx=" << std::to_string(cmd_idx) << " "
+ << "cmd_height=" << std::to_string(cmd_height) << " "
+ << "cmd=" << get_hex10(cmd_hash) << " "
+ << "blk=" << get_hex10(blk_hash) << ">";
+ return std::move(s);
+ }
+};
+
}
#endif