From edcadfb47b736e6c9dd6b078689114aecf5c1add Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 3 Aug 2018 18:09:01 -0400 Subject: allow extra data in blocks --- include/hotstuff/consensus.h | 5 ++++- include/hotstuff/entity.h | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h index 1528b40..85c1e8c 100644 --- a/include/hotstuff/consensus.h +++ b/include/hotstuff/consensus.h @@ -80,7 +80,8 @@ class HotStuffCore { * contain at least one block, and the first block is the actual parent, * while the others are uncles/aunts */ void on_propose(const std::vector &cmds, - const std::vector &parents); + const std::vector &parents, + serializable_bt &&extra = nullptr); /* Functions required to construct concrete instances for abstract classes. * */ @@ -113,6 +114,8 @@ class HotStuffCore { virtual quorum_cert_bt parse_quorum_cert(DataStream &s) = 0; /** Create a command object from its serialized form. */ virtual command_t parse_cmd(DataStream &s) = 0; + /** Create the extra data from its serialized form. */ + virtual serializable_bt parse_extra_block_data(DataStream &) { return nullptr; } public: /** Add a replica to the current configuration. This should only be called diff --git a/include/hotstuff/entity.h b/include/hotstuff/entity.h index 09b40aa..dc77c81 100644 --- a/include/hotstuff/entity.h +++ b/include/hotstuff/entity.h @@ -102,13 +102,17 @@ get_hashes(const std::vector &plist) { return std::move(hashes); } +using serializable_bt = BoxObj; + class Block { friend HotStuffCore; std::vector parent_hashes; std::vector cmds; quorum_cert_bt qc; - uint256_t hash; + serializable_bt extra; + /* the following fields can be derived from above */ + uint256_t hash; std::vector parents; block_t qc_ref; quorum_cert_bt self_qc; @@ -121,12 +125,14 @@ class Block { public: Block(): qc(nullptr), + extra(nullptr), qc_ref(nullptr), self_qc(nullptr), height(0), delivered(false), decision(0) {} Block(bool delivered, int8_t decision): qc(nullptr), + extra(nullptr), hash(salticidae::get_hash(*this)), qc_ref(nullptr), self_qc(nullptr), height(0), @@ -134,14 +140,16 @@ class Block { Block(const std::vector &parents, const std::vector &cmds, - uint32_t height, quorum_cert_bt &&qc, + serializable_bt &&extra, + uint32_t height, const block_t &qc_ref, quorum_cert_bt &&self_qc, int8_t decision = 0): parent_hashes(get_hashes(parents)), cmds(cmds), qc(std::move(qc)), + extra(std::move(extra)), hash(salticidae::get_hash(*this)), parents(parents), qc_ref(qc_ref), @@ -185,6 +193,8 @@ class Block { const block_t &get_qc_ref() const { return qc_ref; } + const serializable_bt &get_extra() const { return extra; } + operator std::string () const { DataStream s; s << "