From 3e9f8b641e623054e50f69a5b41d85f8e65a2e13 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 3 Aug 2018 17:22:34 -0400 Subject: ... --- include/hotstuff/liveness.h | 15 +++++++++------ src/hotstuff.cpp | 1 + src/hotstuff_app.cpp | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h index c3d7d73..b8df8ef 100644 --- a/include/hotstuff/liveness.h +++ b/include/hotstuff/liveness.h @@ -174,7 +174,7 @@ class PMStickyProposer: virtual public PaceMaker { } role; double qc_timeout; double candidate_timeout; - EventContext eb; + EventContext ec; /** QC timer or randomized timeout */ Event timer; block_t last_proposed; @@ -296,7 +296,7 @@ class PMStickyProposer: virtual public PaceMaker { role = FOLLOWER; proposer = new_proposer; last_proposed = nullptr; - timer = Event(eb, -1, 0, [this](int, short) { + timer = Event(ec, -1, 0, [this](int, short) { /* unable to get a QC in time */ to_candidate(); }); @@ -315,7 +315,7 @@ class PMStickyProposer: virtual public PaceMaker { role = PROPOSER; proposer = hsc->get_id(); last_proposed = hsc->get_genesis(); - timer = Event(eb, -1, 0, [this](int, short) { + timer = Event(ec, -1, 0, [this](int, short) { /* proposer unable to get a QC in time */ to_candidate(); }); @@ -330,7 +330,7 @@ class PMStickyProposer: virtual public PaceMaker { role = CANDIDATE; proposer = hsc->get_id(); last_proposed = nullptr; - timer = Event(eb, -1, 0, [this](int, short) { + timer = Event(ec, -1, 0, [this](int, short) { candidate_qc_timeout(); }); candidate_timeout = qc_timeout; @@ -339,6 +339,9 @@ class PMStickyProposer: virtual public PaceMaker { } public: + PMStickyProposer(double qc_timeout, const EventContext &ec): + qc_timeout(qc_timeout), ec(ec) {} + void init(HotStuffCore *hsc) override { PaceMaker::init(hsc); to_candidate(); @@ -371,8 +374,8 @@ class PMStickyProposer: virtual public PaceMaker { }; struct PaceMakerSticky: public PMAllParents, public PMStickyProposer { - PaceMakerSticky(int32_t parent_limit): - PMAllParents(parent_limit), PMStickyProposer() {} + PaceMakerSticky(int32_t parent_limit, double qc_timeout, EventContext eb): + PMAllParents(parent_limit), PMStickyProposer(qc_timeout, eb) {} }; } diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index af1ac88..04b31f8 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -350,6 +350,7 @@ void HotStuffBase::print_stat() const { for (const auto &replica: pn.all_peers()) { auto conn = pn.get_peer_conn(replica); + if (conn == nullptr) continue; size_t ns = conn->get_nsent(); size_t nr = conn->get_nrecv(); conn->clear_nsent(); diff --git a/src/hotstuff_app.cpp b/src/hotstuff_app.cpp index 033688a..2b6e0db 100644 --- a/src/hotstuff_app.cpp +++ b/src/hotstuff_app.cpp @@ -55,7 +55,7 @@ using HotStuff = hotstuff::HotStuffSecp256k1; class HotStuffApp: public HotStuff { double stat_period; - EventContext eb; + EventContext ec; /** Network messaging between a replica and its client. */ ClientNetwork cn; /** Timer object to schedule a periodic printing of system statistics */ @@ -86,7 +86,7 @@ class HotStuffApp: public HotStuff { NetAddr plisten_addr, NetAddr clisten_addr, hotstuff::pacemaker_bt pmaker, - const EventContext &eb); + const EventContext &ec); void start(); }; @@ -133,7 +133,7 @@ int main(int argc, char **argv) { config.add_opt("pace-maker", opt_pace_maker, Config::SET_VAL, 'p', "specify pace maker (sticky, dummy)"); config.add_opt("help", opt_help, Config::SWITCH_ON, 'h', "show this help info"); - EventContext eb; + EventContext ec; #ifdef HOTSTUFF_NORMAL_LOG try { #endif @@ -173,7 +173,7 @@ int main(int argc, char **argv) { auto parent_limit = opt_parent_limit->get(); hotstuff::pacemaker_bt pmaker; if (opt_pace_maker->get() == "sticky") - pmaker = new hotstuff::PaceMakerSticky(parent_limit); + pmaker = new hotstuff::PaceMakerSticky(parent_limit, 1, ec); else pmaker = new hotstuff::PaceMakerDummyFixed(1, parent_limit); @@ -184,7 +184,7 @@ int main(int argc, char **argv) { plisten_addr, NetAddr("0.0.0.0", client_port), std::move(pmaker), - eb); + ec); for (size_t i = 0; i < replicas.size(); i++) { auto p = split_ip_port_cport(replicas[i].first); @@ -208,12 +208,12 @@ HotStuffApp::HotStuffApp(uint32_t blk_size, NetAddr plisten_addr, NetAddr clisten_addr, hotstuff::pacemaker_bt pmaker, - const EventContext &eb): + const EventContext &ec): HotStuff(blk_size, idx, raw_privkey, - plisten_addr, std::move(pmaker), eb), + plisten_addr, std::move(pmaker), ec), stat_period(stat_period), - eb(eb), - cn(eb), + ec(ec), + cn(ec), clisten_addr(clisten_addr) { /* register the handlers for msg from clients */ cn.reg_handler(salticidae::generic_bind(&HotStuffApp::client_request_cmd_handler, this, _1, _2)); @@ -232,7 +232,7 @@ void HotStuffApp::client_request_cmd_handler(MsgReqCmd &&msg, Conn &conn) { } void HotStuffApp::start() { - ev_stat_timer = Event(eb, -1, 0, + ev_stat_timer = Event(ec, -1, 0, std::bind(&HotStuffApp::print_stat_cb, this, _1, _2)); ev_stat_timer.add_with_timeout(stat_period); LOG_INFO("** starting the system with parameters **"); @@ -241,7 +241,7 @@ void HotStuffApp::start() { LOG_INFO("** starting the event loop..."); HotStuff::start(); /* enter the event main loop */ - eb.dispatch(); + ec.dispatch(); } -- cgit v1.2.3-70-g09d2