aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-04-06 18:14:42 -0400
committerDeterminant <[email protected]>2019-04-06 18:14:42 -0400
commit698a0373f7d72ce0ee0e557ed0352a8594a7a6b0 (patch)
tree8592a551efbc3e53901b08eb6ec842bae784ebdb
parent37f7812a240e419c9aaf39a6069d113cfb45be0b (diff)
...
-rw-r--r--include/hotstuff/hotstuff.h13
m---------salticidae0
-rw-r--r--src/hotstuff.cpp28
-rw-r--r--src/hotstuff_app.cpp17
4 files changed, 31 insertions, 27 deletions
diff --git a/include/hotstuff/hotstuff.h b/include/hotstuff/hotstuff.h
index f7acccc..10dcb84 100644
--- a/include/hotstuff/hotstuff.h
+++ b/include/hotstuff/hotstuff.h
@@ -140,7 +140,7 @@ class HotStuffBase: public HotStuffCore {
/** libevent handle */
EventContext ec;
VeriPool vpool;
- std::unordered_set<NetAddr> peers;
+ std::vector<NetAddr> peers;
private:
/** whether libevent handle is owned by itself */
@@ -212,8 +212,7 @@ class HotStuffBase: public HotStuffCore {
/* Submit the command to be decided. */
promise_t exec_command(uint256_t cmd);
- void add_replica(ReplicaID idx, const NetAddr &addr, pubkey_bt &&pub_key);
- void start(bool ec_loop = false);
+ void start(std::vector<std::pair<NetAddr, pubkey_bt>> &&replicas, bool ec_loop = false);
size_t size() const { return peers.size(); }
PaceMaker &get_pace_maker() { return *pmaker; }
@@ -279,9 +278,11 @@ class HotStuff: public HotStuffBase {
nworker,
netconfig) {}
- void add_replica(ReplicaID idx, const NetAddr &addr, const bytearray_t &pubkey_raw) {
- DataStream s(pubkey_raw);
- HotStuffBase::add_replica(idx, addr, new PubKeyType(pubkey_raw));
+ void start(const std::vector<std::pair<NetAddr, bytearray_t>> &replicas, bool ec_loop = false) {
+ std::vector<std::pair<NetAddr, pubkey_bt>> reps;
+ for (auto &r: replicas)
+ reps.push_back(std::make_pair(r.first, new PubKeyType(r.second)));
+ HotStuffBase::start(std::move(reps), ec_loop);
}
};
diff --git a/salticidae b/salticidae
-Subproject c91fdee8e845a2eccbc680c2d88748b2ac95a40
+Subproject 52a6bcd3a8e056135d50211c60742d7c0e2becb
diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp
index f174559..eb9aae4 100644
--- a/src/hotstuff.cpp
+++ b/src/hotstuff.cpp
@@ -120,16 +120,6 @@ promise_t HotStuffBase::exec_command(uint256_t cmd_hash) {
return it->second;
}
-void HotStuffBase::add_replica(ReplicaID idx, const NetAddr &addr,
- pubkey_bt &&pub_key) {
- HotStuffCore::add_replica(idx, addr, std::move(pub_key));
- if (addr != listen_addr)
- {
- peers.insert(addr);
- pn.add_peer(addr);
- }
-}
-
void HotStuffBase::on_fetch_blk(const block_t &blk) {
#ifdef HOTSTUFF_BLK_PROFILE
blk_profiler.get_tx(blk->get_hash());
@@ -393,8 +383,9 @@ HotStuffBase::HotStuffBase(uint32_t blk_size,
void HotStuffBase::do_broadcast_proposal(const Proposal &prop) {
MsgPropose prop_msg(prop);
- for (const auto &replica: peers)
- pn.send_msg(prop_msg, replica);
+ pn.multicast_msg(prop_msg, peers);
+ //for (const auto &replica: peers)
+ // pn.send_msg(prop_msg, replica);
}
void HotStuffBase::do_vote(ReplicaID last_proposer, const Vote &vote) {
@@ -423,7 +414,18 @@ void HotStuffBase::do_decide(Finality &&fin) {
HotStuffBase::~HotStuffBase() {}
-void HotStuffBase::start(bool ec_loop) {
+void HotStuffBase::start(std::vector<std::pair<NetAddr, pubkey_bt>> &&replicas, bool ec_loop) {
+ for (size_t i = 0; i < replicas.size(); i++)
+ {
+ auto &addr = replicas[i].first;
+ HotStuffCore::add_replica(i, addr, std::move(replicas[i].second));
+ if (addr != listen_addr)
+ {
+ peers.push_back(addr);
+ pn.add_peer(addr);
+ }
+ }
+
/* ((n - 1) + 1 - 1) / 3 */
uint32_t nfaulty = peers.size() / 3;
if (nfaulty == 0)
diff --git a/src/hotstuff_app.cpp b/src/hotstuff_app.cpp
index e9a97e3..f8f15f9 100644
--- a/src/hotstuff_app.cpp
+++ b/src/hotstuff_app.cpp
@@ -124,7 +124,7 @@ class HotStuffApp: public HotStuff {
const Net::Config &repnet_config,
const ClientNetwork<opcode_t>::Config &clinet_config);
- void start();
+ void start(const std::vector<std::pair<NetAddr, bytearray_t>> &reps);
};
std::pair<std::string, std::string> split_ip_port_cport(const std::string &s) {
@@ -241,11 +241,12 @@ int main(int argc, char **argv) {
opt_nworker->get(),
repnet_config,
clinet_config);
- for (size_t i = 0; i < replicas.size(); i++)
+ std::vector<std::pair<NetAddr, bytearray_t>> reps;
+ for (auto &r: replicas)
{
- auto p = split_ip_port_cport(replicas[i].first);
- papp->add_replica(i, NetAddr(p.first),
- hotstuff::from_hex(replicas[i].second));
+ auto p = split_ip_port_cport(r.first);
+ reps.push_back(std::make_pair(
+ NetAddr(p.first), hotstuff::from_hex(r.second)));
}
auto shutdown = [&](int) { ec.stop(); };
salticidae::SigEvent ev_sigint(ec, shutdown);
@@ -253,7 +254,7 @@ int main(int argc, char **argv) {
ev_sigint.add(SIGINT);
ev_sigterm.add(SIGTERM);
- papp->start();
+ papp->start(reps);
elapsed.stop(true);
return 0;
}
@@ -309,7 +310,7 @@ void HotStuffApp::client_request_cmd_handler(MsgReqCmd &&msg, const conn_t &conn
}
}
-void HotStuffApp::start() {
+void HotStuffApp::start(const std::vector<std::pair<NetAddr, bytearray_t>> &reps) {
ev_stat_timer = TimerEvent(ec, [this](TimerEvent &) {
HotStuff::print_stat();
//HotStuffCore::prune(100);
@@ -325,7 +326,7 @@ void HotStuffApp::start() {
HOTSTUFF_LOG_INFO("blk_size = %lu", blk_size);
HOTSTUFF_LOG_INFO("conns = %lu", HotStuff::size());
HOTSTUFF_LOG_INFO("** starting the event loop...");
- HotStuff::start();
+ HotStuff::start(reps);
/* enter the event main loop */
ec.dispatch();
}