aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hotstuff.cpp28
-rw-r--r--src/hotstuff_app.cpp17
2 files changed, 24 insertions, 21 deletions
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();
}