aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2018-08-21 21:58:40 -0400
committerDeterminant <[email protected]>2018-08-21 21:58:40 -0400
commit69208d4931f45911e401a97ba9b019a2ffdfe82c (patch)
tree5bdcb23c028b8108963a6ea6379fcabe49b74e6d /src
parent3b7801dcfd573858e9a8f27abe890def47ece2ad (diff)
use randomized initial cnt to avoid duplicate command
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp2
-rw-r--r--src/hotstuff_client.cpp12
2 files changed, 11 insertions, 3 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 562fab5..7827b7c 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -2,8 +2,6 @@
namespace hotstuff {
-uint64_t CommandDummy::cnt = 0;
-
const opcode_t MsgReqCmd::opcode;
MsgReqCmd::MsgReqCmd(const Command &cmd) { serialized << cmd; }
void MsgReqCmd::postponed_parse(HotStuffCore *hsc) {
diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp
index f925b73..97c5dc5 100644
--- a/src/hotstuff_client.cpp
+++ b/src/hotstuff_client.cpp
@@ -1,4 +1,5 @@
#include <cassert>
+#include <random>
#include "salticidae/type.h"
#include "salticidae/netaddr.h"
#include "salticidae/network.h"
@@ -27,6 +28,8 @@ EventContext eb;
ReplicaID proposer;
size_t max_async_num;
int max_iter_num;
+uint64_t cnd_stride;
+uint64_t cnt;
struct Request {
ReplicaID rid;
@@ -51,7 +54,8 @@ void set_proposer(ReplicaID rid) {
void try_send() {
while (waiting.size() < max_async_num && max_iter_num)
{
- auto cmd = CommandDummy::make_cmd();
+ auto cmd = new CommandDummy(cnt);
+ cnt += cnd_stride;
mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer));
#ifndef HOTSTUFF_ENABLE_BENCHMARK
HOTSTUFF_LOG_INFO("send new cmd %.10s",
@@ -106,11 +110,15 @@ std::pair<std::string, std::string> 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);
mn.reg_handler(client_resp_cmd_handler);
@@ -119,8 +127,10 @@ int main(int argc, char **argv) {
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<std::pair<std::string, std::string>> raw;