From 78f277bfe4ad4fa44d81eaaf6dc0d0ff6181d4c7 Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Thu, 22 Apr 2021 18:26:22 -0400 Subject: [PATCH] trivial/refactoring: simple bls refactoring / adjustments (#4114) * use std::make_unique instead of reset which prevents a theoretical memory leak * pass by value and use std::move * use empty instead of comparing to size * remove extra space * adjust include postitioning Co-authored-by: UdjinM6 Co-authored-by: UdjinM6 --- src/bls/bls_ies.cpp | 2 +- src/bls/bls_worker.cpp | 9 ++++++--- src/bls/bls_worker.h | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bls/bls_ies.cpp b/src/bls/bls_ies.cpp index e79c49d7ca..152a0019c8 100644 --- a/src/bls/bls_ies.cpp +++ b/src/bls/bls_ies.cpp @@ -72,7 +72,7 @@ bool CBLSIESEncryptedBlob::Decrypt(size_t idx, const CBLSSecretKey& secretKey, C bool CBLSIESEncryptedBlob::IsValid() const { - return ephemeralPubKey.IsValid() && data.size() > 0 && !ivSeed.IsNull(); + return ephemeralPubKey.IsValid() && !data.empty() && !ivSeed.IsNull(); } diff --git a/src/bls/bls_worker.cpp b/src/bls/bls_worker.cpp index d6344cad71..87152b7b11 100644 --- a/src/bls/bls_worker.cpp +++ b/src/bls/bls_worker.cpp @@ -8,6 +8,9 @@ #include +#include +#include + template bool VerifyVectorHelper(const std::vector& vec, size_t start, size_t count) { @@ -431,11 +434,11 @@ struct ContributionVerifier { std::atomic verifyDoneCount{0}; std::function&)> doneCallback; - ContributionVerifier(const CBLSId& _forId, const std::vector& _vvecs, + ContributionVerifier(CBLSId _forId, const std::vector& _vvecs, const BLSSecretKeyVector& _skShares, size_t _batchSize, bool _parallel, bool _aggregated, ctpl::thread_pool& _workerPool, std::function&)> _doneCallback) : - forId(_forId), + forId(std::move(_forId)), vvecs(_vvecs), skShares(_skShares), batchSize(_batchSize), @@ -461,7 +464,7 @@ struct ContributionVerifier { for (size_t i = 0; i < batchCount; i++) { auto& batchState = batchStates[i]; - batchState.aggDone.reset(new std::atomic(0)); + batchState.aggDone = std::make_unique>(0); batchState.start = i * batchSize; batchState.count = std::min(batchSize, vvecs.size() - batchState.start); batchState.verifyResults.assign(batchState.count, 0); diff --git a/src/bls/bls_worker.h b/src/bls/bls_worker.h index 6d0c9f3a10..671575ecaa 100644 --- a/src/bls/bls_worker.h +++ b/src/bls/bls_worker.h @@ -11,6 +11,7 @@ #include #include +#include // Low level BLS/DKG stuff. All very compute intensive and optimized for parallelization // The worker tries to parallelize as much as possible and utilizes a few properties of BLS aggregation to speed up things @@ -33,11 +34,11 @@ private: CBLSSignature sig; CBLSPublicKey pubKey; uint256 msgHash; - SigVerifyJob(SigVerifyDoneCallback&& _doneCallback, CancelCond&& _cancelCond, const CBLSSignature& _sig, const CBLSPublicKey& _pubKey, const uint256& _msgHash) : + SigVerifyJob(SigVerifyDoneCallback&& _doneCallback, CancelCond&& _cancelCond, const CBLSSignature& _sig, CBLSPublicKey _pubKey, const uint256& _msgHash) : doneCallback(_doneCallback), cancelCond(_cancelCond), sig(_sig), - pubKey(_pubKey), + pubKey(std::move(_pubKey)), msgHash(_msgHash) { }