Skip to content

Commit d6d908d

Browse files
committed
Redirect pruning signature generation/verification to SigManager
1 parent 5d9d14d commit d6d908d

File tree

20 files changed

+251
-250
lines changed

20 files changed

+251
-250
lines changed

Makefile

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,17 @@ else
4949
TCP_ENABLED__:=OFF
5050
endif
5151

52-
CONCORD_BFT_CMAKE_CXX_FLAGS_RELEASE?='-O3 -g'
53-
CONCORD_BFT_CMAKE_USE_LOG4CPP?=ON
54-
CONCORD_BFT_CMAKE_BUILD_UTT?=TRUE
55-
CONCORD_BFT_CMAKE_BUILD_ROCKSDB_STORAGE?=TRUE
56-
CONCORD_BFT_CMAKE_USE_S3_OBJECT_STORE?=TRUE
57-
CONCORD_BFT_CMAKE_USE_OPENTRACING?=TRUE
58-
CONCORD_BFT_CMAKE_USE_PROMETHEUS?=TRUE
59-
CONCORD_BFT_CMAKE_USE_JAEGER?=TRUE
60-
CONCORD_BFT_CMAKE_USE_JSON?=TRUE
61-
CONCORD_BFT_CMAKE_USE_HTTPLIB?=TRUE
62-
CONCORD_BFT_CMAKE_EXPORT_COMPILE_COMMANDS?=TRUE
63-
CONCORD_BFT_CMAKE_OMIT_TEST_OUTPUT?=FALSE
64-
CONCORD_BFT_CMAKE_KEEP_APOLLO_LOGS?=TRUE
65-
CONCORD_BFT_CMAKE_RUN_APOLLO_TESTS?=TRUE
66-
CONCORD_BFT_CMAKE_TRANSACTION_SIGNING_ENABLED?=TRUE
67-
CONCORD_BFT_CMAKE_BUILD_SLOWDOWN?=FALSE
68-
# Only useful with CONCORD_BFT_CMAKE_BUILD_TYPE:=Release
69-
CONCORD_BFT_CMAKE_BUILD_KVBC_BENCH?=TRUE
70-
# Only usefull with CONCORD_BFT_CMAKE_CXX_FLAGS_RELEASE=-O0 -g
71-
CONCORD_BFT_CMAKE_ASAN?=FALSE
72-
CONCORD_BFT_CMAKE_TSAN?=FALSE
73-
CONCORD_BFT_CMAKE_UBSAN?=FALSE
74-
CONCORD_BFT_CMAKE_HEAPTRACK?=FALSE
75-
CONCORD_BFT_CMAKE_CODECOVERAGE?=FALSE
76-
CONCORD_BFT_CMAKE_CCACHE?=TRUE
77-
CONCORD_BFT_CMAKE_USE_FAKE_CLOCK_IN_TIME_SERVICE?=FALSE
78-
ENABLE_RESTART_RECOVERY_TESTS?=FALSE
79-
CONCORD_ENABLE_ALL_METRICS?=FALSE
52+
CONCORD_BFT_CMAKE_BUILD_UTT?=ON
53+
CONCORD_BFT_CMAKE_OMIT_TEST_OUTPUT?=OFF
54+
CONCORD_BFT_CMAKE_KEEP_APOLLO_LOGS?=ON
55+
CONCORD_BFT_CMAKE_RUN_APOLLO_TESTS?=ON
56+
CONCORD_BFT_CMAKE_ASAN?=OFF
57+
CONCORD_BFT_CMAKE_TSAN?=OFF
58+
CONCORD_BFT_CMAKE_UBSAN?=OFF
59+
CONCORD_BFT_CMAKE_HEAPTRACK?=OFF
60+
CONCORD_BFT_CMAKE_CODECOVERAGE?=OFF
61+
CONCORD_BFT_CMAKE_CCACHE?=ON
62+
ENABLE_RESTART_RECOVERY_TESTS?=OFF
8063

8164
# Our CMake logic won't allow more one of these flags to be raised, so having this if/else logic makes sense
8265
ifeq (${CONCORD_BFT_CMAKE_ASAN},ON)

bftengine/include/bftengine/ReplicaConfig.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ class ReplicaConfig : public concord::serialize::SerializableFactory<ReplicaConf
306306
if (auto it = config_params_.find(param); it != config_params_.end()) return concord::util::to<T>(it->second);
307307
return defaultValue;
308308
}
309-
inline std::set<std::pair<const std::string, std::set<uint16_t>>>* getPublicKeysOfClients() {
309+
inline const std::set<std::pair<const std::string, std::set<uint16_t>>>* getPublicKeysOfClients() const {
310310
return (clientTransactionSigningEnabled || !clientsKeysPrefix.empty()) ? &publicKeysOfClients : nullptr;
311311
}
312312

313-
std::string getOperatorPublicKey() {
313+
std::string getOperatorPublicKey() const {
314314
std::ifstream op_key_file(pathToOperatorPublicKey_);
315315
if (!op_key_file.fail()) {
316316
std::stringstream buffer;

bftengine/src/bftengine/ReplicaBase.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class ReplicaBase {
112112
static const uint16_t ALL_OTHER_REPLICAS = UINT16_MAX;
113113

114114
const ReplicaConfig& config_;
115-
ReplicasInfo* repsInfo = nullptr;
115+
const ReplicasInfo* repsInfo = nullptr;
116116
std::shared_ptr<MsgsCommunicator> msgsCommunicator_;
117117
std::shared_ptr<MsgHandlersRegistrator> msgHandlers_;
118118
std::shared_ptr<IRequestsHandler> bftRequestsHandler_;

bftengine/src/bftengine/ReplicaImp.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,16 +4434,7 @@ ReplicaImp::ReplicaImp(bool firstTime,
44344434

44354435
if (firstTime) {
44364436
repsInfo = new ReplicasInfo(config_, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs);
4437-
sigManager_ = SigManager::init(config_.replicaId,
4438-
config_.replicaPrivateKey,
4439-
config_.publicKeysOfReplicas,
4440-
concord::crypto::KeyFormat::HexaDecimalStrippedFormat,
4441-
ReplicaConfig::instance().getPublicKeysOfClients(),
4442-
concord::crypto::KeyFormat::PemFormat,
4443-
{{repsInfo->getIdOfOperator(),
4444-
ReplicaConfig::instance().getOperatorPublicKey(),
4445-
concord::crypto::KeyFormat::PemFormat}},
4446-
*repsInfo);
4437+
sigManager_ = SigManager::owningInstance();
44474438
viewsManager = new ViewsManager(repsInfo);
44484439
} else {
44494440
repsInfo = replicasInfo;

bftengine/src/bftengine/ReplicaLoader.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,14 @@ namespace impl {
4747
namespace {
4848

4949
ReplicaLoader::ErrorCode loadConfig(LoadedReplicaData &ld) {
50-
ld.repsInfo = new ReplicasInfo(ld.repConfig, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs);
5150
auto &config = ld.repConfig;
52-
ld.sigManager = SigManager::init(config.replicaId,
53-
config.replicaPrivateKey,
54-
config.publicKeysOfReplicas,
55-
concord::crypto::KeyFormat::HexaDecimalStrippedFormat,
56-
ReplicaConfig::instance().getPublicKeysOfClients(),
57-
concord::crypto::KeyFormat::PemFormat,
58-
{{ld.repsInfo->getIdOfOperator(),
59-
ReplicaConfig::instance().getOperatorPublicKey(),
60-
concord::crypto::KeyFormat::PemFormat}},
61-
*ld.repsInfo);
62-
63-
std::unique_ptr<Cryptosystem> cryptoSys = std::make_unique<Cryptosystem>(ld.repConfig.thresholdSystemType_,
64-
ld.repConfig.thresholdSystemSubType_,
65-
ld.repConfig.numReplicas,
66-
ld.repConfig.numReplicas);
67-
cryptoSys->loadKeys(ld.repConfig.thresholdPublicKey_, ld.repConfig.thresholdVerificationKeys_);
68-
cryptoSys->loadPrivateKey(ld.repConfig.replicaId, ld.repConfig.thresholdPrivateKey_);
51+
ld.repsInfo = new ReplicasInfo(config, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs);
52+
ld.sigManager = SigManager::owningInstance();
53+
54+
std::unique_ptr<Cryptosystem> cryptoSys = std::make_unique<Cryptosystem>(
55+
config.thresholdSystemType_, config.thresholdSystemSubType_, config.numReplicas, config.numReplicas);
56+
cryptoSys->loadKeys(config.thresholdPublicKey_, config.thresholdVerificationKeys_);
57+
cryptoSys->loadPrivateKey(config.replicaId, config.thresholdPrivateKey_);
6958
bftEngine::CryptoManager::init(std::move(cryptoSys));
7059

7160
return Succ;

bftengine/src/bftengine/ReplicasInfo.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ ReplicasInfo::ReplicasInfo(const ReplicaConfig& config,
146146
}
147147
if (start != end) LOG_INFO(GL, "Principal ids in _idsOfInternalClients: " << start << " to " << end - 1);
148148
return ret;
149-
}()} {
150-
_operator_id = config.operatorEnabled_
151-
? static_cast<PrincipalId>(config.numReplicas + config.numRoReplicas + config.numOfClientProxies +
152-
config.numOfExternalClients + config.numOfClientServices - 1)
153-
: 0;
149+
}()},
150+
151+
_operator_id{static_cast<PrincipalId>(
152+
config.operatorEnabled_ ? config.numReplicas + config.numRoReplicas + config.numOfClientProxies +
153+
config.numOfExternalClients + config.numOfClientServices - 1
154+
: 0)} {
154155
ConcordAssert(_numberOfReplicas == (3 * _fVal + 2 * _cVal + 1));
155156
}
156157

bftengine/src/bftengine/ReplicasInfo.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class ReplicaConfig;
2020

2121
namespace impl {
2222

23+
/**
24+
* An immutable class holding the the ids of all the participants in the network
25+
*/
2326
class ReplicasInfo {
2427
public:
2528
ReplicasInfo(const ReplicaConfig&, bool dynamicCollectorForPartialProofs, bool dynamicCollectorForExecutionProofs);
@@ -110,7 +113,7 @@ class ReplicasInfo {
110113
const std::set<PrincipalId> _idsOfInternalClients;
111114

112115
// Currently we support only a single operator entity in the system
113-
PrincipalId _operator_id;
116+
const PrincipalId _operator_id = 0;
114117
};
115118
} // namespace impl
116119
} // namespace bftEngine

bftengine/src/bftengine/SigManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ SigManager* SigManager::instance() {
4747
return s_sm.get();
4848
}
4949

50+
std::shared_ptr<SigManager> SigManager::owningInstance() {
51+
ConcordAssertNE(s_sm.get(), nullptr);
52+
return s_sm;
53+
}
54+
5055
void SigManager::reset(std::shared_ptr<SigManager> other) { s_sm = other; }
5156

5257
std::shared_ptr<SigManager> SigManager::init(
@@ -457,6 +462,7 @@ SeqNum SigManager::getReplicaLastExecutedSeq() const {
457462
ConcordAssert(replicasInfo_.isIdOfReplica(myId_) || replicasInfo_.isRoReplica());
458463
return replicaLastExecutedSeq_;
459464
}
465+
const ReplicasInfo& SigManager::getReplicasInfo() const { return replicasInfo_; }
460466

461467
} // namespace impl
462468
} // namespace bftEngine

bftengine/src/bftengine/SigManager.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "crypto/signer.hpp"
2020
#include "crypto/verifier.hpp"
2121
#include "SysConsts.hpp"
22+
#include "ReplicasInfo.hpp"
2223
#include <utility>
2324
#include <vector>
2425
#include <map>
@@ -35,15 +36,14 @@ class IThresholdVerifier;
3536
namespace bftEngine {
3637
namespace impl {
3738

38-
class ReplicasInfo;
39-
4039
class SigManager {
4140
public:
4241
using Key = std::string;
4342
using KeyIndex = uint16_t;
4443

4544
virtual ~SigManager() = default;
4645
static SigManager* instance();
46+
static std::shared_ptr<SigManager> owningInstance();
4747
static void reset(std::shared_ptr<SigManager> other);
4848

4949
// It is the caller responsibility to deallocate (delete) the object
@@ -129,6 +129,8 @@ class SigManager {
129129
const concord::crypto::IVerifier& extractVerifierFromMultisig(std::shared_ptr<IThresholdVerifier> thresholdVerifier,
130130
PrincipalId id) const;
131131

132+
const ReplicasInfo& getReplicasInfo() const;
133+
132134
protected:
133135
static constexpr uint16_t updateMetricsAggregatorThresh = 1000;
134136

@@ -153,7 +155,7 @@ class SigManager {
153155
std::unique_ptr<concord::crypto::ISigner> mySigner_;
154156
std::map<PrincipalId, std::shared_ptr<concord::crypto::IVerifier>> verifiers_;
155157
bool clientTransactionSigningEnabled_ = true;
156-
const ReplicasInfo& replicasInfo_;
158+
const ReplicasInfo replicasInfo_;
157159

158160
// The ownership model of a SigManager object depends on its use
159161
static std::shared_ptr<SigManager> s_sm;

kvbc/include/pruning_handler.hpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PruningSigner {
3232
public:
3333
// Construct by passing the configuration for the node the signer is running
3434
// on.
35-
PruningSigner(const std::string &key);
35+
PruningSigner();
3636
// Sign() methods sign the passed message and store the signature in the
3737
// 'signature' field of the message. An exception is thrown on error.
3838
//
@@ -41,9 +41,6 @@ class PruningSigner {
4141
// application-level signature rather than a Concord-BFT Principal's RSA/EdDSA
4242
// signature.
4343
void sign(concord::messages::LatestPrunableBlock &);
44-
45-
private:
46-
std::unique_ptr<concord::crypto::ISigner> signer_;
4744
};
4845

4946
// This class verifies pruning messages that were signed by serializing message
@@ -55,7 +52,7 @@ class PruningSigner {
5552
class PruningVerifier {
5653
public:
5754
// Construct by passing the system configuration.
58-
PruningVerifier(const std::set<std::pair<uint16_t, const std::string>> &replicasPublicKeys);
55+
PruningVerifier();
5956
// Verify() methods verify that the message comes from the advertised sender.
6057
// Methods return true on successful verification and false on unsuccessful.
6158
// An exception is thrown on error.
@@ -76,22 +73,6 @@ class PruningVerifier {
7673
};
7774

7875
bool verify(std::uint64_t sender, const std::string &ser, const std::string &signature) const;
79-
80-
using ReplicaVector = std::vector<Replica>;
81-
82-
// Get a replica from the replicas vector by its index.
83-
const Replica &getReplica(ReplicaVector::size_type idx) const;
84-
85-
// A vector of all the replicas in the system.
86-
ReplicaVector replicas_;
87-
// We map a principal_id to a replica index in the replicas_ vector to be able
88-
// to verify a message through the Replica's verifier that is associated with
89-
// its public key.
90-
std::unordered_map<std::uint64_t, ReplicaVector::size_type> principal_to_replica_idx_;
91-
92-
// Contains a set of replica principal_ids for use in verification. Filled in
93-
// once during construction.
94-
std::unordered_set<std::uint64_t> replica_ids_;
9576
};
9677
class PruningHandler : public concord::reconfiguration::OperatorCommandsReconfigurationHandler {
9778
// This class implements the KVB pruning state machine. Main functionalities
@@ -171,7 +152,6 @@ class PruningHandler : public concord::reconfiguration::OperatorCommandsReconfig
171152
// Throws on errors.
172153
void pruneThroughBlockId(kvbc::BlockId block_id) const;
173154
uint64_t getBlockBftSequenceNumber(kvbc::BlockId) const;
174-
logging::Logger logger_;
175155
PruningSigner signer_;
176156
PruningVerifier verifier_;
177157
kvbc::IReader &ro_storage_;
@@ -198,7 +178,7 @@ class ReadOnlyReplicaPruningHandler : public concord::reconfiguration::OperatorC
198178
IReader &ro_storage)
199179
: concord::reconfiguration::OperatorCommandsReconfigurationHandler{operator_pkey_path, type},
200180
ro_storage_{ro_storage},
201-
signer_{bftEngine::ReplicaConfig::instance().replicaPrivateKey},
181+
signer_{},
202182
pruning_enabled_{bftEngine::ReplicaConfig::instance().pruningEnabled_},
203183
replica_id_{bftEngine::ReplicaConfig::instance().replicaId} {}
204184
bool handle(const concord::messages::LatestPrunableBlockRequest &,

0 commit comments

Comments
 (0)