mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
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 <UdjinM6@users.noreply.github.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
parent
c5b919d084
commit
78f277bfe4
@ -72,7 +72,7 @@ bool CBLSIESEncryptedBlob::Decrypt(size_t idx, const CBLSSecretKey& secretKey, C
|
|||||||
|
|
||||||
bool CBLSIESEncryptedBlob::IsValid() const
|
bool CBLSIESEncryptedBlob::IsValid() const
|
||||||
{
|
{
|
||||||
return ephemeralPubKey.IsValid() && data.size() > 0 && !ivSeed.IsNull();
|
return ephemeralPubKey.IsValid() && !data.empty() && !ivSeed.IsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool VerifyVectorHelper(const std::vector<T>& vec, size_t start, size_t count)
|
bool VerifyVectorHelper(const std::vector<T>& vec, size_t start, size_t count)
|
||||||
{
|
{
|
||||||
@ -431,11 +434,11 @@ struct ContributionVerifier {
|
|||||||
std::atomic<size_t> verifyDoneCount{0};
|
std::atomic<size_t> verifyDoneCount{0};
|
||||||
std::function<void(const std::vector<bool>&)> doneCallback;
|
std::function<void(const std::vector<bool>&)> doneCallback;
|
||||||
|
|
||||||
ContributionVerifier(const CBLSId& _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs,
|
ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs,
|
||||||
const BLSSecretKeyVector& _skShares, size_t _batchSize,
|
const BLSSecretKeyVector& _skShares, size_t _batchSize,
|
||||||
bool _parallel, bool _aggregated, ctpl::thread_pool& _workerPool,
|
bool _parallel, bool _aggregated, ctpl::thread_pool& _workerPool,
|
||||||
std::function<void(const std::vector<bool>&)> _doneCallback) :
|
std::function<void(const std::vector<bool>&)> _doneCallback) :
|
||||||
forId(_forId),
|
forId(std::move(_forId)),
|
||||||
vvecs(_vvecs),
|
vvecs(_vvecs),
|
||||||
skShares(_skShares),
|
skShares(_skShares),
|
||||||
batchSize(_batchSize),
|
batchSize(_batchSize),
|
||||||
@ -461,7 +464,7 @@ struct ContributionVerifier {
|
|||||||
for (size_t i = 0; i < batchCount; i++) {
|
for (size_t i = 0; i < batchCount; i++) {
|
||||||
auto& batchState = batchStates[i];
|
auto& batchState = batchStates[i];
|
||||||
|
|
||||||
batchState.aggDone.reset(new std::atomic<int>(0));
|
batchState.aggDone = std::make_unique<std::atomic<int>>(0);
|
||||||
batchState.start = i * batchSize;
|
batchState.start = i * batchSize;
|
||||||
batchState.count = std::min(batchSize, vvecs.size() - batchState.start);
|
batchState.count = std::min(batchSize, vvecs.size() - batchState.start);
|
||||||
batchState.verifyResults.assign(batchState.count, 0);
|
batchState.verifyResults.assign(batchState.count, 0);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
// Low level BLS/DKG stuff. All very compute intensive and optimized for parallelization
|
// 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
|
// 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;
|
CBLSSignature sig;
|
||||||
CBLSPublicKey pubKey;
|
CBLSPublicKey pubKey;
|
||||||
uint256 msgHash;
|
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),
|
doneCallback(_doneCallback),
|
||||||
cancelCond(_cancelCond),
|
cancelCond(_cancelCond),
|
||||||
sig(_sig),
|
sig(_sig),
|
||||||
pubKey(_pubKey),
|
pubKey(std::move(_pubKey)),
|
||||||
msgHash(_msgHash)
|
msgHash(_msgHash)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user