From 69208d4931f45911e401a97ba9b019a2ffdfe82c Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 21 Aug 2018 21:58:40 -0400 Subject: use randomized initial cnt to avoid duplicate command --- include/hotstuff/client.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'include/hotstuff/client.h') diff --git a/include/hotstuff/client.h b/include/hotstuff/client.h index 92b4eec..614b654 100644 --- a/include/hotstuff/client.h +++ b/include/hotstuff/client.h @@ -26,7 +26,6 @@ struct MsgRespCmd { }; class CommandDummy: public Command { - static uint64_t cnt; uint64_t n; uint256_t hash; @@ -39,10 +38,6 @@ class CommandDummy: public Command { CommandDummy(uint64_t n): n(n), hash(salticidae::get_hash(*this)) {} - static command_t make_cmd() { - return new CommandDummy(cnt++); - } - void serialize(DataStream &s) const override { s << n; } -- cgit v1.2.3-70-g09d2 From 51796ba2e778001948f4cd5acb51e31fcaec0641 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 21 Aug 2018 22:25:00 -0400 Subject: use cid instead of randomization --- include/hotstuff/client.h | 11 ++++++----- src/hotstuff_client.cpp | 16 ++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'include/hotstuff/client.h') diff --git a/include/hotstuff/client.h b/include/hotstuff/client.h index 614b654..447a9db 100644 --- a/include/hotstuff/client.h +++ b/include/hotstuff/client.h @@ -26,7 +26,8 @@ struct MsgRespCmd { }; class CommandDummy: public Command { - uint64_t n; + uint32_t cid; + uint32_t n; uint256_t hash; public: @@ -35,15 +36,15 @@ class CommandDummy: public Command { ~CommandDummy() override {} - CommandDummy(uint64_t n): - n(n), hash(salticidae::get_hash(*this)) {} + CommandDummy(uint32_t cid, uint32_t n): + cid(cid), n(n), hash(salticidae::get_hash(*this)) {} void serialize(DataStream &s) const override { - s << n; + s << cid << n; } void unserialize(DataStream &s) override { - s >> n; + s >> cid >> n; hash = salticidae::get_hash(*this); } diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index 97c5dc5..62b13ed 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -28,8 +28,8 @@ EventContext eb; ReplicaID proposer; size_t max_async_num; int max_iter_num; -uint64_t cnd_stride; -uint64_t cnt; +uint32_t cid; +uint32_t cnt = 0; struct Request { ReplicaID rid; @@ -54,8 +54,7 @@ void set_proposer(ReplicaID rid) { void try_send() { while (waiting.size() < max_async_num && max_iter_num) { - auto cmd = new CommandDummy(cnt); - cnt += cnd_stride; + auto cmd = new CommandDummy(cid, cnt++); mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer)); #ifndef HOTSTUFF_ENABLE_BENCHMARK HOTSTUFF_LOG_INFO("send new cmd %.10s", @@ -110,27 +109,23 @@ std::pair split_ip_port_cport(const std::string &s) { } int main(int argc, char **argv) { - cnt = std::random_device()(); - HOTSTUFF_LOG_INFO("init cnt = %lu", cnt); - Config config("hotstuff.conf"); auto opt_idx = Config::OptValInt::create(0); auto opt_replicas = Config::OptValStrVec::create(); auto opt_max_iter_num = Config::OptValInt::create(100); auto opt_max_async_num = Config::OptValInt::create(10); - auto opt_cnt_stride = Config::OptValInt::create(1000); + auto opt_cid = Config::OptValInt::create(-1); mn.reg_handler(client_resp_cmd_handler); try { config.add_opt("idx", opt_idx, Config::SET_VAL); + config.add_opt("cid", opt_cid, Config::SET_VAL); config.add_opt("replica", opt_replicas, Config::APPEND); config.add_opt("iter", opt_max_iter_num, Config::SET_VAL); config.add_opt("max-async", opt_max_async_num, Config::SET_VAL); - config.add_opt("cnt-stride", opt_cnt_stride, Config::SET_VAL); config.parse(argc, argv); auto idx = opt_idx->get(); - cnd_stride = opt_cnt_stride->get(); max_iter_num = opt_max_iter_num->get(); max_async_num = opt_max_async_num->get(); std::vector> raw; @@ -144,6 +139,7 @@ int main(int argc, char **argv) { if (!(0 <= idx && (size_t)idx < raw.size() && raw.size() > 0)) throw std::invalid_argument("out of range"); + cid = opt_cid->get() != -1 ? opt_cid->get() : idx; for (const auto &p: raw) { auto _p = split_ip_port_cport(p.first); -- cgit v1.2.3-70-g09d2