Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
bls_worker.cpp
Go to the documentation of this file.
75 bool CBLSWorker::GenerateContributions(int quorumThreshold, const BLSIdVector& ids, BLSVerificationVectorPtr& vvecRet, BLSSecretKeyVector& skShares)
123 // when enough batches are finished to form a new batch, the new batch is queued for further parallel aggregation
124 // when no more batches can be created from finished batch results, the final aggregated is created and the doneCallback
126 // The Aggregator object needs to be created on the heap and it will delete itself after calling the doneCallback
127 // The input vector is not copied into the Aggregator but instead a vector of pointers to the original entries from the
128 // input vector is stored. This means that the input vector must stay alive for the whole lifetime of the Aggregator
141 // The intermediate results must be deleted by us again (which we do in SyncAggregateAndPushAggQueue)
173 // If parallel=true, then this will return fast, otherwise this will block until aggregation is done
201 // increment wait counter as otherwise the first finished async aggregation might signal that we're done
208 // this will decrement the wait counter and in most cases NOT finish, as async work is still in progress
226 // All async work is done, but we might have items in the aggQueue which are the results of the async
227 // work. This is the case when these did not add up to a new batch. In this case, we have to aggregate
256 void AsyncAggregateAndPushAggQueue(std::shared_ptr<std::vector<const T*> >& vec, size_t start, size_t count, bool del)
262 void SyncAggregateAndPushAggQueue(std::shared_ptr<std::vector<const T*> >& vec, size_t start, size_t count, bool del)
298 // push new batch to work queue. del=true this time as these items are intermediate results and need to be deleted
331 // Same rules for the input vectors apply to the VectorAggregator as for the Aggregator (they must stay alive)
378 auto aggregator = new AggregatorType(std::move(tmp), 0, count, parallel, workerPool, std::bind(&VectorAggregator::CheckDone, this, std::placeholders::_1, i));
379 // we can't directly start the aggregator here as it might be so fast that it deletes "this" while we are still in this loop
407 // starts with 0 and is incremented if either vvec or skShare aggregation finishs. If it reaches 2, we know
500 auto vvecAgg = new VectorAggregator<CBLSPublicKey>(vvecs, batchState.start, batchState.count, parallel, workerPool, std::bind(&ContributionVerifier::HandleAggVvecDone, this, batchIdx, std::placeholders::_1));
501 auto skShareAgg = new Aggregator<CBLSSecretKey>(skShares, batchState.start, batchState.count, parallel, workerPool, std::bind(&ContributionVerifier::HandleAggSkShareDone, this, batchIdx, std::placeholders::_1));
537 // something went wrong while aggregating and there is nothing we can do now except mark the whole batch as failed
557 // at least one entry in the batch is invalid, revert to per-contribution verification (but parallelized)
571 batchState.verifyResults[i] = Verify(vvecs[batchState.start + i], skShares[batchState.start + i]);
600 void CBLSWorker::AsyncBuildQuorumVerificationVector(const std::vector<BLSVerificationVectorPtr>& vvecs,
616 auto agg = new VectorAggregator<CBLSPublicKey>(vvecs, start, count, parallel, workerPool, std::move(doneCallback));
620 std::future<BLSVerificationVectorPtr> CBLSWorker::AsyncBuildQuorumVerificationVector(const std::vector<BLSVerificationVectorPtr>& vvecs,
628 BLSVerificationVectorPtr CBLSWorker::BuildQuorumVerificationVector(const std::vector<BLSVerificationVectorPtr>& vvecs,
662 std::future<CBLSSecretKey> CBLSWorker::AsyncAggregateSecretKeys(const BLSSecretKeyVector& secKeys,
683 std::future<CBLSPublicKey> CBLSWorker::AsyncAggregatePublicKeys(const BLSPublicKeyVector& pubKeys,
719 CBLSPublicKey CBLSWorker::BuildPubKeyShare(const BLSVerificationVectorPtr& vvec, const CBLSId& id)
726 void CBLSWorker::AsyncVerifyContributionShares(const CBLSId& forId, const std::vector<BLSVerificationVectorPtr>& vvecs, const BLSSecretKeyVector& skShares,
736 auto verifier = new ContributionVerifier(forId, vvecs, skShares, 8, parallel, aggregated, workerPool, std::move(doneCallback));
740 std::future<std::vector<bool> > CBLSWorker::AsyncVerifyContributionShares(const CBLSId& forId, const std::vector<BLSVerificationVectorPtr>& vvecs, const BLSSecretKeyVector& skShares,
744 AsyncVerifyContributionShares(forId, vvecs, skShares, parallel, aggregated, std::move(p.first));
748 std::vector<bool> CBLSWorker::VerifyContributionShares(const CBLSId& forId, const std::vector<BLSVerificationVectorPtr>& vvecs, const BLSSecretKeyVector& skShares,
776 bool CBLSWorker::VerifyContributionShare(const CBLSId& forId, const BLSVerificationVectorPtr& vvec,
788 bool CBLSWorker::VerifyVerificationVector(const BLSVerificationVector& vvec, size_t start, size_t count)
823 bool CBLSWorker::VerifySecretKeyVector(const BLSSecretKeyVector& secKeys, size_t start, size_t count)
828 bool CBLSWorker::VerifySignatureVector(const BLSSignatureVector& sigs, size_t start, size_t count)
833 void CBLSWorker::AsyncSign(const CBLSSecretKey& secKey, const uint256& msgHash, CBLSWorker::SignDoneCallback doneCallback)
840 std::future<CBLSSignature> CBLSWorker::AsyncSign(const CBLSSecretKey& secKey, const uint256& msgHash)
847 void CBLSWorker::AsyncVerifySig(const CBLSSignature& sig, const CBLSPublicKey& pubKey, const uint256& msgHash,
866 // batched/aggregated verification does not allow duplicate hashes, so we push what we currently have and start
871 sigVerifyQueue.emplace_back(std::move(doneCallback), std::move(cancelCond), sig, pubKey, msgHash);
877 std::future<bool> CBLSWorker::AsyncVerifySig(const CBLSSignature& sig, const CBLSPublicKey& pubKey, const uint256& msgHash, CancelCond cancelCond)
939 // TODO this could be improved if we would cache pairing results in some way as the previous aggregated verification already calculated all the pairings for the hashes
bool VerifyContributionShare(const CBLSId &forId, const BLSVerificationVectorPtr &vvec, const CBLSSecretKey &skContribution)
Definition: bls_worker.cpp:776
T SyncAggregate(const std::vector< TP > &vec, size_t start, size_t count)
Definition: bls_worker.cpp:305
std::pair< std::function< void(T)>, std::future< T > > BuildFutureDoneCallback2()
Definition: bls_worker.cpp:40
void AsyncVerifyBatchOneByOne(size_t batchIdx)
Definition: bls_worker.cpp:564
void HandleAggSkShareDone(size_t batchIdx, const CBLSSecretKey &skShare)
Definition: bls_worker.cpp:515
Definition: bls.h:238
void AsyncBuildQuorumVerificationVector(const std::vector< BLSVerificationVectorPtr > &vvecs, size_t start, size_t count, bool parallel, std::function< void(const BLSVerificationVectorPtr &)> doneCallback)
Definition: bls_worker.cpp:600
bool VerifySecretKeyVector(const BLSSecretKeyVector &secKeys, size_t start=0, size_t count=0)
Definition: bls_worker.cpp:823
auto push(F &&f, Rest &&... rest) -> std::future< decltype(f(0, rest...))>
Definition: ctpl.h:152
VectorAggregator(const VectorVectorType &_vecs, size_t _start, size_t _count, bool _parallel, ctpl::thread_pool &_workerPool, DoneCallback _doneCallback)
Definition: bls_worker.cpp:352
std::shared_ptr< std::vector< const T * > > inputVec
Definition: bls_worker.cpp:134
void AsyncVerifyContributionShares(const CBLSId &forId, const std::vector< BLSVerificationVectorPtr > &vvecs, const BLSSecretKeyVector &skShares, bool parallel, bool aggregated, std::function< void(const std::vector< bool > &)> doneCallback)
Definition: bls_worker.cpp:726
std::function< void(bool)> SigVerifyDoneCallback
Definition: bls_worker.h:25
std::function< void(const T &agg)> DoneCallback
Definition: bls_worker.cpp:148
CBLSPublicKey AggregatePublicKeys(const BLSPublicKeyVector &pubKeys, size_t start=0, size_t count=0, bool parallel=true)
Definition: bls_worker.cpp:691
Definition: box.hpp:161
BLSVerificationVectorPtr BuildQuorumVerificationVector(const std::vector< BLSVerificationVectorPtr > &vvecs, size_t start=0, size_t count=0, bool parallel=true)
Definition: bls_worker.cpp:628
void AsyncAggregateHelper(ctpl::thread_pool &workerPool, const std::vector< T > &vec, size_t start, size_t count, bool parallel, std::function< void(const T &)> doneCallback)
Definition: bls_worker.cpp:635
bool VerifyVerificationVector(const BLSVerificationVector &vvec, size_t start=0, size_t count=0)
Definition: bls_worker.cpp:788
void HandleAggDone(size_t batchIdx)
Definition: bls_worker.cpp:532
bool GenerateContributions(int threshold, const BLSIdVector &ids, BLSVerificationVectorPtr &vvecRet, BLSSecretKeyVector &skShares)
Definition: bls_worker.cpp:75
void AsyncAggregateAndPushAggQueue(std::shared_ptr< std::vector< const T *> > &vec, size_t start, size_t count, bool del)
Definition: bls_worker.cpp:256
bool VerifyInsecureAggregated(const std::vector< CBLSPublicKey > &pubKeys, const std::vector< uint256 > &hashes) const
Definition: bls.cpp:348
std::function< void(const VectorPtrType &agg)> DoneCallback
Definition: bls_worker.cpp:338
std::shared_ptr< BLSVerificationVector > BLSVerificationVectorPtr
Definition: bls.h:471
bool VerifyVerificationVectors(const std::vector< BLSVerificationVectorPtr > &vvecs, size_t start=0, size_t count=0)
Definition: bls_worker.cpp:793
std::shared_ptr< VectorType > VectorPtrType
Definition: bls_worker.cpp:336
void AsyncAggregatePublicKeys(const BLSPublicKeyVector &pubKeys, size_t start, size_t count, bool parallel, std::function< void(const CBLSPublicKey &)> doneCallback)
Definition: bls_worker.cpp:676
bool VerifySignatureVector(const BLSSignatureVector &sigs, size_t start=0, size_t count=0)
Definition: bls_worker.cpp:828
void AsyncAggregatedVerifyBatch(size_t batchIdx)
Definition: bls_worker.cpp:547
std::atomic< size_t > verifyDoneCount
Definition: bls_worker.cpp:431
void HandleAggVvecDone(size_t batchIdx, const BLSVerificationVectorPtr &vvec)
Definition: bls_worker.cpp:507
CBLSPublicKey BuildPubKeyShare(const BLSVerificationVectorPtr &vvec, const CBLSId &id)
Definition: bls_worker.cpp:719
Definition: bls.h:263
std::pair< std::function< void(const T &)>, std::future< T > > BuildFutureDoneCallback()
Definition: bls_worker.cpp:31
Definition: bls_worker.cpp:399
std::function< void(const CBLSSignature &)> SignDoneCallback
Definition: bls_worker.h:24
void HandleVerifyDone(size_t batchIdx, size_t count)
Definition: bls_worker.cpp:524
Definition: bls.h:286
std::vector< bool > VerifyContributionShares(const CBLSId &forId, const std::vector< BLSVerificationVectorPtr > &vvecs, const BLSSecretKeyVector &skShares, bool parallel=true, bool aggregated=true)
Definition: bls_worker.cpp:748
CBLSSecretKey AggregateSecretKeys(const BLSSecretKeyVector &secKeys, size_t start=0, size_t count=0, bool parallel=true)
Definition: bls_worker.cpp:670
std::shared_ptr< BLSSecretKeyVector > BLSSecretKeyVectorPtr
Definition: bls.h:473
std::unique_ptr< std::atomic< int > > aggDone
Definition: bls_worker.cpp:409
const std::vector< BLSVerificationVectorPtr > & vvecs
Definition: bls_worker.cpp:419
std::vector< VectorPtrType > VectorVectorType
Definition: bls_worker.cpp:337
Definition: bls_worker.cpp:130
bool Verify(const BLSVerificationVectorPtr &vvec, const CBLSSecretKey &skShare)
Definition: bls_worker.cpp:578
void AsyncVerifySig(const CBLSSignature &sig, const CBLSPublicKey &pubKey, const uint256 &msgHash, SigVerifyDoneCallback doneCallback, CancelCond cancelCond=[] { return false;})
Definition: bls_worker.cpp:847
bool PublicKeyShare(const std::vector< CBLSPublicKey > &mpk, const CBLSId &id)
Definition: bls.cpp:218
Definition: bls_worker.cpp:333
void SyncAggregateAndPushAggQueue(std::shared_ptr< std::vector< const T *> > &vec, size_t start, size_t count, bool del)
Definition: bls_worker.cpp:262
void AggregateInsecure(const CBLSSignature &o)
Definition: bls.cpp:277
std::function< void(const std::vector< bool > &)> doneCallback
Definition: bls_worker.cpp:432
void AsyncAggregateSecretKeys(const BLSSecretKeyVector &secKeys, size_t start, size_t count, bool parallel, std::function< void(const CBLSSecretKey &)> doneCallback)
Definition: bls_worker.cpp:655
void AsyncSign(const CBLSSecretKey &secKey, const uint256 &msgHash, SignDoneCallback doneCallback)
Definition: bls_worker.cpp:833
void RenameThreadPool(ctpl::thread_pool &tp, const char *baseName)
Definition: util.cpp:1276
void AsyncAggregate(size_t batchIdx)
Definition: bls_worker.cpp:495
std::future< bool > AsyncVerifyContributionShare(const CBLSId &forId, const BLSVerificationVectorPtr &vvec, const CBLSSecretKey &skContribution)
Definition: bls_worker.cpp:754
ContributionVerifier(const CBLSId &_forId, const std::vector< BLSVerificationVectorPtr > &_vvecs, const BLSSecretKeyVector &_skShares, size_t _batchSize, bool _parallel, bool _aggregated, ctpl::thread_pool &_workerPool, std::function< void(const std::vector< bool > &)> _doneCallback)
Definition: bls_worker.cpp:434
CBLSSignature AggregateSigs(const BLSSignatureVector &sigs, size_t start=0, size_t count=0, bool parallel=true)
Definition: bls_worker.cpp:712
Definition: ctpl.h:48
Aggregator(const std::vector< TP > &_inputVec, size_t start, size_t count, bool _parallel, ctpl::thread_pool &_workerPool, DoneCallback _doneCallback)
Definition: bls_worker.cpp:153
std::vector< char > verifyResults
Definition: bls_worker.cpp:415
void AsyncAggregateSigs(const BLSSignatureVector &sigs, size_t start, size_t count, bool parallel, std::function< void(const CBLSSignature &)> doneCallback)
Definition: bls_worker.cpp:697
std::vector< BatchState > batchStates
Definition: bls_worker.cpp:430
bool VerifyVectorHelper(const std::vector< T > &vec, size_t start, size_t count)
Definition: bls_worker.cpp:12