Skip to content

Commit dfdc9b6

Browse files
authored
Poe fix response (#225)
* change reponse num for poe * change reponse num for poe * add files * add files
1 parent 550d5ec commit dfdc9b6

File tree

10 files changed

+130
-7
lines changed

10 files changed

+130
-7
lines changed

platform/consensus/ordering/common/framework/performance_manager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ PerformanceManager::~PerformanceManager() {
6969

7070
int PerformanceManager::GetPrimary() { return primary_; }
7171

72+
int PerformanceManager::NeedResponse() {
73+
return config_.GetMinClientReceiveNum(); // f+1;
74+
}
75+
7276
std::unique_ptr<Request> PerformanceManager::GenerateUserRequest() {
7377
std::unique_ptr<Request> request = std::make_unique<Request>();
7478
request->set_data(data_func_());
@@ -154,7 +158,7 @@ CollectorResultCode PerformanceManager::AddResponseMsg(
154158
return CollectorResultCode::OK;
155159
}
156160
response_[idx][seq]++;
157-
if (response_[idx][seq] >= config_.GetMinClientReceiveNum()) {
161+
if (response_[idx][seq] >= NeedResponse()) {
158162
response_[idx].erase(response_[idx].find(seq));
159163
done = true;
160164
}

platform/consensus/ordering/common/framework/performance_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class PerformanceManager {
4646

4747
protected:
4848
virtual void SendMessage(const Request& request);
49+
virtual int NeedResponse();
4950

5051
private:
5152
// Add response messages which will be sent back to the caller

platform/consensus/ordering/pbft/checkpoint_manager_test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class CheckPointManagerTest : public Test {
108108
TEST_F(CheckPointManagerTest, SendCheckPoint) {
109109
config_.SetViewchangeCommitTimeout(100);
110110
SystemInfo sys_info;
111-
CheckPointManager manager(config_, &replica_communicator_, nullptr, &sys_info);
111+
CheckPointManager manager(config_, &replica_communicator_, nullptr,
112+
&sys_info);
112113

113114
for (int i = 1; i <= 5; ++i) {
114115
std::unique_ptr<Request> request = std::make_unique<Request>();
@@ -135,7 +136,8 @@ TEST_F(CheckPointManagerTest, SendCheckPointOnce) {
135136
}));
136137

137138
SystemInfo sys_info;
138-
CheckPointManager manager(config_, &replica_communicator_, nullptr, &sys_info);
139+
CheckPointManager manager(config_, &replica_communicator_, nullptr,
140+
&sys_info);
139141
for (int i = 1; i <= 5; ++i) {
140142
std::unique_ptr<Request> request = std::make_unique<Request>();
141143
request->set_seq(i);
@@ -163,7 +165,8 @@ TEST_F(CheckPointManagerTest, SendCheckPointTwo) {
163165
}));
164166

165167
SystemInfo sys_info;
166-
CheckPointManager manager(config_, &replica_communicator_, nullptr, &sys_info);
168+
CheckPointManager manager(config_, &replica_communicator_, nullptr,
169+
&sys_info);
167170
std::unique_ptr<Request> request = std::make_unique<Request>();
168171
for (int i = 1; i <= 5; ++i) {
169172
std::unique_ptr<Request> request = std::make_unique<Request>();
@@ -261,7 +264,8 @@ TEST_F(CheckPointManagerTest, Votes) {
261264
std::future<bool> propose_done_future = propose_done.get_future();
262265

263266
SystemInfo sys_info;
264-
CheckPointManager manager(config_, &replica_communicator_, &mock_verifier, &sys_info);
267+
CheckPointManager manager(config_, &replica_communicator_, &mock_verifier,
268+
&sys_info);
265269
EXPECT_CALL(replica_communicator_, BroadCast)
266270
.WillRepeatedly(Invoke([&](const google::protobuf::Message& message) {
267271
for (int i = 1; i <= 3; ++i) {

platform/consensus/ordering/pbft/commitment_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class CommitmentTest : public Test {
5858
global_stats_(Stats::GetGlobalStats(1)),
5959
config_(GenerateConfig()),
6060
system_info_(config_),
61-
checkpoint_manager_(config_, &replica_communicator_, &verifier_, &system_info_),
61+
checkpoint_manager_(config_, &replica_communicator_, &verifier_,
62+
&system_info_),
6263
message_manager_(std::make_unique<MessageManager>(
6364
config_, nullptr, &checkpoint_manager_, &system_info_)),
6465
commitment_(

platform/consensus/ordering/pbft/query_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class QueryTest : public Test {
5959
: global_stats_(Stats::GetGlobalStats(1)),
6060
config_(GenerateConfig()),
6161
system_info_(config_),
62-
checkpoint_manager_(config_, &replica_communicator_, nullptr, &system_info_),
62+
checkpoint_manager_(config_, &replica_communicator_, nullptr,
63+
&system_info_),
6364
message_manager_(config_, nullptr, &checkpoint_manager_, &system_info_),
6465
recovery_(config_, &checkpoint_manager_, &system_info_, nullptr),
6566
query_(config_, &recovery_),

platform/consensus/ordering/poe/framework/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@ cc_library(
2626
"//visibility:public",
2727
],
2828
deps = [
29+
":performance_manager",
2930
"//common/utils",
3031
"//platform/consensus/ordering/common/framework:consensus",
3132
"//platform/consensus/ordering/poe/algorithm:poe",
3233
],
3334
)
35+
36+
cc_library(
37+
name = "performance_manager",
38+
srcs = ["performance_manager.cpp"],
39+
hdrs = ["performance_manager.h"],
40+
deps = [
41+
"//platform/consensus/ordering/common/framework:performance_manager",
42+
"//platform/consensus/ordering/poe/proto:proposal_cc_proto",
43+
],
44+
)

platform/consensus/ordering/poe/framework/consensus.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,26 @@
2727
namespace resdb {
2828
namespace poe {
2929

30+
std::unique_ptr<PoEPerformanceManager> Consensus::GetPerformanceManager() {
31+
return config_.IsPerformanceRunning()
32+
? std::make_unique<PoEPerformanceManager>(
33+
config_, GetBroadCastClient(), GetSignatureVerifier())
34+
: nullptr;
35+
}
36+
3037
Consensus::Consensus(const ResDBConfig& config,
3138
std::unique_ptr<TransactionManager> executor)
3239
: common::Consensus(config, std::move(executor)) {
3340
int total_replicas = config_.GetReplicaNum();
3441
int f = (total_replicas - 1) / 3;
3542

43+
if (config_.GetPublicKeyCertificateInfo()
44+
.public_key()
45+
.public_key_info()
46+
.type() == CertificateKeyInfo::CLIENT) {
47+
SetPerformanceManager(GetPerformanceManager());
48+
}
49+
3650
Init();
3751

3852
start_ = 0;

platform/consensus/ordering/poe/framework/consensus.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "executor/common/transaction_manager.h"
2323
#include "platform/consensus/ordering/common/framework/consensus.h"
2424
#include "platform/consensus/ordering/poe/algorithm/poe.h"
25+
#include "platform/consensus/ordering/poe/framework/performance_manager.h"
2526
#include "platform/networkstrate/consensus_manager.h"
2627

2728
namespace resdb {
@@ -41,6 +42,8 @@ class Consensus : public common::Consensus {
4142

4243
int Prepare(const Transaction& txn);
4344

45+
std::unique_ptr<PoEPerformanceManager> GetPerformanceManager();
46+
4447
protected:
4548
std::unique_ptr<PoE> poe_;
4649
Stats* global_stats_;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "platform/consensus/ordering/poe/framework/performance_manager.h"
21+
22+
#include <glog/logging.h>
23+
24+
#include "common/utils/utils.h"
25+
26+
namespace resdb {
27+
namespace poe {
28+
29+
using comm::CollectorResultCode;
30+
31+
PoEPerformanceManager::PoEPerformanceManager(
32+
const ResDBConfig& config, ReplicaCommunicator* replica_communicator,
33+
SignatureVerifier* verifier)
34+
: PerformanceManager(config, replica_communicator, verifier) {
35+
f_ = config_.GetMaxMaliciousReplicaNum();
36+
}
37+
38+
int PoEPerformanceManager::NeedResponse() { return 2 * f_ + 1; }
39+
40+
} // namespace poe
41+
} // namespace resdb
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <thread>
23+
24+
#include "platform/consensus/ordering/common/framework/performance_manager.h"
25+
#include "platform/consensus/ordering/poe/proto/proposal.pb.h"
26+
27+
namespace resdb {
28+
namespace poe {
29+
30+
class PoEPerformanceManager : public common::PerformanceManager {
31+
public:
32+
PoEPerformanceManager(const ResDBConfig& config,
33+
ReplicaCommunicator* replica_communicator,
34+
SignatureVerifier* verifier);
35+
36+
int NeedResponse() override;
37+
38+
private:
39+
int f_;
40+
};
41+
42+
} // namespace poe
43+
} // namespace resdb

0 commit comments

Comments
 (0)