From e6d7e7d829fbfdb87899fc4dd05f5bddc344bdb6 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 24 Mar 2019 21:32:23 -0400 Subject: clean up --- include/hotstuff/consensus.h | 6 ++--- include/hotstuff/crypto.h | 62 ++++++++++++++++++++++---------------------- include/hotstuff/entity.h | 2 +- include/hotstuff/type.h | 1 + 4 files changed, 36 insertions(+), 35 deletions(-) (limited to 'include/hotstuff') diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h index b273f97..5f781c5 100644 --- a/include/hotstuff/consensus.h +++ b/include/hotstuff/consensus.h @@ -79,7 +79,7 @@ class HotStuffCore { /** Call to initialize the protocol, should be called once before all other * functions. */ - void on_init(uint32_t nfaulty) { config.nmajority = 2 * nfaulty + 1; } + void on_init(uint32_t nfaulty); /* TODO: better name for "delivery" ? */ /** Call to inform the state machine that a block is ready to be handled. @@ -267,13 +267,13 @@ struct Vote: public Serializable { bool verify() const { assert(hsc != nullptr); return cert->verify(hsc->get_config().get_pubkey(voter)) && - cert->get_blk_hash() == blk_hash; + cert->get_obj_hash() == blk_hash; } promise_t verify(VeriPool &vpool) const { assert(hsc != nullptr); return cert->verify(hsc->get_config().get_pubkey(voter), vpool).then([this](bool result) { - return result && cert->get_blk_hash() == blk_hash; + return result && cert->get_obj_hash() == blk_hash; }); } diff --git a/include/hotstuff/crypto.h b/include/hotstuff/crypto.h index 7af9d8c..60e7dfc 100644 --- a/include/hotstuff/crypto.h +++ b/include/hotstuff/crypto.h @@ -50,7 +50,7 @@ class PartCert: public Serializable, public Cloneable { virtual ~PartCert() = default; virtual promise_t verify(const PubKey &pubkey, VeriPool &vpool) = 0; virtual bool verify(const PubKey &pubkey) = 0; - virtual const uint256_t &get_blk_hash() const = 0; + virtual const uint256_t &get_obj_hash() const = 0; virtual PartCert *clone() override = 0; }; @@ -63,7 +63,7 @@ class QuorumCert: public Serializable, public Cloneable { virtual void compute() = 0; virtual promise_t verify(const ReplicaConfig &config, VeriPool &vpool) = 0; virtual bool verify(const ReplicaConfig &config) = 0; - virtual const uint256_t &get_blk_hash() const = 0; + virtual const uint256_t &get_obj_hash() const = 0; virtual QuorumCert *clone() override = 0; }; @@ -84,23 +84,23 @@ class PrivKeyDummy: public PrivKey { }; class PartCertDummy: public PartCert { - uint256_t blk_hash; + uint256_t obj_hash; public: PartCertDummy() {} - PartCertDummy(const uint256_t &blk_hash): - blk_hash(blk_hash) {} + PartCertDummy(const uint256_t &obj_hash): + obj_hash(obj_hash) {} void serialize(DataStream &s) const override { - s << (uint32_t)0 << blk_hash; + s << (uint32_t)0 << obj_hash; } void unserialize(DataStream &s) override { uint32_t tmp; - s >> tmp >> blk_hash; + s >> tmp >> obj_hash; } PartCert *clone() override { - return new PartCertDummy(blk_hash); + return new PartCertDummy(obj_hash); } bool verify(const PubKey &) override { return true; } @@ -108,23 +108,23 @@ class PartCertDummy: public PartCert { return promise_t([](promise_t &pm){ pm.resolve(true); }); } - const uint256_t &get_blk_hash() const override { return blk_hash; } + const uint256_t &get_obj_hash() const override { return obj_hash; } }; class QuorumCertDummy: public QuorumCert { - uint256_t blk_hash; + uint256_t obj_hash; public: QuorumCertDummy() {} - QuorumCertDummy(const ReplicaConfig &, const uint256_t &blk_hash): - blk_hash(blk_hash) {} + QuorumCertDummy(const ReplicaConfig &, const uint256_t &obj_hash): + obj_hash(obj_hash) {} void serialize(DataStream &s) const override { - s << (uint32_t)1 << blk_hash; + s << (uint32_t)1 << obj_hash; } void unserialize(DataStream &s) override { uint32_t tmp; - s >> tmp >> blk_hash; + s >> tmp >> obj_hash; } QuorumCert *clone() override { @@ -138,7 +138,7 @@ class QuorumCertDummy: public QuorumCert { return promise_t([](promise_t &pm) { pm.resolve(true); }); } - const uint256_t &get_blk_hash() const override { return blk_hash; } + const uint256_t &get_obj_hash() const override { return obj_hash; } }; @@ -163,7 +163,7 @@ class Secp256k1Context { } }; -using secp256k1_context_t = RcObj; +using secp256k1_context_t = ArcObj; extern secp256k1_context_t secp256k1_default_sign_ctx; extern secp256k1_context_t secp256k1_default_verify_ctx; @@ -346,55 +346,55 @@ class Secp256k1VeriTask: public VeriTask { }; class PartCertSecp256k1: public SigSecp256k1, public PartCert { - uint256_t blk_hash; + uint256_t obj_hash; public: PartCertSecp256k1() = default; - PartCertSecp256k1(const PrivKeySecp256k1 &priv_key, const uint256_t &blk_hash): - SigSecp256k1(blk_hash, priv_key), + PartCertSecp256k1(const PrivKeySecp256k1 &priv_key, const uint256_t &obj_hash): + SigSecp256k1(obj_hash, priv_key), PartCert(), - blk_hash(blk_hash) {} + obj_hash(obj_hash) {} bool verify(const PubKey &pub_key) override { - return SigSecp256k1::verify(blk_hash, + return SigSecp256k1::verify(obj_hash, static_cast(pub_key), secp256k1_default_verify_ctx); } promise_t verify(const PubKey &pub_key, VeriPool &vpool) override { - return vpool.verify(new Secp256k1VeriTask(blk_hash, + return vpool.verify(new Secp256k1VeriTask(obj_hash, static_cast(pub_key), static_cast(*this))); } - const uint256_t &get_blk_hash() const override { return blk_hash; } + const uint256_t &get_obj_hash() const override { return obj_hash; } PartCertSecp256k1 *clone() override { return new PartCertSecp256k1(*this); } void serialize(DataStream &s) const override { - s << blk_hash; + s << obj_hash; this->SigSecp256k1::serialize(s); } void unserialize(DataStream &s) override { - s >> blk_hash; + s >> obj_hash; this->SigSecp256k1::unserialize(s); } }; class QuorumCertSecp256k1: public QuorumCert { - uint256_t blk_hash; + uint256_t obj_hash; salticidae::Bits rids; std::unordered_map sigs; public: QuorumCertSecp256k1() = default; - QuorumCertSecp256k1(const ReplicaConfig &config, const uint256_t &blk_hash); + QuorumCertSecp256k1(const ReplicaConfig &config, const uint256_t &obj_hash); void add_part(ReplicaID rid, const PartCert &pc) override { - if (pc.get_blk_hash() != blk_hash) + if (pc.get_obj_hash() != obj_hash) throw std::invalid_argument("PartCert does match the block hash"); sigs.insert(std::make_pair( rid, static_cast(pc))); @@ -406,20 +406,20 @@ class QuorumCertSecp256k1: public QuorumCert { bool verify(const ReplicaConfig &config) override; promise_t verify(const ReplicaConfig &config, VeriPool &vpool) override; - const uint256_t &get_blk_hash() const override { return blk_hash; } + const uint256_t &get_obj_hash() const override { return obj_hash; } QuorumCertSecp256k1 *clone() override { return new QuorumCertSecp256k1(*this); } void serialize(DataStream &s) const override { - s << blk_hash << rids; + s << obj_hash << rids; for (size_t i = 0; i < rids.size(); i++) if (rids.get(i)) s << sigs.at(i); } void unserialize(DataStream &s) override { - s >> blk_hash >> rids; + s >> obj_hash >> rids; for (size_t i = 0; i < rids.size(); i++) if (rids.get(i)) s >> sigs[i]; } diff --git a/include/hotstuff/entity.h b/include/hotstuff/entity.h index c112dd7..12d92cc 100644 --- a/include/hotstuff/entity.h +++ b/include/hotstuff/entity.h @@ -105,7 +105,7 @@ class Command: public Serializable { } }; -using command_t = RcObj; +using command_t = ArcObj; template inline static std::vector diff --git a/include/hotstuff/type.h b/include/hotstuff/type.h index e4c87d6..1d5ac55 100644 --- a/include/hotstuff/type.h +++ b/include/hotstuff/type.h @@ -28,6 +28,7 @@ namespace hotstuff { using salticidae::RcObj; +using salticidae::ArcObj; using salticidae::BoxObj; using salticidae::uint256_t; -- cgit v1.2.3-70-g09d2