From 3c355d7f9e7b491b9fc5af4516286ab4100238c6 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 19 Jul 2018 17:51:15 -0400 Subject: ... --- include/hotstuff/consensus.h | 50 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'include/hotstuff/consensus.h') 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 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 << ""; + return std::move(s); + } +}; + } #endif -- cgit v1.2.3