aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-05-08 15:23:47 -0400
committerDeterminant <[email protected]>2019-05-08 15:23:47 -0400
commit4661ecc2ae1684cc02bde22215200e05b15ed4d7 (patch)
treeecdf720754f4cf2d8081203bb3a2ad2484c433e6 /src
parent8e0a449961a7d78546dd09deb20f3b16bb460988 (diff)
reintroduce client confirms
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp6
-rw-r--r--src/hotstuff.cpp8
-rw-r--r--src/hotstuff_app.cpp30
-rw-r--r--src/hotstuff_client.cpp52
4 files changed, 34 insertions, 62 deletions
diff --git a/src/client.cpp b/src/client.cpp
index ee4b7dd..7090616 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -20,8 +20,8 @@ namespace hotstuff {
const opcode_t MsgReqCmd::opcode;
const opcode_t MsgRespCmd::opcode;
-#ifdef HOTSTUFF_AUTOCLI
-const opcode_t MsgDemandCmd::opcode;
-#endif
+//#ifdef HOTSTUFF_AUTOCLI
+//const opcode_t MsgDemandCmd::opcode;
+//#endif
}
diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp
index 2cc3821..d0b4139 100644
--- a/src/hotstuff.cpp
+++ b/src/hotstuff.cpp
@@ -117,10 +117,10 @@ promise_t HotStuffBase::exec_command(uint256_t cmd_hash) {
else
{
on_propose(cmds, pmaker->get_parents());
-#ifdef HOTSTUFF_AUTOCLI
- for (size_t i = pmaker->get_pending_size(); i < 1; i++)
- do_demand_commands(blk_size);
-#endif
+//#ifdef HOTSTUFF_AUTOCLI
+// for (size_t i = pmaker->get_pending_size(); i < 1; i++)
+// do_demand_commands(blk_size);
+//#endif
}
});
}
diff --git a/src/hotstuff_app.cpp b/src/hotstuff_app.cpp
index b1776f5..bc596f4 100644
--- a/src/hotstuff_app.cpp
+++ b/src/hotstuff_app.cpp
@@ -78,9 +78,9 @@ class HotStuffApp: public HotStuff {
/** The listen address for client RPC */
NetAddr clisten_addr;
-#if HOTSTUFF_CMD_RESPSIZE > 0
+//#if HOTSTUFF_CMD_RESPSIZE > 0
std::unordered_map<const uint256_t, promise_t> unconfirmed;
-#endif
+//#endif
using conn_t = ClientNetwork<opcode_t>::conn_t;
@@ -102,25 +102,25 @@ class HotStuffApp: public HotStuff {
#ifndef HOTSTUFF_ENABLE_BENCHMARK
HOTSTUFF_LOG_INFO("replicated %s", std::string(fin).c_str());
#endif
-#if HOTSTUFF_CMD_RESPSIZE > 0
+//#if HOTSTUFF_CMD_RESPSIZE > 0
auto it = unconfirmed.find(fin.cmd_hash);
if (it != unconfirmed.end())
{
it->second.resolve(fin);
unconfirmed.erase(it);
}
-#endif
+//#endif
}
-#ifdef HOTSTUFF_AUTOCLI
- void do_demand_commands(size_t blk_size) override {
- size_t ncli = client_conns.size();
- size_t bsize = (blk_size + ncli - 1) / ncli;
- hotstuff::MsgDemandCmd mdc{bsize};
- for(const auto &conn: client_conns)
- cn.send_msg(mdc, conn);
- }
-#endif
+//#ifdef HOTSTUFF_AUTOCLI
+// void do_demand_commands(size_t blk_size) override {
+// size_t ncli = client_conns.size();
+// size_t bsize = (blk_size + ncli - 1) / ncli;
+// hotstuff::MsgDemandCmd mdc{bsize};
+// for(const auto &conn: client_conns)
+// cn.send_msg(mdc, conn);
+// }
+//#endif
#ifdef HOTSTUFF_MSG_STAT
std::unordered_set<conn_t> client_conns;
@@ -313,7 +313,7 @@ void HotStuffApp::client_request_cmd_handler(MsgReqCmd &&msg, const conn_t &conn
exec_command(cmd_hash).then([this, addr](Finality fin) {
cn.send_msg(MsgRespCmd(fin), addr);
});
-#if HOTSTUFF_CMD_RESPSIZE > 0
+//#if HOTSTUFF_CMD_RESPSIZE > 0
else
{
auto it = unconfirmed.find(cmd_hash);
@@ -324,7 +324,7 @@ void HotStuffApp::client_request_cmd_handler(MsgReqCmd &&msg, const conn_t &conn
cn.send_msg(MsgRespCmd(std::move(fin)), addr);
});
}
-#endif
+//#endif
}
void HotStuffApp::start(const std::vector<std::pair<NetAddr, bytearray_t>> &reps) {
diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp
index 8eeb8e5..2c8b738 100644
--- a/src/hotstuff_client.cpp
+++ b/src/hotstuff_client.cpp
@@ -52,12 +52,10 @@ uint32_t cnt = 0;
uint32_t nfaulty;
struct Request {
- ReplicaID rid;
command_t cmd;
size_t confirmed;
salticidae::ElapsedTime et;
- Request(ReplicaID rid, const command_t &cmd):
- rid(rid), cmd(cmd), confirmed(0) { et.start(); }
+ Request(const command_t &cmd): cmd(cmd), confirmed(0) { et.start(); }
};
using Net = salticidae::MsgNetwork<opcode_t>;
@@ -73,18 +71,10 @@ void connect_all() {
conns.insert(std::make_pair(i, mn.connect(replicas[i])));
}
-void set_proposer(ReplicaID rid) {
- proposer = rid;
-// auto it = conns.find(rid);
-// if (it == conns.end())
-// conns.insert(std::make_pair(rid, mn.connect(replicas[rid])));
-}
-
bool try_send(bool check = true) {
if ((!check || waiting.size() < max_async_num) && max_iter_num)
{
auto cmd = new CommandDummy(cid, cnt++);
- //mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer));
MsgReqCmd msg(*cmd);
for (auto &p: conns) mn.send_msg(msg, p.second);
#ifndef HOTSTUFF_ENABLE_BENCHMARK
@@ -92,7 +82,7 @@ bool try_send(bool check = true) {
get_hex(cmd->get_hash()).c_str());
#endif
waiting.insert(std::make_pair(
- cmd->get_hash(), Request(proposer, cmd)));
+ cmd->get_hash(), Request(cmd)));
if (max_iter_num > 0)
max_iter_num--;
return true;
@@ -108,24 +98,7 @@ void client_resp_cmd_handler(MsgRespCmd &&msg, const Net::conn_t &) {
auto &et = it->second.et;
if (it == waiting.end()) return;
et.stop();
-// if (fin.rid != proposer)
-// {
-// HOTSTUFF_LOG_INFO("reconnect to the new proposer");
-// set_proposer(fin.rid);
-// }
-// if (fin.rid != it->second.rid)
-// {
-// mn.send_msg(MsgReqCmd(*(waiting.find(cmd_hash)->second.cmd)),
-// *conns.at(proposer));
-//#ifndef HOTSTUFF_ENABLE_BENCHMARK
-// HOTSTUFF_LOG_INFO("resend cmd %.10s",
-// get_hex(cmd_hash).c_str());
-//#endif
-// et.start();
-// it->second.rid = proposer;
-// return;
-// }
-// if (++it->second.confirmed <= nfaulty) return; // wait for f + 1 ack
+ if (++it->second.confirmed <= nfaulty) return; // wait for f + 1 ack
#ifndef HOTSTUFF_ENABLE_BENCHMARK
HOTSTUFF_LOG_INFO("got %s, wall: %.3f, cpu: %.3f",
std::string(fin).c_str(),
@@ -141,12 +114,12 @@ void client_resp_cmd_handler(MsgRespCmd &&msg, const Net::conn_t &) {
#endif
}
-#ifdef HOTSTUFF_AUTOCLI
-void client_demand_cmd_handler(hotstuff::MsgDemandCmd &&msg, const Net::conn_t &) {
- for (size_t i = 0; i < msg.ncmd; i++)
- try_send(false);
-}
-#endif
+//#ifdef HOTSTUFF_AUTOCLI
+//void client_demand_cmd_handler(hotstuff::MsgDemandCmd &&msg, const Net::conn_t &) {
+// for (size_t i = 0; i < msg.ncmd; i++)
+// try_send(false);
+//}
+//#endif
std::pair<std::string, std::string> split_ip_port_cport(const std::string &s) {
auto ret = salticidae::trim_all(salticidae::split(s, ";"));
@@ -169,9 +142,9 @@ int main(int argc, char **argv) {
ev_sigterm.add(SIGTERM);
mn.reg_handler(client_resp_cmd_handler);
-#ifdef HOTSTUFF_AUTOCLI
- mn.reg_handler(client_demand_cmd_handler);
-#endif
+//#ifdef HOTSTUFF_AUTOCLI
+// mn.reg_handler(client_demand_cmd_handler);
+//#endif
mn.start();
config.add_opt("idx", opt_idx, Config::SET_VAL);
@@ -205,7 +178,6 @@ int main(int argc, char **argv) {
nfaulty = (replicas.size() - 1) / 3;
HOTSTUFF_LOG_INFO("nfaulty = %zu", nfaulty);
connect_all();
- set_proposer(idx);
while (try_send());
ec.dispatch();