Skip to content

Commit

Permalink
add poe (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcchen authored Apr 10, 2024
1 parent 69069c8 commit fe73ffa
Show file tree
Hide file tree
Showing 31 changed files with 1,924 additions and 9 deletions.
16 changes: 16 additions & 0 deletions benchmark/protocols/poe/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package(default_visibility = ["//visibility:private"])

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

cc_binary(
name = "kv_server_performance",
srcs = ["kv_server_performance.cpp"],
deps = [
"//chain/storage:memory_db",
"//executor/kv:kv_executor",
"//platform/config:resdb_config_utils",
"//platform/consensus/ordering/poe/framework:consensus",
"//service/utils:server_factory",
],
)

89 changes: 89 additions & 0 deletions benchmark/protocols/poe/kv_server_performance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2019-2022 ExpoLab, UC Davis
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

#include <glog/logging.h>

#include "chain/storage/memory_db.h"
#include "executor/kv/kv_executor.h"
#include "platform/config/resdb_config_utils.h"
#include "platform/consensus/ordering/poe/framework/consensus.h"
#include "platform/networkstrate/service_network.h"
#include "platform/statistic/stats.h"
#include "proto/kv/kv.pb.h"

using namespace resdb;
using namespace resdb::poe;
using namespace resdb::storage;

void ShowUsage() {
printf("<config> <private_key> <cert_file> [logging_dir]\n");
}

std::string GetRandomKey() {
int num1 = rand() % 10;
int num2 = rand() % 10;
return std::to_string(num1) + std::to_string(num2);
}

int main(int argc, char** argv) {
if (argc < 3) {
ShowUsage();
exit(0);
}

// google::InitGoogleLogging(argv[0]);
// FLAGS_minloglevel = google::GLOG_WARNING;

char* config_file = argv[1];
char* private_key_file = argv[2];
char* cert_file = argv[3];

if (argc >= 5) {
auto monitor_port = Stats::GetGlobalStats(5);
monitor_port->SetPrometheus(argv[4]);
}

std::unique_ptr<ResDBConfig> config =
GenerateResDBConfig(config_file, private_key_file, cert_file);

config->RunningPerformance(true);
ResConfigData config_data = config->GetConfigData();

auto performance_consens = std::make_unique<Consensus>(
*config, std::make_unique<KVExecutor>(std::make_unique<MemoryDB>()));
performance_consens->SetupPerformanceDataFunc([]() {
KVRequest request;
request.set_cmd(KVRequest::SET);
request.set_key(GetRandomKey());
request.set_value("helloword");
std::string request_data;
request.SerializeToString(&request_data);
return request_data;
});

auto server =
std::make_unique<ServiceNetwork>(*config, std::move(performance_consens));
server->Run();
}
1 change: 1 addition & 0 deletions platform/consensus/execution/transaction_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ void TransactionExecutor::Execute(std::unique_ptr<Request> request,
response = std::make_unique<BatchUserResponse>();
}

response->set_proxy_id(batch_request.proxy_id());
response->set_createtime(batch_request.createtime());
response->set_local_id(batch_request.local_id());
response->set_hash(batch_request.hash());
Expand Down
12 changes: 12 additions & 0 deletions platform/consensus/ordering/common/algorithm/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package(default_visibility = ["//platform/consensus/ordering:__subpackages__"])

cc_library(
name = "protocol_base",
srcs = ["protocol_base.cpp"],
hdrs = ["protocol_base.h"],
deps = [
"//common:comm",
"//common/crypto:signature_verifier",
],
)

53 changes: 53 additions & 0 deletions platform/consensus/ordering/common/algorithm/protocol_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "platform/consensus/ordering/common/algorithm/protocol_base.h"

#include <glog/logging.h>

namespace resdb {
namespace common {

ProtocolBase::ProtocolBase(
int id,
int f,
int total_num,
SingleCallFuncType single_call,
BroadcastCallFuncType broadcast_call,
CommitFuncType commit) :
id_(id),
f_(f),
total_num_(total_num),
single_call_(single_call),
broadcast_call_(broadcast_call),
commit_(commit) {
stop_ = false;
}

ProtocolBase::ProtocolBase( int id, int f, int total_num) : ProtocolBase(id, f, total_num, nullptr, nullptr, nullptr){

}

ProtocolBase::~ProtocolBase() {
Stop();
}

void ProtocolBase::Stop(){
stop_ = true;
}

bool ProtocolBase::IsStop(){
return stop_;
}

int ProtocolBase::SendMessage(int msg_type, const google::protobuf::Message& msg, int node_id) {
return single_call_(msg_type, msg, node_id);
}

int ProtocolBase::Broadcast(int msg_type, const google::protobuf::Message& msg) {
return broadcast_call_(msg_type, msg);
}

int ProtocolBase::Commit(const google::protobuf::Message& msg) {
return commit_(msg);
}

} // namespace protocol
} // namespace resdb
64 changes: 64 additions & 0 deletions platform/consensus/ordering/common/algorithm/protocol_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once

#include <functional>
#include <google/protobuf/message.h>
#include "common/crypto/signature_verifier.h"

namespace resdb {
namespace common {

class ProtocolBase {
public:
typedef std::function<int(int, const google::protobuf::Message& msg, int)> SingleCallFuncType;
typedef std::function<int(int, const google::protobuf::Message& msg)> BroadcastCallFuncType;
typedef std::function<int(const google::protobuf::Message& msg)> CommitFuncType;

ProtocolBase(
int id,
int f,
int total_num,
SingleCallFuncType single_call,
BroadcastCallFuncType broadcast_call,
CommitFuncType commit
);

ProtocolBase( int id, int f, int total_num);


virtual ~ProtocolBase();

void Stop();

inline
void SetSingleCallFunc(SingleCallFuncType single_call) { single_call_ = single_call; }

inline
void SetBroadcastCallFunc(BroadcastCallFuncType broadcast_call) { broadcast_call_ = broadcast_call; }

inline
void SetCommitFunc(CommitFuncType commit_func) { commit_ = commit_func; }

inline
void SetSignatureVerifier(SignatureVerifier* verifier) { verifier_ = verifier;}

protected:
int SendMessage(int msg_type, const google::protobuf::Message& msg, int node_id);
int Broadcast(int msg_type, const google::protobuf::Message& msg);
int Commit(const google::protobuf::Message& msg);

bool IsStop();

protected:
int id_;
int f_;
int total_num_;
std::function<int(int, const google::protobuf::Message& msg, int)> single_call_;
std::function<int(int, const google::protobuf::Message& msg)> broadcast_call_;
std::function<int(const google::protobuf::Message& msg)> commit_;
std::atomic<bool> stop_;

SignatureVerifier* verifier_;
};

} // namespace protocol
} // namespace resdb
49 changes: 49 additions & 0 deletions platform/consensus/ordering/common/framework/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package(default_visibility = ["//platform/consensus/ordering:__subpackages__"])

cc_library(
name = "consensus",
srcs = ["consensus.cpp"],
hdrs = ["consensus.h"],
deps = [
":performance_manager",
":response_manager",
"//common/utils",
"//executor/common:transaction_manager",
"//platform/consensus/execution:transaction_executor",
"//platform/consensus/ordering/common/algorithm:protocol_base",
"//platform/networkstrate:consensus_manager",
],
)

cc_library(
name = "performance_manager",
srcs = ["performance_manager.cpp"],
hdrs = ["performance_manager.h"],
deps = [
":transaction_utils",
"//platform/networkstrate:replica_communicator",
"//platform/networkstrate:server_comm",
],
)


cc_library(
name = "response_manager",
srcs = ["response_manager.cpp"],
hdrs = ["response_manager.h"],
deps = [
":transaction_utils",
"//platform/networkstrate:replica_communicator",
"//platform/networkstrate:server_comm",
],
)

cc_library(
name = "transaction_utils",
srcs = ["transaction_utils.cpp"],
hdrs = ["transaction_utils.h"],
visibility = ["//visibility:public"],
deps = [
"//platform/proto:resdb_cc_proto",
],
)
Loading

0 comments on commit fe73ffa

Please sign in to comment.