diff --git a/Makefile b/Makefile index 726e5e29ab..9c8d11d3ad 100644 --- a/Makefile +++ b/Makefile @@ -49,34 +49,17 @@ else TCP_ENABLED__:=OFF endif -CONCORD_BFT_CMAKE_CXX_FLAGS_RELEASE?='-O3 -g' -CONCORD_BFT_CMAKE_USE_LOG4CPP?=ON -CONCORD_BFT_CMAKE_BUILD_UTT?=TRUE -CONCORD_BFT_CMAKE_BUILD_ROCKSDB_STORAGE?=TRUE -CONCORD_BFT_CMAKE_USE_S3_OBJECT_STORE?=TRUE -CONCORD_BFT_CMAKE_USE_OPENTRACING?=TRUE -CONCORD_BFT_CMAKE_USE_PROMETHEUS?=TRUE -CONCORD_BFT_CMAKE_USE_JAEGER?=TRUE -CONCORD_BFT_CMAKE_USE_JSON?=TRUE -CONCORD_BFT_CMAKE_USE_HTTPLIB?=TRUE -CONCORD_BFT_CMAKE_EXPORT_COMPILE_COMMANDS?=TRUE -CONCORD_BFT_CMAKE_OMIT_TEST_OUTPUT?=FALSE -CONCORD_BFT_CMAKE_KEEP_APOLLO_LOGS?=TRUE -CONCORD_BFT_CMAKE_RUN_APOLLO_TESTS?=TRUE -CONCORD_BFT_CMAKE_TRANSACTION_SIGNING_ENABLED?=TRUE -CONCORD_BFT_CMAKE_BUILD_SLOWDOWN?=FALSE -# Only useful with CONCORD_BFT_CMAKE_BUILD_TYPE:=Release -CONCORD_BFT_CMAKE_BUILD_KVBC_BENCH?=TRUE -# Only usefull with CONCORD_BFT_CMAKE_CXX_FLAGS_RELEASE=-O0 -g -CONCORD_BFT_CMAKE_ASAN?=FALSE -CONCORD_BFT_CMAKE_TSAN?=FALSE -CONCORD_BFT_CMAKE_UBSAN?=FALSE -CONCORD_BFT_CMAKE_HEAPTRACK?=FALSE -CONCORD_BFT_CMAKE_CODECOVERAGE?=FALSE -CONCORD_BFT_CMAKE_CCACHE?=TRUE -CONCORD_BFT_CMAKE_USE_FAKE_CLOCK_IN_TIME_SERVICE?=FALSE -ENABLE_RESTART_RECOVERY_TESTS?=FALSE -CONCORD_ENABLE_ALL_METRICS?=FALSE +CONCORD_BFT_CMAKE_BUILD_UTT?=ON +CONCORD_BFT_CMAKE_OMIT_TEST_OUTPUT?=OFF +CONCORD_BFT_CMAKE_KEEP_APOLLO_LOGS?=ON +CONCORD_BFT_CMAKE_RUN_APOLLO_TESTS?=ON +CONCORD_BFT_CMAKE_ASAN?=OFF +CONCORD_BFT_CMAKE_TSAN?=OFF +CONCORD_BFT_CMAKE_UBSAN?=OFF +CONCORD_BFT_CMAKE_HEAPTRACK?=OFF +CONCORD_BFT_CMAKE_CODECOVERAGE?=OFF +CONCORD_BFT_CMAKE_CCACHE?=ON +ENABLE_RESTART_RECOVERY_TESTS?=OFF # Our CMake logic won't allow more one of these flags to be raised, so having this if/else logic makes sense ifeq (${CONCORD_BFT_CMAKE_ASAN},ON) diff --git a/bftengine/include/bftengine/ReplicaConfig.hpp b/bftengine/include/bftengine/ReplicaConfig.hpp index 2cd6af5ce2..a875d4ef01 100644 --- a/bftengine/include/bftengine/ReplicaConfig.hpp +++ b/bftengine/include/bftengine/ReplicaConfig.hpp @@ -306,11 +306,11 @@ class ReplicaConfig : public concord::serialize::SerializableFactory(it->second); return defaultValue; } - inline std::set>>* getPublicKeysOfClients() { + inline const std::set>>* getPublicKeysOfClients() const { return (clientTransactionSigningEnabled || !clientsKeysPrefix.empty()) ? &publicKeysOfClients : nullptr; } - std::string getOperatorPublicKey() { + std::string getOperatorPublicKey() const { std::ifstream op_key_file(pathToOperatorPublicKey_); if (!op_key_file.fail()) { std::stringstream buffer; diff --git a/bftengine/src/bftengine/ReplicaBase.hpp b/bftengine/src/bftengine/ReplicaBase.hpp index aa625a4ea3..3096ae15fe 100644 --- a/bftengine/src/bftengine/ReplicaBase.hpp +++ b/bftengine/src/bftengine/ReplicaBase.hpp @@ -112,7 +112,7 @@ class ReplicaBase { static const uint16_t ALL_OTHER_REPLICAS = UINT16_MAX; const ReplicaConfig& config_; - ReplicasInfo* repsInfo = nullptr; + const ReplicasInfo* repsInfo = nullptr; std::shared_ptr msgsCommunicator_; std::shared_ptr msgHandlers_; std::shared_ptr bftRequestsHandler_; diff --git a/bftengine/src/bftengine/ReplicaImp.cpp b/bftengine/src/bftengine/ReplicaImp.cpp index 1ecd2fd8cb..272144d193 100644 --- a/bftengine/src/bftengine/ReplicaImp.cpp +++ b/bftengine/src/bftengine/ReplicaImp.cpp @@ -4434,16 +4434,7 @@ ReplicaImp::ReplicaImp(bool firstTime, if (firstTime) { repsInfo = new ReplicasInfo(config_, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs); - sigManager_ = SigManager::init(config_.replicaId, - config_.replicaPrivateKey, - config_.publicKeysOfReplicas, - concord::crypto::KeyFormat::HexaDecimalStrippedFormat, - ReplicaConfig::instance().getPublicKeysOfClients(), - concord::crypto::KeyFormat::PemFormat, - {{repsInfo->getIdOfOperator(), - ReplicaConfig::instance().getOperatorPublicKey(), - concord::crypto::KeyFormat::PemFormat}}, - *repsInfo); + sigManager_ = SigManager::owningInstance(); viewsManager = new ViewsManager(repsInfo); } else { repsInfo = replicasInfo; diff --git a/bftengine/src/bftengine/ReplicaLoader.cpp b/bftengine/src/bftengine/ReplicaLoader.cpp index 8e60e23319..c7dffd11c7 100644 --- a/bftengine/src/bftengine/ReplicaLoader.cpp +++ b/bftengine/src/bftengine/ReplicaLoader.cpp @@ -47,25 +47,14 @@ namespace impl { namespace { ReplicaLoader::ErrorCode loadConfig(LoadedReplicaData &ld) { - ld.repsInfo = new ReplicasInfo(ld.repConfig, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs); auto &config = ld.repConfig; - ld.sigManager = SigManager::init(config.replicaId, - config.replicaPrivateKey, - config.publicKeysOfReplicas, - concord::crypto::KeyFormat::HexaDecimalStrippedFormat, - ReplicaConfig::instance().getPublicKeysOfClients(), - concord::crypto::KeyFormat::PemFormat, - {{ld.repsInfo->getIdOfOperator(), - ReplicaConfig::instance().getOperatorPublicKey(), - concord::crypto::KeyFormat::PemFormat}}, - *ld.repsInfo); - - std::unique_ptr cryptoSys = std::make_unique(ld.repConfig.thresholdSystemType_, - ld.repConfig.thresholdSystemSubType_, - ld.repConfig.numReplicas, - ld.repConfig.numReplicas); - cryptoSys->loadKeys(ld.repConfig.thresholdPublicKey_, ld.repConfig.thresholdVerificationKeys_); - cryptoSys->loadPrivateKey(ld.repConfig.replicaId, ld.repConfig.thresholdPrivateKey_); + ld.repsInfo = new ReplicasInfo(config, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs); + ld.sigManager = SigManager::owningInstance(); + + std::unique_ptr cryptoSys = std::make_unique( + config.thresholdSystemType_, config.thresholdSystemSubType_, config.numReplicas, config.numReplicas); + cryptoSys->loadKeys(config.thresholdPublicKey_, config.thresholdVerificationKeys_); + cryptoSys->loadPrivateKey(config.replicaId, config.thresholdPrivateKey_); bftEngine::CryptoManager::init(std::move(cryptoSys)); return Succ; diff --git a/bftengine/src/bftengine/ReplicasInfo.cpp b/bftengine/src/bftengine/ReplicasInfo.cpp index 13d3060b57..b3c570c5c4 100644 --- a/bftengine/src/bftengine/ReplicasInfo.cpp +++ b/bftengine/src/bftengine/ReplicasInfo.cpp @@ -146,11 +146,12 @@ ReplicasInfo::ReplicasInfo(const ReplicaConfig& config, } if (start != end) LOG_INFO(GL, "Principal ids in _idsOfInternalClients: " << start << " to " << end - 1); return ret; - }()} { - _operator_id = config.operatorEnabled_ - ? static_cast(config.numReplicas + config.numRoReplicas + config.numOfClientProxies + - config.numOfExternalClients + config.numOfClientServices - 1) - : 0; + }()}, + + _operator_id{static_cast( + config.operatorEnabled_ ? config.numReplicas + config.numRoReplicas + config.numOfClientProxies + + config.numOfExternalClients + config.numOfClientServices - 1 + : 0)} { ConcordAssert(_numberOfReplicas == (3 * _fVal + 2 * _cVal + 1)); } diff --git a/bftengine/src/bftengine/ReplicasInfo.hpp b/bftengine/src/bftengine/ReplicasInfo.hpp index b6a65efeaa..81b3a0994a 100644 --- a/bftengine/src/bftengine/ReplicasInfo.hpp +++ b/bftengine/src/bftengine/ReplicasInfo.hpp @@ -20,6 +20,9 @@ class ReplicaConfig; namespace impl { +/** + * An immutable class holding the the ids of all the participants in the network + */ class ReplicasInfo { public: ReplicasInfo(const ReplicaConfig&, bool dynamicCollectorForPartialProofs, bool dynamicCollectorForExecutionProofs); @@ -110,7 +113,7 @@ class ReplicasInfo { const std::set _idsOfInternalClients; // Currently we support only a single operator entity in the system - PrincipalId _operator_id; + const PrincipalId _operator_id = 0; }; } // namespace impl } // namespace bftEngine diff --git a/bftengine/src/bftengine/SigManager.cpp b/bftengine/src/bftengine/SigManager.cpp index 14ed5df1e8..a4df8073c5 100644 --- a/bftengine/src/bftengine/SigManager.cpp +++ b/bftengine/src/bftengine/SigManager.cpp @@ -47,6 +47,11 @@ SigManager* SigManager::instance() { return s_sm.get(); } +std::shared_ptr SigManager::owningInstance() { + ConcordAssertNE(s_sm.get(), nullptr); + return s_sm; +} + void SigManager::reset(std::shared_ptr other) { s_sm = other; } std::shared_ptr SigManager::init( @@ -457,6 +462,7 @@ SeqNum SigManager::getReplicaLastExecutedSeq() const { ConcordAssert(replicasInfo_.isIdOfReplica(myId_) || replicasInfo_.isRoReplica()); return replicaLastExecutedSeq_; } +const ReplicasInfo& SigManager::getReplicasInfo() const { return replicasInfo_; } } // namespace impl } // namespace bftEngine diff --git a/bftengine/src/bftengine/SigManager.hpp b/bftengine/src/bftengine/SigManager.hpp index 63bb5f307e..57f3a51a62 100644 --- a/bftengine/src/bftengine/SigManager.hpp +++ b/bftengine/src/bftengine/SigManager.hpp @@ -19,6 +19,7 @@ #include "crypto/signer.hpp" #include "crypto/verifier.hpp" #include "SysConsts.hpp" +#include "ReplicasInfo.hpp" #include #include #include @@ -35,8 +36,6 @@ class IThresholdVerifier; namespace bftEngine { namespace impl { -class ReplicasInfo; - class SigManager { public: using Key = std::string; @@ -44,6 +43,7 @@ class SigManager { virtual ~SigManager() = default; static SigManager* instance(); + static std::shared_ptr owningInstance(); static void reset(std::shared_ptr other); // It is the caller responsibility to deallocate (delete) the object @@ -129,6 +129,8 @@ class SigManager { const concord::crypto::IVerifier& extractVerifierFromMultisig(std::shared_ptr thresholdVerifier, PrincipalId id) const; + const ReplicasInfo& getReplicasInfo() const; + protected: static constexpr uint16_t updateMetricsAggregatorThresh = 1000; @@ -153,7 +155,7 @@ class SigManager { std::unique_ptr mySigner_; std::map> verifiers_; bool clientTransactionSigningEnabled_ = true; - const ReplicasInfo& replicasInfo_; + const ReplicasInfo replicasInfo_; // The ownership model of a SigManager object depends on its use static std::shared_ptr s_sm; diff --git a/kvbc/include/pruning_handler.hpp b/kvbc/include/pruning_handler.hpp index 2f3a6237a8..5c02fc6f06 100644 --- a/kvbc/include/pruning_handler.hpp +++ b/kvbc/include/pruning_handler.hpp @@ -32,7 +32,7 @@ class PruningSigner { public: // Construct by passing the configuration for the node the signer is running // on. - PruningSigner(const std::string &key); + PruningSigner(); // Sign() methods sign the passed message and store the signature in the // 'signature' field of the message. An exception is thrown on error. // @@ -41,9 +41,6 @@ class PruningSigner { // application-level signature rather than a Concord-BFT Principal's RSA/EdDSA // signature. void sign(concord::messages::LatestPrunableBlock &); - - private: - std::unique_ptr signer_; }; // This class verifies pruning messages that were signed by serializing message @@ -55,7 +52,7 @@ class PruningSigner { class PruningVerifier { public: // Construct by passing the system configuration. - PruningVerifier(const std::set> &replicasPublicKeys); + PruningVerifier(); // Verify() methods verify that the message comes from the advertised sender. // Methods return true on successful verification and false on unsuccessful. // An exception is thrown on error. @@ -76,22 +73,6 @@ class PruningVerifier { }; bool verify(std::uint64_t sender, const std::string &ser, const std::string &signature) const; - - using ReplicaVector = std::vector; - - // Get a replica from the replicas vector by its index. - const Replica &getReplica(ReplicaVector::size_type idx) const; - - // A vector of all the replicas in the system. - ReplicaVector replicas_; - // We map a principal_id to a replica index in the replicas_ vector to be able - // to verify a message through the Replica's verifier that is associated with - // its public key. - std::unordered_map principal_to_replica_idx_; - - // Contains a set of replica principal_ids for use in verification. Filled in - // once during construction. - std::unordered_set replica_ids_; }; class PruningHandler : public concord::reconfiguration::OperatorCommandsReconfigurationHandler { // This class implements the KVB pruning state machine. Main functionalities @@ -171,7 +152,6 @@ class PruningHandler : public concord::reconfiguration::OperatorCommandsReconfig // Throws on errors. void pruneThroughBlockId(kvbc::BlockId block_id) const; uint64_t getBlockBftSequenceNumber(kvbc::BlockId) const; - logging::Logger logger_; PruningSigner signer_; PruningVerifier verifier_; kvbc::IReader &ro_storage_; @@ -198,7 +178,7 @@ class ReadOnlyReplicaPruningHandler : public concord::reconfiguration::OperatorC IReader &ro_storage) : concord::reconfiguration::OperatorCommandsReconfigurationHandler{operator_pkey_path, type}, ro_storage_{ro_storage}, - signer_{bftEngine::ReplicaConfig::instance().replicaPrivateKey}, + signer_{}, pruning_enabled_{bftEngine::ReplicaConfig::instance().pruningEnabled_}, replica_id_{bftEngine::ReplicaConfig::instance().replicaId} {} bool handle(const concord::messages::LatestPrunableBlockRequest &, diff --git a/kvbc/src/Replica.cpp b/kvbc/src/Replica.cpp index 2dff5b6df8..7e37525898 100644 --- a/kvbc/src/Replica.cpp +++ b/kvbc/src/Replica.cpp @@ -316,8 +316,21 @@ void Replica::saveReconfigurationCmdToResPages(const std::string &key) { void Replica::createReplicaAndSyncState() { ConcordAssertNE(m_kvBlockchain, nullptr); + + ReplicasInfo repsInfo{replicaConfig_, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs}; + SigManager::init( + replicaConfig_.replicaId, + replicaConfig_.replicaPrivateKey, + replicaConfig_.publicKeysOfReplicas, + concord::crypto::KeyFormat::HexaDecimalStrippedFormat, + replicaConfig_.getPublicKeysOfClients(), + concord::crypto::KeyFormat::PemFormat, + {{repsInfo.getIdOfOperator(), replicaConfig_.getOperatorPublicKey(), concord::crypto::KeyFormat::PemFormat}}, + repsInfo); + auto requestHandler = KvbcRequestHandler::create(m_cmdHandler, cronTableRegistry_, *m_kvBlockchain, aggregator_); registerReconfigurationHandlers(requestHandler); + m_replicaPtr = bftEngine::ReplicaFactory::createReplica( replicaConfig_, requestHandler, m_stateTransfer, m_ptrComm.get(), m_metadataStorage, pm_, secretsManager_); requestHandler->setPersistentStorage(m_replicaPtr->persistentStorage()); diff --git a/kvbc/src/pruning_handler.cpp b/kvbc/src/pruning_handler.cpp index 6f546076fe..faa35cc7bb 100644 --- a/kvbc/src/pruning_handler.cpp +++ b/kvbc/src/pruning_handler.cpp @@ -16,45 +16,32 @@ #include "pruning_handler.hpp" #include "categorization/versioned_kv_category.h" #include "kvbc_key_types.hpp" +#include "SigManager.hpp" namespace concord::kvbc::pruning { using bftEngine::ReplicaConfig; void PruningSigner::sign(concord::messages::LatestPrunableBlock& block) { + auto& sigManager = *bftEngine::impl::SigManager::instance(); std::ostringstream oss; std::string ser; oss << block.replica << block.block_id; ser = oss.str(); - std::vector signature(signer_->signatureLength()); - auto actualSignatureLength = signer_->sign(ser, signature.data()); - ConcordAssertEQ(actualSignatureLength, signer_->signatureLength()); + std::vector signature(sigManager.getMySigLength()); + sigManager.sign( + sigManager.getReplicaLastExecutedSeq(), ser.data(), ser.size(), reinterpret_cast(signature.data())); + block.signature = std::move(signature); } -PruningSigner::PruningSigner(const std::string& key) - : signer_{concord::crypto::Factory::getSigner(key, ReplicaConfig::instance().replicaMsgSigningAlgo)} {} - -PruningVerifier::PruningVerifier(const std::set>& replicasPublicKeys) { - auto i = 0u; - for (auto& [idx, pkey] : replicasPublicKeys) { - replicas_.push_back( - Replica{idx, concord::crypto::Factory::getVerifier(pkey, ReplicaConfig::instance().replicaMsgSigningAlgo)}); - const auto ins_res = replica_ids_.insert(replicas_.back().principal_id); - if (!ins_res.second) { - throw std::runtime_error{"PruningVerifier found duplicate replica principal_id: " + - std::to_string(replicas_.back().principal_id)}; - } +PruningSigner::PruningSigner() {} - const auto& replica = replicas_.back(); - principal_to_replica_idx_[replica.principal_id] = i; - i++; - } -} +PruningVerifier::PruningVerifier() {} bool PruningVerifier::verify(const concord::messages::LatestPrunableBlock& block) const { // LatestPrunableBlock can only be sent by replicas and not by client proxies. - if (replica_ids_.find(block.replica) == std::end(replica_ids_)) { + if (!SigManager::instance()->hasVerifier(block.replica)) { return false; } std::ostringstream oss; @@ -66,46 +53,51 @@ bool PruningVerifier::verify(const concord::messages::LatestPrunableBlock& block } bool PruningVerifier::verify(const concord::messages::PruneRequest& request) const { - if (request.latest_prunable_block.size() != static_cast(replica_ids_.size())) { + const auto& repInfo = SigManager::instance()->getReplicasInfo(); + const auto expected_response_count = repInfo.getNumberOfReplicas() + repInfo.getNumberOfRoReplicas(); + if (request.latest_prunable_block.size() != static_cast(expected_response_count)) { + LOG_ERROR( + PRUNING_LOG, + "Invalid number of latest prunable block responses in prune request" << KVLOG( + request.latest_prunable_block.size(), repInfo.getNumberOfReplicas(), repInfo.getNumberOfRoReplicas())); return false; } // PruneRequest can only be sent by client proxies and not by replicas. - if (replica_ids_.find(request.sender) != std::end(replica_ids_)) { + if (repInfo.isIdOfReplica(request.sender)) { + LOG_ERROR(PRUNING_LOG, "Invalid sender of prune request, sender id:" << request.sender); return false; } // Note PruningVerifier does not handle verification of the operator's // signature authorizing this pruning order, as the operator's signature is a // dedicated application-level signature rather than one of the Concord-BFT - // principals' RSA signatures. + // principals' main signatures. // Verify that *all* replicas have responded with valid responses. - auto replica_ids_to_verify = replica_ids_; for (auto& block : request.latest_prunable_block) { + auto currentId = block.replica; if (!verify(block)) { + LOG_ERROR(PRUNING_LOG, "Failed to verify latest prunable block of replica id:" << currentId); return false; } - auto it = replica_ids_to_verify.find(block.replica); - if (it == std::end(replica_ids_to_verify)) { + + if (!(repInfo.isIdOfReplica(currentId) || repInfo.isIdOfPeerRoReplica(currentId))) { + LOG_ERROR(PRUNING_LOG, "latest prunable block is not of a replica nor an RO replica:" << currentId); return false; } - replica_ids_to_verify.erase(it); } - return replica_ids_to_verify.empty(); + + return true; } bool PruningVerifier::verify(std::uint64_t sender, const std::string& ser, const std::string& signature) const { - auto it = principal_to_replica_idx_.find(sender); - if (it == std::cend(principal_to_replica_idx_)) { + if (!SigManager::instance()->hasVerifier(sender)) { return false; } - return getReplica(it->second).verifier->verify(ser, signature); -} - -const PruningVerifier::Replica& PruningVerifier::getReplica(ReplicaVector::size_type idx) const { - return replicas_[idx]; + auto& sigManager = *bftEngine::impl::SigManager::instance(); + return sigManager.verifySig(sender, ser, signature); } PruningHandler::PruningHandler(const std::string& operator_pkey_path, @@ -115,9 +107,8 @@ PruningHandler::PruningHandler(const std::string& operator_pkey_path, kvbc::IBlocksDeleter& blocks_deleter, bool run_async) : concord::reconfiguration::OperatorCommandsReconfigurationHandler{operator_pkey_path, type}, - logger_{logging::getLogger("concord.pruning")}, - signer_{bftEngine::ReplicaConfig::instance().replicaPrivateKey}, - verifier_{bftEngine::ReplicaConfig::instance().publicKeysOfReplicas}, + signer_{}, + verifier_{}, ro_storage_{ro_storage}, blocks_adder_{blocks_adder}, blocks_deleter_{blocks_deleter}, @@ -173,7 +164,7 @@ bool PruningHandler::handle(const concord::messages::PruneRequest& request, "LatestPrunableBlock messages did not bear correct signatures " "from the claimed replicas."; concord::messages::ReconfigurationErrorMsg error_msg; - LOG_WARN(logger_, error); + LOG_WARN(PRUNING_LOG, error); error_msg.error_msg = error; rres.response = error_msg; return false; @@ -214,10 +205,10 @@ void PruningHandler::pruneThroughBlockId(kvbc::BlockId block_id) const { try { blocks_deleter_.deleteBlocksUntil(until, false); } catch (std::exception& e) { - LOG_FATAL(logger_, e.what()); + LOG_FATAL(PRUNING_LOG, e.what()); std::terminate(); } catch (...) { - LOG_FATAL(logger_, "Error while running pruning"); + LOG_FATAL(PRUNING_LOG, "Error while running pruning"); std::terminate(); } // We grab a mutex to handle the case in which we ask for pruning status @@ -226,11 +217,11 @@ void PruningHandler::pruneThroughBlockId(kvbc::BlockId block_id) const { bftEngine::ControlStateManager::instance().setPruningProcess(false); }; if (run_async_) { - LOG_INFO(logger_, "running pruning in async mode"); + LOG_INFO(PRUNING_LOG, "running pruning in async mode"); async_pruning_res_ = std::async(prune, block_id + 1); (void)async_pruning_res_; } else { - LOG_INFO(logger_, "running pruning in sync mode"); + LOG_INFO(PRUNING_LOG, "running pruning in sync mode"); prune(block_id + 1); } } @@ -251,7 +242,7 @@ bool PruningHandler::handle(const concord::messages::PruneStatusRequest&, prune_status.last_pruned_block = (genesis_id > INITIAL_GENESIS_BLOCK_ID ? genesis_id - 1 : 0); prune_status.in_progress = bftEngine::ControlStateManager::instance().getPruningProcessStatus(); rres.response = prune_status; - LOG_INFO(logger_, "Pruning status is " << KVLOG(prune_status.in_progress)); + LOG_INFO(PRUNING_LOG, "Pruning status is " << KVLOG(prune_status.in_progress)); return true; } @@ -260,16 +251,16 @@ uint64_t PruningHandler::getBlockBftSequenceNumber(kvbc::BlockId bid) const { concord::kvbc::categorization::kConcordInternalCategoryId, std::string{kvbc::keyTypes::bft_seq_num_key}, bid); uint64_t sequenceNum = 0; if (!opt_value) { - LOG_WARN(logger_, "Unable to get block"); + LOG_WARN(PRUNING_LOG, "Unable to get block"); return sequenceNum; } auto value = std::get(*opt_value); if (value.data.empty()) { - LOG_WARN(logger_, "value has zero-length"); + LOG_WARN(PRUNING_LOG, "value has zero-length"); return sequenceNum; } sequenceNum = concordUtils::fromBigEndianBuffer(value.data.data()); - LOG_DEBUG(logger_, "sequenceNum = " << sequenceNum); + LOG_DEBUG(PRUNING_LOG, "sequenceNum = " << sequenceNum); return sequenceNum; } } // namespace concord::kvbc::pruning diff --git a/kvbc/test/CMakeLists.txt b/kvbc/test/CMakeLists.txt index 9485068cda..6395aa7ca3 100644 --- a/kvbc/test/CMakeLists.txt +++ b/kvbc/test/CMakeLists.txt @@ -306,8 +306,8 @@ if (BUILD_ROCKSDB_STORAGE) stdc++fs ) - - add_executable(pruning_test pruning_test.cpp) + add_executable(pruning_test pruning_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../bftengine/tests/messages/helper.cpp) + target_include_directories(pruning_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../bftengine/tests/messages) add_test(pruning_test pruning_test) target_link_libraries(pruning_test GTest::GTest diff --git a/kvbc/test/pruning_test.cpp b/kvbc/test/pruning_test.cpp index 1a86fc58c3..0f701ff110 100644 --- a/kvbc/test/pruning_test.cpp +++ b/kvbc/test/pruning_test.cpp @@ -18,7 +18,9 @@ #include "db_interfaces.h" #include "util/endianness.hpp" #include "pruning_handler.hpp" - +#include "SigManager.hpp" +#include "CryptoManager.hpp" +#include "helper.hpp" #include "storage/test/storage_test_common.h" #include @@ -36,40 +38,23 @@ using concord::kvbc::BlockId; using namespace concord::kvbc; using namespace concord::kvbc::categorization; using namespace concord::kvbc::pruning; -using concord::crypto::SignatureAlgorithm; using bftEngine::ReplicaConfig; -using concord::crypto::generateEdDSAKeyPair; +using bftEngine::impl::SigManager; +using bftEngine::CryptoManager; namespace { -const NodeIdType replica_0 = 0; -const NodeIdType replica_1 = 1; -const NodeIdType replica_2 = 2; -const NodeIdType replica_3 = 3; -constexpr uint8_t noOfReplicas = 4U; - -std::pair keyPair[noOfReplicas]; -bftEngine::ReplicaConfig &replicaConfig = bftEngine::ReplicaConfig::instance(); -std::map private_keys_of_replicas; - -void setUpKeysConfiguration_4() { - for (auto i = 0; i < noOfReplicas; ++i) { - if (ReplicaConfig::instance().replicaMsgSigningAlgo == SignatureAlgorithm::EdDSA) { - keyPair[i] = generateEdDSAKeyPair(); - } - } - replicaConfig.publicKeysOfReplicas.insert(std::pair(replica_0, keyPair[0].second)); - replicaConfig.publicKeysOfReplicas.insert(std::pair(replica_1, keyPair[1].second)); - replicaConfig.publicKeysOfReplicas.insert(std::pair(replica_2, keyPair[2].second)); - replicaConfig.publicKeysOfReplicas.insert(std::pair(replica_3, keyPair[3].second)); - private_keys_of_replicas[replica_0] = keyPair[0].first; - private_keys_of_replicas[replica_1] = keyPair[1].first; - private_keys_of_replicas[replica_2] = keyPair[2].first; - private_keys_of_replicas[replica_3] = keyPair[3].first; -} +const auto GENESIS_BLOCK_ID = BlockId{1}; +const auto LAST_BLOCK_ID = BlockId{150}; +const auto REPLICA_PRINCIPAL_ID_START = 0; +const auto CLIENT_PRINCIPAL_ID_START = 20000; class test_rocksdb : public ::testing::Test { + static constexpr const uint8_t noOfReplicas = 4U; + void SetUp() override { + GL.setLogLevel(logging::DEBUG_LOG_LEVEL); + setUpKeysConfiguration_4(); destroyDb(); db = TestRocksDb::createNative(); } @@ -83,13 +68,86 @@ class test_rocksdb : public ::testing::Test { } protected: + ReplicaConfig &replicaConfig = ReplicaConfig::instance(); + std::map private_keys_of_replicas; + std::array, noOfReplicas> replicasInfo; + std::array, noOfReplicas> sigManagers; + std::array, noOfReplicas> cryptoManagers; + static const std::pair s_eddsaKeyPairs[noOfReplicas]; + + void setUpKeysConfiguration_4() { + replicaConfig.replicaId = 0; + replicaConfig.numReplicas = 4; + replicaConfig.fVal = 1; + replicaConfig.cVal = 0; + replicaConfig.numOfClientProxies = 4; + replicaConfig.numOfExternalClients = 15; + + std::vector hexPublicKeys(noOfReplicas); + replicaConfig.publicKeysOfReplicas.clear(); + for (auto i = 0; i < noOfReplicas; ++i) { + hexPublicKeys[i] = s_eddsaKeyPairs[i].second; + private_keys_of_replicas.emplace(i, s_eddsaKeyPairs[i].first); + replicaConfig.publicKeysOfReplicas.emplace(i, hexPublicKeys[i]); + } + + for (auto i = 0; i < noOfReplicas; i++) { + replicasInfo[i] = std::make_unique(replicaConfig, true, true); + sigManagers[i] = SigManager::init(i, + private_keys_of_replicas.at(i), + replicaConfig.publicKeysOfReplicas, + concord::crypto::KeyFormat::HexaDecimalStrippedFormat, + nullptr, + concord::crypto::KeyFormat::HexaDecimalStrippedFormat, + {}, + *replicasInfo[i].get()); + cryptoManagers[i] = CryptoManager::init( + std::make_unique(i, hexPublicKeys, private_keys_of_replicas.at(i))); + } + } + + void switchReplicaContext(NodeIdType id) { + LOG_INFO(GL, "Switching replica context to replica " << id); + SigManager::reset(sigManagers[id]); + CryptoManager::reset(cryptoManagers[id]); + } + + void signAs(NodeIdType id, concord::messages::LatestPrunableBlock &block) { + switchReplicaContext(id); + PruningSigner{}.sign(block); + } + + concord::messages::PruneRequest ConstructPruneRequest(std::size_t client_idx, + BlockId min_prunable_block_id = LAST_BLOCK_ID) { + concord::messages::PruneRequest prune_req; + prune_req.sender = client_idx; + + for (uint64_t i = 0u; i < noOfReplicas; i++) { + auto &latest_block = prune_req.latest_prunable_block.emplace_back(concord::messages::LatestPrunableBlock()); + latest_block.replica = i; + // Send different block IDs. + latest_block.block_id = min_prunable_block_id + i; + + signAs(i, latest_block); + } + return prune_req; + } + std::shared_ptr db; }; -const auto GENESIS_BLOCK_ID = BlockId{1}; -const auto LAST_BLOCK_ID = BlockId{150}; -const auto REPLICA_PRINCIPAL_ID_START = 0; -const auto CLIENT_PRINCIPAL_ID_START = 20000; +// clang-format off +const std::pair test_rocksdb::s_eddsaKeyPairs[noOfReplicas] = { + {"61498efe1764b89357a02e2887d224154006ceacf26269f8695a4af561453eef", + "386f4fb049a5d8bb0706d3793096c8f91842ce380dfc342a2001d50dfbc901f4"}, + {"247a74ab3620ec6b9f5feab9ee1f86521da3fa2804ad45bb5bf2c5b21ef105bc", + "3f9e7dbde90477c24c1bacf14e073a356c1eca482d352d9cc0b16560a4e7e469"}, + {"fb539bc3d66deda55524d903da26dbec1f4b6abf41ec5db521e617c64eb2c341", + "2311c6013ff657844669d8b803b2e1ed33fe06eed445f966a800a8fbb8d790e8"}, + {"55ea66e855b83ec4a02bd8fcce6bb4426ad3db2a842fa2a2a6777f13e40a4717", + "1ba7449655784fc9ce193a7887de1e4d3d35f7c82b802440c4f28bf678a34b34"}, +}; +// clang-format on class TestStorage : public IReader, public IBlockAdder, public IBlocksDeleter { public: @@ -245,42 +303,19 @@ void InitBlockchainStorage(std::size_t replica_count, ASSERT_EQ(s.getLastBlockId(), LAST_BLOCK_ID); } -concord::messages::PruneRequest ConstructPruneRequest(std::size_t client_idx, - const std::map &private_keys, - BlockId min_prunable_block_id = LAST_BLOCK_ID) { - concord::messages::PruneRequest prune_req; - prune_req.sender = client_idx; - uint64_t i = 0u; - for (auto &[idx, pkey] : private_keys) { - auto &latest_block = prune_req.latest_prunable_block.emplace_back(concord::messages::LatestPrunableBlock()); - latest_block.replica = idx; - // Send different block IDs. - latest_block.block_id = min_prunable_block_id + i; - - auto block_signer = PruningSigner{pkey}; - block_signer.sign(latest_block); - i++; - } - return prune_req; -} - TEST_F(test_rocksdb, sign_verify_correct) { const auto replica_count = 4; uint64_t sending_id = 0; uint64_t client_proxy_count = 4; - const auto verifier = PruningVerifier{replicaConfig.publicKeysOfReplicas}; - std::vector signers; - signers.reserve(replica_count); - for (auto i = 0; i < replica_count; ++i) { - signers.emplace_back(PruningSigner{private_keys_of_replicas[i]}); - } + const auto verifier = PruningVerifier{}; // Sign and verify a LatestPrunableBlock message. { concord::messages::LatestPrunableBlock block; block.replica = REPLICA_PRINCIPAL_ID_START + sending_id; block.block_id = LAST_BLOCK_ID; - signers[sending_id].sign(block); + + signAs(sending_id, block); ASSERT_TRUE(verifier.verify(block)); } @@ -293,7 +328,7 @@ TEST_F(test_rocksdb, sign_verify_correct) { auto &block = request.latest_prunable_block.emplace_back(concord::messages::LatestPrunableBlock()); block.replica = REPLICA_PRINCIPAL_ID_START + i; block.block_id = LAST_BLOCK_ID; - signers[i].sign(block); + signAs(i, block); } ASSERT_TRUE(verifier.verify(request)); } @@ -303,19 +338,14 @@ TEST_F(test_rocksdb, verify_malformed_messages) { const auto replica_count = 4; const auto client_proxy_count = replica_count; const auto sending_id = 1; - const auto verifier = PruningVerifier{replicaConfig.publicKeysOfReplicas}; - std::vector signers; - signers.reserve(replica_count); - for (auto i = 0; i < replica_count; ++i) { - signers.emplace_back(PruningSigner{private_keys_of_replicas[i]}); - } + const auto verifier = PruningVerifier{}; // Break verification of LatestPrunableBlock messages. { concord::messages::LatestPrunableBlock block; block.replica = REPLICA_PRINCIPAL_ID_START + sending_id; block.block_id = LAST_BLOCK_ID; - signers[sending_id].sign(block); + signAs(sending_id, block); // Change the replica ID after signing. block.replica = REPLICA_PRINCIPAL_ID_START + sending_id + 1; @@ -346,7 +376,7 @@ TEST_F(test_rocksdb, verify_malformed_messages) { auto &block = request.latest_prunable_block.emplace_back(concord::messages::LatestPrunableBlock()); block.replica = REPLICA_PRINCIPAL_ID_START + i; block.block_id = LAST_BLOCK_ID; - signers[i].sign(block); + signAs(i, block); } request.sender = request.sender + 1; @@ -362,7 +392,7 @@ TEST_F(test_rocksdb, verify_malformed_messages) { auto &block = request.latest_prunable_block.emplace_back(concord::messages::LatestPrunableBlock()); block.replica = REPLICA_PRINCIPAL_ID_START + i; block.block_id = LAST_BLOCK_ID; - signers[i].sign(block); + signAs(i, block); } ASSERT_FALSE(verifier.verify(request)); @@ -376,7 +406,7 @@ TEST_F(test_rocksdb, verify_malformed_messages) { auto &block = request.latest_prunable_block.emplace_back(concord::messages::LatestPrunableBlock()); block.replica = REPLICA_PRINCIPAL_ID_START + i; block.block_id = LAST_BLOCK_ID; - signers[i].sign(block); + signAs(i, block); } request.latest_prunable_block[0].replica = REPLICA_PRINCIPAL_ID_START + replica_count + 8; @@ -393,14 +423,14 @@ TEST_F(test_rocksdb, sm_latest_prunable_request_correct_num_bocks_to_keep) { replicaConfig.pruningEnabled_ = true; TestStorage storage(db); auto &blocks_deleter = storage; - const auto verifier = PruningVerifier{replicaConfig.publicKeysOfReplicas}; - replicaConfig.replicaPrivateKey = keyPair[1].first; + const auto verifier = PruningVerifier{}; + switchReplicaContext(replica_idx); InitBlockchainStorage(replica_count, storage); // Construct the pruning state machine with a nullptr TimeContract to verify // it works in case the time service is disabled. - auto sm = PruningHandler{bftEngine::ReplicaConfig::instance().pathToOperatorPublicKey_, - bftEngine::ReplicaConfig::instance().operatorMsgSigningAlgo, + auto sm = PruningHandler{ReplicaConfig::instance().pathToOperatorPublicKey_, + ReplicaConfig::instance().operatorMsgSigningAlgo, storage, storage, blocks_deleter, @@ -420,13 +450,14 @@ TEST_F(test_rocksdb, sm_latest_prunable_request_big_num_blocks_to_keep) { replicaConfig.numBlocksToKeep_ = num_blocks_to_keep; replicaConfig.replicaId = 1; replicaConfig.pruningEnabled_ = true; - replicaConfig.replicaPrivateKey = keyPair[1].first; + replicaConfig.replicaPrivateKey = s_eddsaKeyPairs[1].first; + switchReplicaContext(1); TestStorage storage(db); auto &blocks_deleter = storage; - const auto verifier = PruningVerifier{replicaConfig.publicKeysOfReplicas}; + const auto verifier = PruningVerifier{}; - auto sm = PruningHandler{bftEngine::ReplicaConfig::instance().pathToOperatorPublicKey_, - bftEngine::ReplicaConfig::instance().operatorMsgSigningAlgo, + auto sm = PruningHandler{ReplicaConfig::instance().pathToOperatorPublicKey_, + ReplicaConfig::instance().operatorMsgSigningAlgo, storage, storage, blocks_deleter, @@ -450,15 +481,16 @@ TEST_F(test_rocksdb, sm_latest_prunable_request_no_pruning_conf) { replicaConfig.numBlocksToKeep_ = num_blocks_to_keep; replicaConfig.replicaId = 1; replicaConfig.pruningEnabled_ = true; - replicaConfig.replicaPrivateKey = keyPair[1].first; + replicaConfig.replicaPrivateKey = s_eddsaKeyPairs[1].first; + switchReplicaContext(1); TestStorage storage(db); auto &blocks_deleter = storage; - const auto verifier = PruningVerifier{replicaConfig.publicKeysOfReplicas}; + const auto verifier = PruningVerifier{}; InitBlockchainStorage(replica_count, storage); - auto sm = PruningHandler{bftEngine::ReplicaConfig::instance().pathToOperatorPublicKey_, - bftEngine::ReplicaConfig::instance().operatorMsgSigningAlgo, + auto sm = PruningHandler{ReplicaConfig::instance().pathToOperatorPublicKey_, + ReplicaConfig::instance().operatorMsgSigningAlgo, storage, storage, blocks_deleter, @@ -482,15 +514,14 @@ TEST_F(test_rocksdb, sm_latest_prunable_request_pruning_disabled) { replicaConfig.numBlocksToKeep_ = num_blocks_to_keep; replicaConfig.replicaId = replica_idx; replicaConfig.pruningEnabled_ = false; - replicaConfig.replicaPrivateKey = keyPair[1].first; + replicaConfig.replicaPrivateKey = s_eddsaKeyPairs[1].first; auto storage = TestStorage(db); auto &blocks_deleter = storage; - const auto verifier = PruningVerifier{replicaConfig.publicKeysOfReplicas}; InitBlockchainStorage(replica_count, storage); - auto sm = PruningHandler{bftEngine::ReplicaConfig::instance().pathToOperatorPublicKey_, - bftEngine::ReplicaConfig::instance().operatorMsgSigningAlgo, + auto sm = PruningHandler{ReplicaConfig::instance().pathToOperatorPublicKey_, + ReplicaConfig::instance().operatorMsgSigningAlgo, storage, storage, blocks_deleter, @@ -511,18 +542,18 @@ TEST_F(test_rocksdb, sm_handle_prune_request_on_pruning_disabled) { replicaConfig.numBlocksToKeep_ = num_blocks_to_keep; replicaConfig.replicaId = replica_idx; replicaConfig.pruningEnabled_ = false; - replicaConfig.replicaPrivateKey = keyPair[1].first; + replicaConfig.replicaPrivateKey = s_eddsaKeyPairs[1].first; TestStorage storage(db); auto &blocks_deleter = storage; - auto sm = PruningHandler{bftEngine::ReplicaConfig::instance().pathToOperatorPublicKey_, - bftEngine::ReplicaConfig::instance().operatorMsgSigningAlgo, + auto sm = PruningHandler{ReplicaConfig::instance().pathToOperatorPublicKey_, + ReplicaConfig::instance().operatorMsgSigningAlgo, storage, storage, blocks_deleter, false}; - const auto req = ConstructPruneRequest(client_idx, private_keys_of_replicas); + const auto req = ConstructPruneRequest(client_idx); concord::messages::ReconfigurationResponse rres; auto res = sm.handle(req, 0, UINT32_MAX, {}, rres); ASSERT_TRUE(res); @@ -535,20 +566,20 @@ TEST_F(test_rocksdb, sm_handle_correct_prune_request) { replicaConfig.numBlocksToKeep_ = num_blocks_to_keep; replicaConfig.replicaId = replica_idx; replicaConfig.pruningEnabled_ = true; - replicaConfig.replicaPrivateKey = keyPair[1].first; + replicaConfig.replicaPrivateKey = s_eddsaKeyPairs[1].first; TestStorage storage(db); auto &blocks_deleter = storage; InitBlockchainStorage(replica_count, storage); - auto sm = PruningHandler{bftEngine::ReplicaConfig::instance().pathToOperatorPublicKey_, - bftEngine::ReplicaConfig::instance().operatorMsgSigningAlgo, + auto sm = PruningHandler{ReplicaConfig::instance().pathToOperatorPublicKey_, + ReplicaConfig::instance().operatorMsgSigningAlgo, storage, storage, blocks_deleter, false}; const auto latest_prunable_block_id = storage.getLastBlockId() - num_blocks_to_keep; - const auto req = ConstructPruneRequest(client_idx, private_keys_of_replicas, latest_prunable_block_id); + const auto req = ConstructPruneRequest(client_idx, latest_prunable_block_id); blocks_deleter.deleteBlocksUntil(latest_prunable_block_id + 1); concord::messages::ReconfigurationResponse rres; auto res = sm.handle(req, 0, UINT32_MAX, {}, rres); @@ -564,13 +595,13 @@ TEST_F(test_rocksdb, sm_handle_incorrect_prune_request) { replicaConfig.numBlocksToKeep_ = num_blocks_to_keep; replicaConfig.replicaId = replica_idx; replicaConfig.pruningEnabled_ = true; - replicaConfig.replicaPrivateKey = keyPair[1].first; + replicaConfig.replicaPrivateKey = s_eddsaKeyPairs[1].first; TestStorage storage(db); auto &blocks_deleter = storage; InitBlockchainStorage(replica_count, storage); - auto sm = PruningHandler{bftEngine::ReplicaConfig::instance().pathToOperatorPublicKey_, - bftEngine::ReplicaConfig::instance().operatorMsgSigningAlgo, + auto sm = PruningHandler{ReplicaConfig::instance().pathToOperatorPublicKey_, + ReplicaConfig::instance().operatorMsgSigningAlgo, storage, storage, blocks_deleter, @@ -578,7 +609,7 @@ TEST_F(test_rocksdb, sm_handle_incorrect_prune_request) { // Add a valid N + 1 latest prunable block. { - auto req = ConstructPruneRequest(client_idx, private_keys_of_replicas); + auto req = ConstructPruneRequest(client_idx); const auto &block = req.latest_prunable_block[3]; auto latest_prunnable_block = concord::messages::LatestPrunableBlock(); latest_prunnable_block.block_id = block.block_id; @@ -594,7 +625,7 @@ TEST_F(test_rocksdb, sm_handle_incorrect_prune_request) { // Send N - 1 latest prunable blocks. { - auto req = ConstructPruneRequest(client_idx, private_keys_of_replicas); + auto req = ConstructPruneRequest(client_idx); req.latest_prunable_block.pop_back(); concord::messages::ReconfigurationResponse rres; auto res = sm.handle(req, 0, UINT32_MAX, {}, rres); @@ -605,7 +636,7 @@ TEST_F(test_rocksdb, sm_handle_incorrect_prune_request) { // Send a latest prunable block with an invalid signature. { - auto req = ConstructPruneRequest(client_idx, private_keys_of_replicas); + auto req = ConstructPruneRequest(client_idx); auto &block = req.latest_prunable_block[req.latest_prunable_block.size() - 1]; block.signature[0] += 1; concord::messages::ReconfigurationResponse rres; @@ -618,7 +649,6 @@ TEST_F(test_rocksdb, sm_handle_incorrect_prune_request) { } // namespace int main(int argc, char **argv) { - setUpKeysConfiguration_4(); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/libs/log/logger.hpp b/libs/log/logger.hpp index 93294cc991..5d6d417743 100644 --- a/libs/log/logger.hpp +++ b/libs/log/logger.hpp @@ -35,6 +35,7 @@ extern logging::Logger THRESHSIGN_LOG; extern logging::Logger OPENSSL_LOG; extern logging::Logger BLS_LOG; extern logging::Logger EDDSA_MULTISIG_LOG; +extern logging::Logger PRUNING_LOG; extern logging::Logger EDDSA_SIG_LOG; extern logging::Logger KEY_EX_LOG; extern logging::Logger CAT_BLOCK_LOG; diff --git a/libs/log/src/logger.cpp b/libs/log/src/logger.cpp index c4703c8321..c35ab38008 100644 --- a/libs/log/src/logger.cpp +++ b/libs/log/src/logger.cpp @@ -30,6 +30,7 @@ logging::Logger CNSUS = logging::getLogger("concord.bft.consensus"); logging::Logger THRESHSIGN_LOG = logging::getLogger("concord.bft.threshsign"); logging::Logger BLS_LOG = logging::getLogger("concord.bft.threshsign.bls"); logging::Logger EDDSA_MULTISIG_LOG = logging::getLogger("threshsign.eddsa"); +logging::Logger PRUNING_LOG = logging::getLogger("concord.pruning"); logging::Logger OPENSSL_LOG = logging::getLogger("concord.bft.openssl"); logging::Logger EDDSA_SIG_LOG = logging::getLogger("singlesig.eddsa"); logging::Logger KEY_EX_LOG = logging::getLogger("concord.bft.key-exchange"); diff --git a/tests/apollo/test_skvbc_commit_path.py b/tests/apollo/test_skvbc_commit_path.py index 233dd969bd..cd8a74cb13 100644 --- a/tests/apollo/test_skvbc_commit_path.py +++ b/tests/apollo/test_skvbc_commit_path.py @@ -271,4 +271,4 @@ async def test_fast_path_after_view_change(self, bft_network, tracker): await bft_network.wait_for_consensus_path( path_type=ConsensusPathType.OPTIMISTIC_FAST, run_ops=lambda: skvbc.send_n_kvs_sequentially(int(1.1 * EVALUATION_PERIOD_SEQUENCES)), - threshold=num_ops) \ No newline at end of file + threshold=num_ops) diff --git a/tests/apollo/test_skvbc_view_change.py b/tests/apollo/test_skvbc_view_change.py index 486bd8997e..33a2187173 100644 --- a/tests/apollo/test_skvbc_view_change.py +++ b/tests/apollo/test_skvbc_view_change.py @@ -480,8 +480,6 @@ async def test_multiple_vc_slow_path(self, bft_network, tracker): await bft_network.wait_for_view_with_threshold(view) await skvbc.read_your_writes() - await bft_network.assert_slow_path_prevalent(0, 0, random.choice( - bft_network.all_replicas(without=crashed_replicas))) @with_trio @with_bft_network(start_replica_cmd, diff --git a/tests/apollo/util/bft.py b/tests/apollo/util/bft.py index b73f6529fe..bea7ee5a11 100644 --- a/tests/apollo/util/bft.py +++ b/tests/apollo/util/bft.py @@ -247,7 +247,7 @@ async def test_with_bft_network(): return decorator MAX_MSG_SIZE = 64*1024 # 64k -REQ_TIMEOUT_MILLI = 5000 * 2 +REQ_TIMEOUT_MILLI = 5000 RETRY_TIMEOUT_MILLI = 250 METRICS_TIMEOUT_SEC = 5 @@ -416,7 +416,7 @@ def new(cls, config, background_nursery, client_factory=None, with_cre=False, us return bft_network @classmethod - def existing(cls, config, replicas, clients, client_factory=None, background_nursery=None, builddir=None): + def existing(cls, config, replicas, clients, client_factory=None, background_nursery=None): certdir = None builddir = tempfile.mkdtemp(prefix='builddir') if not client_factory: diff --git a/tests/apollo/util/eliot_logging.py b/tests/apollo/util/eliot_logging.py index 91598e004b..cc9ed8d5ec 100644 --- a/tests/apollo/util/eliot_logging.py +++ b/tests/apollo/util/eliot_logging.py @@ -34,9 +34,6 @@ def set_file_destination(): now = logdir_timestamp() test_name = f"apollo_run_{now}" - if os.environ.get('BLOCKCHAIN_VERSION', default="1").lower() == "4": - test_name = test_name + "_v4" - relative_apollo_logs = 'tests/apollo/logs' relative_current_run_logs = f'{relative_apollo_logs}/{logdir_timestamp()}' logs_dir = f'../../build/{relative_current_run_logs}' @@ -56,8 +53,6 @@ def set_file_destination(): latest_shortcut.unlink() latest_shortcut.symlink_to(target=Path(f'../{relative_current_run_logs}'), target_is_directory=True) - # Set the log file path - to_file(open(test_log, "a+")) test_log_file = open(test_log, "a+") to_file(test_log_file) diff --git a/tests/apollo/util/pyclient/bft_client.py b/tests/apollo/util/pyclient/bft_client.py index 31ccb2fc1b..9a34e666ed 100644 --- a/tests/apollo/util/pyclient/bft_client.py +++ b/tests/apollo/util/pyclient/bft_client.py @@ -299,7 +299,7 @@ async def write_batch(self, msg_batch, batch_seq_nums=None, m_of_n_quorum=None, self.client_id, msg_seq_num, False, self.config.req_timeout_milli, batch_cid, msg, 0, True, reconfiguration=False, span_context=b'', signature=signature, batch_index=n)]) - data = bft_msgs.pack_batch_request(self.client_id, batch_size, msg_data, batch_batch_cid) + data = bft_msgs.pack_batch_request(self.client_id, batch_size, msg_data, batch_cid) if m_of_n_quorum is None: m_of_n_quorum = MofNQuorum.LinearizableQuorum(self.config, [r.id for r in self.replicas]) @@ -311,7 +311,7 @@ async def write_batch(self, msg_batch, batch_seq_nums=None, m_of_n_quorum=None, return await self._send_receive_loop(data, False, m_of_n_quorum, batch_size * self.config.retry_timeout_milli / 1000, no_retries=no_retries) except trio.TooSlowError: - raise trio.TooSlowError(f"client_id {self.client_id}, for batch msg {batch_batch_cid} {batch_seq_nums}") + raise trio.TooSlowError(f"client_id {self.client_id}, for batch msg {batch_cid} {batch_seq_nums}") finally: pass diff --git a/tests/simpleTest/src/simple_test_replica.cpp b/tests/simpleTest/src/simple_test_replica.cpp index ca1dba63e8..4d4af80abb 100644 --- a/tests/simpleTest/src/simple_test_replica.cpp +++ b/tests/simpleTest/src/simple_test_replica.cpp @@ -25,6 +25,17 @@ SimpleTestReplica::SimpleTestReplica(ICommunication *commObject, MetadataStorage *metaDataStorage) : comm{commObject}, replicaConfig{rc}, behaviorPtr{behvPtr}, statePtr(state) { bftEngine::IControlHandler::instance(new bftEngine::ControlHandler()); + + ReplicasInfo repsInfo{rc, dynamicCollectorForPartialProofs, dynamicCollectorForExecutionProofs}; + SigManager::init(rc.replicaId, + rc.replicaPrivateKey, + rc.publicKeysOfReplicas, + concord::crypto::KeyFormat::HexaDecimalStrippedFormat, + rc.getPublicKeysOfClients(), + concord::crypto::KeyFormat::PemFormat, + {{repsInfo.getIdOfOperator(), rc.getOperatorPublicKey(), concord::crypto::KeyFormat::PemFormat}}, + repsInfo); + replica = bftEngine::ReplicaFactory::createReplica(rc, std::shared_ptr(state), inMemoryST,