From 745cb7a88baec540386f57edac7c84db889d63eb Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 3 Aug 2018 16:58:55 -0400 Subject: add pace maker option --- include/hotstuff/hotstuff.h | 2 +- include/hotstuff/liveness.h | 9 +++++++-- src/hotstuff.cpp | 2 +- src/hotstuff_app.cpp | 24 ++++++++++++++---------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/hotstuff/hotstuff.h b/include/hotstuff/hotstuff.h index 41c83b4..b0a6827 100644 --- a/include/hotstuff/hotstuff.h +++ b/include/hotstuff/hotstuff.h @@ -128,7 +128,6 @@ class HotStuffBase: public HotStuffCore { size_t blk_size; /** libevent handle */ EventContext eb; - pacemaker_bt pmaker; private: /** whether libevent handle is owned by itself */ @@ -138,6 +137,7 @@ class HotStuffBase: public HotStuffCore { #ifdef HOTSTUFF_BLK_PROFILE BlockProfiler blk_profiler; #endif + pacemaker_bt pmaker; /* queues for async tasks */ std::unordered_map blk_fetch_waiting; std::unordered_map blk_delivery_waiting; diff --git a/include/hotstuff/liveness.h b/include/hotstuff/liveness.h index c87a242..c3d7d73 100644 --- a/include/hotstuff/liveness.h +++ b/include/hotstuff/liveness.h @@ -166,7 +166,7 @@ class PaceMakerDummyFixed: public PaceMakerDummy { * sees such new QC, if the QC is given by itself, it becomes the proposer, * otherwise yields to the creator of the QC as a follower. */ -class PMStickyProposer: public PMWaitQC { +class PMStickyProposer: virtual public PaceMaker { enum { PROPOSER, FOLLOWER, @@ -340,7 +340,7 @@ class PMStickyProposer: public PMWaitQC { public: void init(HotStuffCore *hsc) override { - PMWaitQC::init(hsc); + PaceMaker::init(hsc); to_candidate(); } @@ -370,6 +370,11 @@ class PMStickyProposer: public PMWaitQC { } }; +struct PaceMakerSticky: public PMAllParents, public PMStickyProposer { + PaceMakerSticky(int32_t parent_limit): + PMAllParents(parent_limit), PMStickyProposer() {} +}; + } #endif diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index 2bde97e..af1ac88 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -381,8 +381,8 @@ HotStuffBase::HotStuffBase(uint32_t blk_size, listen_addr(listen_addr), blk_size(blk_size), eb(eb), - pmaker(std::move(pmaker)), pn(eb), + pmaker(std::move(pmaker)), fetched(0), delivered(0), nsent(0), nrecv(0), diff --git a/src/hotstuff_app.cpp b/src/hotstuff_app.cpp index f7270f2..033688a 100644 --- a/src/hotstuff_app.cpp +++ b/src/hotstuff_app.cpp @@ -62,8 +62,6 @@ class HotStuffApp: public HotStuff { Event ev_stat_timer; /** The listen address for client RPC */ NetAddr clisten_addr; - /** Maximum number of parents. */ - int32_t parent_limit; using Conn = ClientNetwork::Conn; @@ -82,12 +80,12 @@ class HotStuffApp: public HotStuff { public: HotStuffApp(uint32_t blk_size, - int32_t parent_limit, double stat_period, ReplicaID idx, const bytearray_t &raw_privkey, NetAddr plisten_addr, NetAddr clisten_addr, + hotstuff::pacemaker_bt pmaker, const EventContext &eb); void start(); @@ -123,6 +121,7 @@ int main(int argc, char **argv) { auto opt_client_port = Config::OptValInt::create(-1); auto opt_privkey = Config::OptValStr::create(); auto opt_help = Config::OptValFlag::create(false); + auto opt_pace_maker = Config::OptValStr::create("dummy"); config.add_opt("block-size", opt_blk_size, Config::SET_VAL); config.add_opt("parent-limit", opt_parent_limit, Config::SET_VAL); @@ -131,6 +130,7 @@ int main(int argc, char **argv) { config.add_opt("idx", opt_idx, Config::SET_VAL); config.add_opt("cport", opt_client_port, Config::SET_VAL); config.add_opt("privkey", opt_privkey, Config::SET_VAL); + 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; @@ -170,13 +170,20 @@ int main(int argc, char **argv) { NetAddr plisten_addr{split_ip_port_cport(binding_addr).first}; + auto parent_limit = opt_parent_limit->get(); + hotstuff::pacemaker_bt pmaker; + if (opt_pace_maker->get() == "sticky") + pmaker = new hotstuff::PaceMakerSticky(parent_limit); + else + pmaker = new hotstuff::PaceMakerDummyFixed(1, parent_limit); + papp = new HotStuffApp(opt_blk_size->get(), - opt_parent_limit->get(), opt_stat_period->get(), idx, hotstuff::from_hex(opt_privkey->get()), plisten_addr, NetAddr("0.0.0.0", client_port), + std::move(pmaker), eb); for (size_t i = 0; i < replicas.size(); i++) { @@ -195,21 +202,19 @@ int main(int argc, char **argv) { } HotStuffApp::HotStuffApp(uint32_t blk_size, - int32_t parent_limit, double stat_period, ReplicaID idx, const bytearray_t &raw_privkey, NetAddr plisten_addr, NetAddr clisten_addr, + hotstuff::pacemaker_bt pmaker, const EventContext &eb): HotStuff(blk_size, idx, raw_privkey, - plisten_addr, - new hotstuff::PaceMakerDummyFixed(1, parent_limit), eb), + plisten_addr, std::move(pmaker), eb), stat_period(stat_period), eb(eb), cn(eb), - clisten_addr(clisten_addr), - parent_limit(parent_limit) { + 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)); cn.listen(clisten_addr); @@ -232,7 +237,6 @@ void HotStuffApp::start() { ev_stat_timer.add_with_timeout(stat_period); LOG_INFO("** starting the system with parameters **"); LOG_INFO("blk_size = %lu", blk_size); - LOG_INFO("parent_limit = %d", parent_limit); LOG_INFO("conns = %lu", HotStuff::size()); LOG_INFO("** starting the event loop..."); HotStuff::start(); -- cgit v1.2.3