aboutsummaryrefslogtreecommitdiff
path: root/include/hotstuff
diff options
context:
space:
mode:
Diffstat (limited to 'include/hotstuff')
-rw-r--r--include/hotstuff/consensus.h8
-rw-r--r--include/hotstuff/entity.h22
-rw-r--r--include/hotstuff/hotstuff.h42
-rw-r--r--include/hotstuff/liveness.h6
-rw-r--r--include/hotstuff/type.h8
5 files changed, 42 insertions, 44 deletions
diff --git a/include/hotstuff/consensus.h b/include/hotstuff/consensus.h
index 8a4f5f0..e2f7cfc 100644
--- a/include/hotstuff/consensus.h
+++ b/include/hotstuff/consensus.h
@@ -142,7 +142,7 @@ class HotStuffCore {
public:
/** Add a replica to the current configuration. This should only be called
* before running HotStuffCore protocol. */
- void add_replica(ReplicaID rid, const NetAddr &addr, pubkey_bt &&pub_key);
+ void add_replica(ReplicaID rid, const PeerId &peer_id, pubkey_bt &&pub_key);
/** Try to prune blocks lower than last committed height - staleness. */
void prune(uint32_t staleness);
@@ -201,7 +201,7 @@ struct Proposal: public Serializable {
s << "<proposal "
<< "rid=" << std::to_string(proposer) << " "
<< "blk=" << get_hex10(blk->get_hash()) << ">";
- return std::move(s);
+ return s;
}
};
@@ -261,7 +261,7 @@ struct Vote: public Serializable {
s << "<vote "
<< "rid=" << std::to_string(voter) << " "
<< "blk=" << get_hex10(blk_hash) << ">";
- return std::move(s);
+ return s;
}
};
@@ -307,7 +307,7 @@ struct Finality: public Serializable {
<< "cmd_height=" << std::to_string(cmd_height) << " "
<< "cmd=" << get_hex10(cmd_hash) << " "
<< "blk=" << get_hex10(blk_hash) << ">";
- return std::move(s);
+ return s;
}
};
diff --git a/include/hotstuff/entity.h b/include/hotstuff/entity.h
index b3bf6a8..dea980d 100644
--- a/include/hotstuff/entity.h
+++ b/include/hotstuff/entity.h
@@ -39,20 +39,20 @@ enum EntityType {
struct ReplicaInfo {
ReplicaID id;
- salticidae::NetAddr addr;
+ salticidae::PeerId peer_id;
pubkey_bt pubkey;
ReplicaInfo(ReplicaID id,
- const salticidae::NetAddr &addr,
+ const salticidae::PeerId &peer_id,
pubkey_bt &&pubkey):
- id(id), addr(addr), pubkey(std::move(pubkey)) {}
+ id(id), peer_id(peer_id), pubkey(std::move(pubkey)) {}
ReplicaInfo(const ReplicaInfo &other):
- id(other.id), addr(other.addr),
+ id(other.id), peer_id(other.peer_id),
pubkey(other.pubkey->clone()) {}
ReplicaInfo(ReplicaInfo &&other):
- id(other.id), addr(other.addr),
+ id(other.id), peer_id(other.peer_id),
pubkey(std::move(other.pubkey)) {}
};
@@ -82,8 +82,8 @@ class ReplicaConfig {
return *(get_info(rid).pubkey);
}
- const salticidae::NetAddr &get_addr(ReplicaID rid) const {
- return get_info(rid).addr;
+ const salticidae::PeerId &get_peer_id(ReplicaID rid) const {
+ return get_info(rid).peer_id;
}
};
@@ -101,7 +101,7 @@ class Command: public Serializable {
virtual operator std::string () const {
DataStream s;
s << "<cmd id=" << get_hex10(get_hash()) << ">";
- return std::move(s);
+ return s;
}
};
@@ -113,7 +113,7 @@ get_hashes(const std::vector<Hashable> &plist) {
std::vector<uint256_t> hashes;
for (const auto &p: plist)
hashes.push_back(p->get_hash());
- return std::move(hashes);
+ return hashes;
}
class Block {
@@ -142,7 +142,7 @@ class Block {
delivered(false), decision(0) {}
Block(bool delivered, int8_t decision):
- qc(nullptr),
+ qc(new QuorumCertDummy()),
hash(salticidae::get_hash(*this)),
qc_ref(nullptr),
self_qc(nullptr), height(0),
@@ -209,7 +209,7 @@ class Block {
<< "height=" << std::to_string(height) << " "
<< "parent=" << get_hex10(parent_hashes[0]) << " "
<< "qc_ref=" << (qc_ref ? get_hex10(qc_ref->get_hash()) : "null") << ">";
- return std::move(s);
+ return s;
}
};
diff --git a/include/hotstuff/hotstuff.h b/include/hotstuff/hotstuff.h
index 07f69d9..33b673f 100644
--- a/include/hotstuff/hotstuff.h
+++ b/include/hotstuff/hotstuff.h
@@ -89,7 +89,7 @@ class FetchContext: public promise_t {
HotStuffBase *hs;
MsgReqBlock fetch_msg;
const uint256_t ent_hash;
- std::unordered_set<NetAddr> replica_ids;
+ std::unordered_set<PeerId> replicas;
inline void timeout_cb(TimerEvent &);
public:
FetchContext(const FetchContext &) = delete;
@@ -99,9 +99,9 @@ class FetchContext: public promise_t {
FetchContext(const uint256_t &ent_hash, HotStuffBase *hs);
~FetchContext() {}
- inline void send(const NetAddr &replica_id);
+ inline void send(const PeerId &replica);
inline void reset_timeout();
- inline void add_replica(const NetAddr &replica_id, bool fetch_now = true);
+ inline void add_replica(const PeerId &replica, bool fetch_now = true);
};
class BlockDeliveryContext: public promise_t {
@@ -142,7 +142,7 @@ class HotStuffBase: public HotStuffCore {
EventContext ec;
salticidae::ThreadCall tcall;
VeriPool vpool;
- std::vector<NetAddr> peers;
+ std::vector<PeerId> peers;
private:
/** whether libevent handle is owned by itself */
@@ -176,11 +176,11 @@ class HotStuffBase: public HotStuffCore {
mutable double part_delivery_time;
mutable double part_delivery_time_min;
mutable double part_delivery_time_max;
- mutable std::unordered_map<const NetAddr, uint32_t> part_fetched_replica;
+ mutable std::unordered_map<const PeerId, uint32_t> part_fetched_replica;
void on_fetch_cmd(const command_t &cmd);
void on_fetch_blk(const block_t &blk);
- void on_deliver_blk(const block_t &blk);
+ bool on_deliver_blk(const block_t &blk);
/** deliver consensus message: <propose> */
inline void propose_handler(MsgPropose &&, const Net::conn_t &);
@@ -235,11 +235,11 @@ class HotStuffBase: public HotStuffCore {
/* Helper functions */
/** Returns a promise resolved (with command_t cmd) when Command is fetched. */
- promise_t async_fetch_cmd(const uint256_t &cmd_hash, const NetAddr *replica_id, bool fetch_now = true);
+ promise_t async_fetch_cmd(const uint256_t &cmd_hash, const PeerId *replica, bool fetch_now = true);
/** Returns a promise resolved (with block_t blk) when Block is fetched. */
- promise_t async_fetch_blk(const uint256_t &blk_hash, const NetAddr *replica_id, bool fetch_now = true);
+ promise_t async_fetch_blk(const uint256_t &blk_hash, const PeerId *replica, bool fetch_now = true);
/** Returns a promise resolved (with block_t blk) when Block is delivered (i.e. prefix is fetched). */
- promise_t async_deliver_blk(const uint256_t &blk_hash, const NetAddr &replica_id);
+ promise_t async_deliver_blk(const uint256_t &blk_hash, const PeerId &replica);
};
/** HotStuff protocol (templated by cryptographic implementation). */
@@ -316,7 +316,7 @@ FetchContext<ent_type>::FetchContext(FetchContext && other):
hs(other.hs),
fetch_msg(std::move(other.fetch_msg)),
ent_hash(other.ent_hash),
- replica_ids(std::move(other.replica_ids)) {
+ replicas(std::move(other.replicas)) {
other.timeout.del();
timeout = TimerEvent(hs->ec,
std::bind(&FetchContext::timeout_cb, this, _1));
@@ -326,16 +326,16 @@ FetchContext<ent_type>::FetchContext(FetchContext && other):
template<>
inline void FetchContext<ENT_TYPE_CMD>::timeout_cb(TimerEvent &) {
HOTSTUFF_LOG_WARN("cmd fetching %.10s timeout", get_hex(ent_hash).c_str());
- for (const auto &replica_id: replica_ids)
- send(replica_id);
+ for (const auto &replica: replicas)
+ send(replica);
reset_timeout();
}
template<>
inline void FetchContext<ENT_TYPE_BLK>::timeout_cb(TimerEvent &) {
HOTSTUFF_LOG_WARN("block fetching %.10s timeout", get_hex(ent_hash).c_str());
- for (const auto &replica_id: replica_ids)
- send(replica_id);
+ for (const auto &replica: replicas)
+ send(replica);
reset_timeout();
}
@@ -352,9 +352,9 @@ FetchContext<ent_type>::FetchContext(
}
template<EntityType ent_type>
-void FetchContext<ent_type>::send(const NetAddr &replica_id) {
- hs->part_fetched_replica[replica_id]++;
- hs->pn.send_msg(fetch_msg, replica_id);
+void FetchContext<ent_type>::send(const PeerId &replica) {
+ hs->part_fetched_replica[replica]++;
+ hs->pn.send_msg(fetch_msg, replica);
}
template<EntityType ent_type>
@@ -363,10 +363,10 @@ void FetchContext<ent_type>::reset_timeout() {
}
template<EntityType ent_type>
-void FetchContext<ent_type>::add_replica(const NetAddr &replica_id, bool fetch_now) {
- if (replica_ids.empty() && fetch_now)
- send(replica_id);
- replica_ids.insert(replica_id);
+void FetchContext<ent_type>::add_replica(const PeerId &replica, bool fetch_now) {
+ if (replicas.empty() && fetch_now)
+ send(replica);
+ replicas.insert(replica);
}
}
diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h
index 452ecdc..eff1406 100644
--- a/include/hotstuff/liveness.h
+++ b/include/hotstuff/liveness.h
@@ -124,7 +124,7 @@ class PMHighTail: public virtual PaceMaker {
// if (!--nparents) break;
// }
// }
- return std::move(parents);
+ return parents;
}
};
@@ -182,7 +182,7 @@ class PMWaitQC: public virtual PaceMaker {
promise_t pm;
pending_beats.push(pm);
schedule_next();
- return std::move(pm);
+ return pm;
}
promise_t beat_resp(ReplicaID last_proposer) override {
@@ -393,7 +393,7 @@ class PMRoundRobinProposer: virtual public PaceMaker {
promise_t pm;
pending_beats.push(pm);
proposer_schedule_next();
- return std::move(pm);
+ return pm;
}
else
return promise_t([proposer=proposer](promise_t &pm) {
diff --git a/include/hotstuff/type.h b/include/hotstuff/type.h
index 07c1e72..d895b73 100644
--- a/include/hotstuff/type.h
+++ b/include/hotstuff/type.h
@@ -21,6 +21,7 @@
#include "salticidae/event.h"
#include "salticidae/ref.h"
#include "salticidae/netaddr.h"
+#include "salticidae/network.h"
#include "salticidae/stream.h"
#include "salticidae/type.h"
#include "salticidae/util.h"
@@ -38,19 +39,16 @@ using salticidae::letoh;
using salticidae::get_hex;
using salticidae::from_hex;
using salticidae::bytearray_t;
+using salticidae::get_hex10;
using salticidae::get_hash;
using salticidae::NetAddr;
+using salticidae::PeerId;
using salticidae::TimerEvent;
using salticidae::FdEvent;
using salticidae::EventContext;
using promise::promise_t;
-template<typename SerialType>
-inline std::string get_hex10(const SerialType &x) {
- return get_hex(x).substr(0, 10);
-}
-
class HotStuffError: public salticidae::SalticidaeError {
public:
template<typename... Args>