mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
refactor: modifications to GenerateContributions (#4594)
* modifications to GenerateContributions * Introduce some benchmarks to ensure there's no regression * minor fixups Signed-off-by: pasta <pasta@dashboost.org>
This commit is contained in:
parent
8f36cfe236
commit
58d3e1381b
@ -106,6 +106,47 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static void BLSDKG_GenerateContributions(benchmark::Bench& bench, uint32_t epoch_iters, int quorumSize)
|
||||
{
|
||||
CBLSWorker blsWorker;
|
||||
blsWorker.Start();
|
||||
std::vector<CBLSId> ids;
|
||||
std::vector<Member> members;
|
||||
for (int i = 0; i < quorumSize; i++) {
|
||||
uint256 id;
|
||||
WriteLE64(id.begin(), i + 1);
|
||||
members.push_back({CBLSId(id), {}, {}});
|
||||
ids.emplace_back(id);
|
||||
}
|
||||
bench.minEpochIterations(epoch_iters).run([&blsWorker, &quorumSize, &ids, &members] {
|
||||
for (int i = 0; i < quorumSize; i++) {
|
||||
blsWorker.GenerateContributions(quorumSize / 2 + 1, ids, members[i].vvec, members[i].skShares);
|
||||
}
|
||||
});
|
||||
blsWorker.Stop();
|
||||
}
|
||||
|
||||
#define BENCH_GenerateContributions(name, quorumSize, epoch_iters) \
|
||||
static void BLSDKG_GenerateContributions_##name##_##quorumSize(benchmark::Bench& bench) \
|
||||
{ \
|
||||
BLSDKG_InitDKG(bench, epoch_iters, quorumSize); \
|
||||
} \
|
||||
BENCHMARK(BLSDKG_GenerateContributions_##name##_##quorumSize)
|
||||
|
||||
static void BLSDKG_InitDKG(benchmark::Bench& bench, uint32_t epoch_iters, int quorumSize)
|
||||
{
|
||||
bench.minEpochIterations(epoch_iters).run([&] {
|
||||
DKG d(quorumSize);
|
||||
});
|
||||
}
|
||||
|
||||
#define BENCH_InitDKG(name, quorumSize, epoch_iters) \
|
||||
static void BLSDKG_InitDKG_##name##_##quorumSize(benchmark::Bench& bench) \
|
||||
{ \
|
||||
BLSDKG_InitDKG(bench, epoch_iters, quorumSize); \
|
||||
} \
|
||||
BENCHMARK(BLSDKG_InitDKG_##name##_##quorumSize)
|
||||
|
||||
#define BENCH_BuildQuorumVerificationVectors(name, quorumSize, epoch_iters) \
|
||||
static void BLSDKG_BuildQuorumVerificationVectors_##name##_##quorumSize(benchmark::Bench& bench) \
|
||||
{ \
|
||||
@ -124,6 +165,12 @@ public:
|
||||
} \
|
||||
BENCHMARK(BLSDKG_VerifyContributionShares_##name##_##quorumSize)
|
||||
|
||||
BENCH_GenerateContributions(simple, 10, 50);
|
||||
BENCH_GenerateContributions(simple, 50, 5);
|
||||
|
||||
BENCH_InitDKG(simple, 10, 100)
|
||||
BENCH_InitDKG(simple, 50, 10)
|
||||
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 10, 1000)
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 100, 10)
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 400, 1)
|
||||
|
@ -75,22 +75,23 @@ void CBLSWorker::Stop()
|
||||
|
||||
bool CBLSWorker::GenerateContributions(int quorumThreshold, const BLSIdVector& ids, BLSVerificationVectorPtr& vvecRet, BLSSecretKeyVector& skSharesRet)
|
||||
{
|
||||
auto svec = std::make_shared<BLSSecretKeyVector>((size_t)quorumThreshold);
|
||||
auto svec = BLSSecretKeyVector((size_t)quorumThreshold);
|
||||
vvecRet = std::make_shared<BLSVerificationVector>((size_t)quorumThreshold);
|
||||
skSharesRet.resize(ids.size());
|
||||
|
||||
for (int i = 0; i < quorumThreshold; i++) {
|
||||
(*svec)[i].MakeNewKey();
|
||||
svec[i].MakeNewKey();
|
||||
}
|
||||
std::list<std::future<bool> > futures;
|
||||
size_t batchSize = 8;
|
||||
std::vector<std::future<bool>> futures;
|
||||
futures.reserve((quorumThreshold / batchSize + ids.size() / batchSize) + 2);
|
||||
|
||||
for (size_t i = 0; i < quorumThreshold; i += batchSize) {
|
||||
size_t start = i;
|
||||
size_t count = std::min(batchSize, quorumThreshold - start);
|
||||
auto f = [&, start, count](int threadId) {
|
||||
for (size_t j = start; j < start + count; j++) {
|
||||
(*vvecRet)[j] = (*svec)[j].GetPublicKey();
|
||||
(*vvecRet)[j] = svec[j].GetPublicKey();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
@ -102,7 +103,7 @@ bool CBLSWorker::GenerateContributions(int quorumThreshold, const BLSIdVector& i
|
||||
size_t count = std::min(batchSize, ids.size() - start);
|
||||
auto f = [&, start, count](int threadId) {
|
||||
for (size_t j = start; j < start + count; j++) {
|
||||
if (!skSharesRet[j].SecretKeyShare(*svec, ids[j])) {
|
||||
if (!skSharesRet[j].SecretKeyShare(svec, ids[j])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -110,13 +111,9 @@ bool CBLSWorker::GenerateContributions(int quorumThreshold, const BLSIdVector& i
|
||||
};
|
||||
futures.emplace_back(workerPool.push(f));
|
||||
}
|
||||
bool success = true;
|
||||
for (auto& f : futures) {
|
||||
if (!f.get()) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
return std::all_of(futures.begin(), futures.end(), [](auto& f){
|
||||
return f.get();
|
||||
});
|
||||
}
|
||||
|
||||
// aggregates a single vector of BLS objects in parallel
|
||||
|
Loading…
Reference in New Issue
Block a user