mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
bench: adapt bls_dkg tests to nanobench
* stop using global pointers, every run gets a unique pointer for itself * keep tests relatively self contained, remove the need for CleanupBLSDkgTests() * remove parallel tests, they seem to be somewhat unpredictable and seem to have no correlated increased CPU usage * minor cleanup and refactoring, convert struct to class, rearrange variables * correlate batch with quorum, minEpochIterations set to 1, unless tests are known unstable, then set to 10
This commit is contained in:
parent
b5db3c3d65
commit
baabcf4e35
@ -25,7 +25,6 @@ static const char* DEFAULT_BENCH_FILTER = ".*";
|
||||
|
||||
void InitBLSTests();
|
||||
void CleanupBLSTests();
|
||||
void CleanupBLSDkgTests();
|
||||
|
||||
static fs::path SetDataDir()
|
||||
{
|
||||
@ -103,7 +102,6 @@ int main(int argc, char** argv)
|
||||
fs::remove_all(bench_datadir);
|
||||
|
||||
// need to be called before global destructors kick in (PoolAllocator is needed due to many BLSSecretKeys)
|
||||
CleanupBLSDkgTests();
|
||||
CleanupBLSTests();
|
||||
|
||||
ECC_Stop();
|
||||
|
@ -98,7 +98,7 @@ static void BLS_Sign_Normal(benchmark::Bench& bench)
|
||||
secKey.MakeNewKey();
|
||||
|
||||
// Benchmark.
|
||||
bench.minEpochIterations(1000).run([&] {
|
||||
bench.minEpochIterations(100).run([&] {
|
||||
uint256 hash = GetRandHash();
|
||||
secKey.Sign(hash);
|
||||
});
|
||||
@ -115,7 +115,7 @@ static void BLS_Verify_Normal(benchmark::Bench& bench)
|
||||
|
||||
// Benchmark.
|
||||
size_t i = 0;
|
||||
bench.batch(pubKeys.size()).unit("byte").minEpochIterations(20).run([&] {
|
||||
bench.minEpochIterations(20).run([&] {
|
||||
bool valid = sigs[i].VerifyInsecure(pubKeys[i], msgHashes[i]);
|
||||
if (valid && invalid[i]) {
|
||||
std::cout << "expected invalid but it is valid" << std::endl;
|
||||
@ -129,7 +129,7 @@ static void BLS_Verify_Normal(benchmark::Bench& bench)
|
||||
}
|
||||
|
||||
|
||||
static void BLS_Verify_LargeBlock(size_t txCount, benchmark::Bench& bench)
|
||||
static void BLS_Verify_LargeBlock(size_t txCount, benchmark::Bench& bench, uint32_t epoch_iters)
|
||||
{
|
||||
BLSPublicKeyVector pubKeys;
|
||||
BLSSecretKeyVector secKeys;
|
||||
@ -139,7 +139,7 @@ static void BLS_Verify_LargeBlock(size_t txCount, benchmark::Bench& bench)
|
||||
BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
|
||||
|
||||
// Benchmark.
|
||||
bench.run([&] {
|
||||
bench.minEpochIterations(epoch_iters).run([&] {
|
||||
for (size_t i = 0; i < pubKeys.size(); i++) {
|
||||
sigs[i].VerifyInsecure(pubKeys[i], msgHashes[i]);
|
||||
}
|
||||
@ -148,15 +148,15 @@ static void BLS_Verify_LargeBlock(size_t txCount, benchmark::Bench& bench)
|
||||
|
||||
static void BLS_Verify_LargeBlock100(benchmark::Bench& bench)
|
||||
{
|
||||
BLS_Verify_LargeBlock(100, bench);
|
||||
BLS_Verify_LargeBlock(100, bench, 10);
|
||||
}
|
||||
|
||||
static void BLS_Verify_LargeBlock1000(benchmark::Bench& bench)
|
||||
{
|
||||
BLS_Verify_LargeBlock(1000, bench);
|
||||
BLS_Verify_LargeBlock(1000, bench, 1);
|
||||
}
|
||||
|
||||
static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::Bench& bench)
|
||||
static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::Bench& bench, uint32_t epoch_iters)
|
||||
{
|
||||
BLSPublicKeyVector pubKeys;
|
||||
BLSSecretKeyVector secKeys;
|
||||
@ -166,7 +166,7 @@ static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::Bench
|
||||
BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
|
||||
|
||||
// Benchmark.
|
||||
bench.run([&] {
|
||||
bench.minEpochIterations(epoch_iters).run([&] {
|
||||
CBLSSignature aggSig = CBLSSignature::AggregateInsecure(sigs);
|
||||
aggSig.VerifyInsecureAggregated(pubKeys, msgHashes);
|
||||
});
|
||||
@ -174,15 +174,15 @@ static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::Bench
|
||||
|
||||
static void BLS_Verify_LargeBlockSelfAggregated100(benchmark::Bench& bench)
|
||||
{
|
||||
BLS_Verify_LargeBlockSelfAggregated(100, bench);
|
||||
BLS_Verify_LargeBlockSelfAggregated(100, bench, 10);
|
||||
}
|
||||
|
||||
static void BLS_Verify_LargeBlockSelfAggregated1000(benchmark::Bench& bench)
|
||||
{
|
||||
BLS_Verify_LargeBlockSelfAggregated(1000, bench);
|
||||
BLS_Verify_LargeBlockSelfAggregated(1000, bench, 2);
|
||||
}
|
||||
|
||||
static void BLS_Verify_LargeAggregatedBlock(size_t txCount, benchmark::Bench& bench)
|
||||
static void BLS_Verify_LargeAggregatedBlock(size_t txCount, benchmark::Bench& bench, uint32_t epoch_iters)
|
||||
{
|
||||
BLSPublicKeyVector pubKeys;
|
||||
BLSSecretKeyVector secKeys;
|
||||
@ -194,19 +194,19 @@ static void BLS_Verify_LargeAggregatedBlock(size_t txCount, benchmark::Bench& be
|
||||
CBLSSignature aggSig = CBLSSignature::AggregateInsecure(sigs);
|
||||
|
||||
// Benchmark.
|
||||
bench.minEpochIterations(10).run([&] {
|
||||
bench.minEpochIterations(epoch_iters).run([&] {
|
||||
aggSig.VerifyInsecureAggregated(pubKeys, msgHashes);
|
||||
});
|
||||
}
|
||||
|
||||
static void BLS_Verify_LargeAggregatedBlock100(benchmark::Bench& bench)
|
||||
{
|
||||
BLS_Verify_LargeAggregatedBlock(100, bench);
|
||||
BLS_Verify_LargeAggregatedBlock(100, bench, 10);
|
||||
}
|
||||
|
||||
static void BLS_Verify_LargeAggregatedBlock1000(benchmark::Bench& bench)
|
||||
{
|
||||
BLS_Verify_LargeAggregatedBlock(1000, bench);
|
||||
BLS_Verify_LargeAggregatedBlock(1000, bench, 1);
|
||||
}
|
||||
|
||||
static void BLS_Verify_LargeAggregatedBlock1000PreVerified(benchmark::Bench& bench)
|
||||
|
@ -15,35 +15,16 @@ struct Member {
|
||||
BLSSecretKeyVector skShares;
|
||||
};
|
||||
|
||||
struct DKG
|
||||
class DKG
|
||||
{
|
||||
std::vector<Member> members;
|
||||
private:
|
||||
std::vector<CBLSId> ids;
|
||||
|
||||
std::vector<Member> members;
|
||||
std::vector<BLSVerificationVectorPtr> receivedVvecs;
|
||||
|
||||
BLSSecretKeyVector receivedSkShares;
|
||||
|
||||
BLSVerificationVectorPtr quorumVvec;
|
||||
|
||||
DKG(int quorumSize)
|
||||
{
|
||||
members.reserve(quorumSize);
|
||||
ids.reserve(quorumSize);
|
||||
|
||||
for (int i = 0; i < quorumSize; i++) {
|
||||
uint256 id;
|
||||
WriteLE64(id.begin(), i + 1);
|
||||
members.push_back({CBLSId(id), {}, {}});
|
||||
ids.emplace_back(id);
|
||||
}
|
||||
|
||||
for (int i = 0; i < quorumSize; i++) {
|
||||
blsWorker.GenerateContributions(quorumSize / 2 + 1, ids, members[i].vvec, members[i].skShares);
|
||||
}
|
||||
|
||||
//printf("initialized quorum %d\n", quorumSize);
|
||||
}
|
||||
|
||||
void ReceiveVvecs()
|
||||
{
|
||||
receivedVvecs.clear();
|
||||
@ -61,24 +42,9 @@ struct DKG
|
||||
}
|
||||
}
|
||||
|
||||
void BuildQuorumVerificationVector(bool parallel)
|
||||
void VerifyContributionShares(size_t whoAmI, const std::set<size_t>& invalidIndexes, bool aggregated)
|
||||
{
|
||||
quorumVvec = blsWorker.BuildQuorumVerificationVector(receivedVvecs, 0, 0, parallel);
|
||||
//assert(worker.VerifyVerificationVector(*members[memberIdx].quorumVvec));
|
||||
}
|
||||
|
||||
void Bench_BuildQuorumVerificationVectors(benchmark::Bench& bench, bool parallel)
|
||||
{
|
||||
ReceiveVvecs();
|
||||
|
||||
bench.run([&] {
|
||||
BuildQuorumVerificationVector(parallel);
|
||||
});
|
||||
}
|
||||
|
||||
void VerifyContributionShares(size_t whoAmI, const std::set<size_t>& invalidIndexes, bool parallel, bool aggregated)
|
||||
{
|
||||
auto result = blsWorker.VerifyContributionShares(members[whoAmI].id, receivedVvecs, receivedSkShares, parallel, aggregated);
|
||||
auto result = blsWorker.VerifyContributionShares(members[whoAmI].id, receivedVvecs, receivedSkShares, aggregated);
|
||||
for (size_t i = 0; i < receivedVvecs.size(); i++) {
|
||||
if (invalidIndexes.count(i)) {
|
||||
assert(!result[i]);
|
||||
@ -88,13 +54,38 @@ struct DKG
|
||||
}
|
||||
}
|
||||
|
||||
void Bench_VerifyContributionShares(benchmark::Bench& bench, int invalidCount, bool parallel, bool aggregated)
|
||||
public:
|
||||
DKG(int quorumSize)
|
||||
{
|
||||
members.reserve(quorumSize);
|
||||
ids.reserve(quorumSize);
|
||||
|
||||
for (int i = 0; i < quorumSize; i++) {
|
||||
uint256 id;
|
||||
WriteLE64(id.begin(), i + 1);
|
||||
members.push_back({CBLSId(id), {}, {}});
|
||||
ids.emplace_back(id);
|
||||
}
|
||||
|
||||
for (int i = 0; i < quorumSize; i++) {
|
||||
blsWorker.GenerateContributions(quorumSize / 2 + 1, ids, members[i].vvec, members[i].skShares);
|
||||
}
|
||||
}
|
||||
|
||||
void Bench_BuildQuorumVerificationVectors(benchmark::Bench& bench, uint32_t epoch_iters)
|
||||
{
|
||||
ReceiveVvecs();
|
||||
|
||||
// Benchmark.
|
||||
bench.minEpochIterations(epoch_iters).run([&] {
|
||||
quorumVvec = blsWorker.BuildQuorumVerificationVector(receivedVvecs, 0, 0, false);
|
||||
});
|
||||
}
|
||||
|
||||
void Bench_VerifyContributionShares(benchmark::Bench& bench, int invalidCount, bool aggregated, uint32_t epoch_iters)
|
||||
{
|
||||
ReceiveVvecs();
|
||||
size_t memberIdx = 0;
|
||||
bench.run([&] {
|
||||
bench.minEpochIterations(epoch_iters).run([&] {
|
||||
auto& m = members[memberIdx];
|
||||
|
||||
ReceiveShares(memberIdx);
|
||||
@ -106,78 +97,39 @@ struct DKG
|
||||
invalidIndexes.emplace(shareIdx);
|
||||
}
|
||||
|
||||
VerifyContributionShares(memberIdx, invalidIndexes, parallel, aggregated);
|
||||
VerifyContributionShares(memberIdx, invalidIndexes, aggregated);
|
||||
|
||||
memberIdx = (memberIdx + 1) % members.size();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<DKG> dkg10;
|
||||
std::shared_ptr<DKG> dkg100;
|
||||
std::shared_ptr<DKG> dkg400;
|
||||
|
||||
void InitIfNeeded()
|
||||
{
|
||||
if (dkg10 == nullptr) {
|
||||
dkg10 = std::make_shared<DKG>(10);
|
||||
}
|
||||
if (dkg100 == nullptr) {
|
||||
dkg100 = std::make_shared<DKG>(100);
|
||||
}
|
||||
if (dkg400 == nullptr) {
|
||||
dkg400 = std::make_shared<DKG>(400);
|
||||
}
|
||||
}
|
||||
|
||||
void CleanupBLSDkgTests()
|
||||
{
|
||||
dkg10.reset();
|
||||
dkg100.reset();
|
||||
dkg400.reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define BENCH_BuildQuorumVerificationVectors(name, quorumSize, parallel, num_iters_for_one_second) \
|
||||
#define BENCH_BuildQuorumVerificationVectors(name, quorumSize, epoch_iters) \
|
||||
static void BLSDKG_BuildQuorumVerificationVectors_##name##_##quorumSize(benchmark::Bench& bench) \
|
||||
{ \
|
||||
InitIfNeeded(); \
|
||||
dkg##quorumSize->Bench_BuildQuorumVerificationVectors(bench, parallel); \
|
||||
std::unique_ptr<DKG> ptr = std::make_unique<DKG>(quorumSize); \
|
||||
ptr->Bench_BuildQuorumVerificationVectors(bench, epoch_iters); \
|
||||
ptr.reset(); \
|
||||
} \
|
||||
BENCHMARK(BLSDKG_BuildQuorumVerificationVectors_##name##_##quorumSize)
|
||||
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 10, false, 11000)
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 100, false, 110)
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 400, false, 6)
|
||||
BENCH_BuildQuorumVerificationVectors(parallel, 10, true, 12000)
|
||||
BENCH_BuildQuorumVerificationVectors(parallel, 100, true, 170)
|
||||
BENCH_BuildQuorumVerificationVectors(parallel, 400, true, 8)
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
|
||||
|
||||
#define BENCH_VerifyContributionShares(name, quorumSize, invalidCount, parallel, aggregated, num_iters_for_one_second) \
|
||||
#define BENCH_VerifyContributionShares(name, quorumSize, invalidCount, aggregated, epoch_iters) \
|
||||
static void BLSDKG_VerifyContributionShares_##name##_##quorumSize(benchmark::Bench& bench) \
|
||||
{ \
|
||||
InitIfNeeded(); \
|
||||
dkg##quorumSize->Bench_VerifyContributionShares(bench, invalidCount, parallel, aggregated); \
|
||||
std::unique_ptr<DKG> ptr = std::make_unique<DKG>(quorumSize); \
|
||||
ptr->Bench_VerifyContributionShares(bench, invalidCount, aggregated, epoch_iters); \
|
||||
ptr.reset(); \
|
||||
} \
|
||||
BENCHMARK(BLSDKG_VerifyContributionShares_##name##_##quorumSize)
|
||||
|
||||
BENCH_VerifyContributionShares(simple, 10, 5, false, false, 70)
|
||||
BENCH_VerifyContributionShares(simple, 100, 5, false, false, 1)
|
||||
BENCH_VerifyContributionShares(simple, 400, 5, false, false, 1)
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 10, 1000)
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 100, 10)
|
||||
BENCH_BuildQuorumVerificationVectors(simple, 400, 1)
|
||||
|
||||
BENCH_VerifyContributionShares(aggregated, 10, 5, false, true, 70)
|
||||
BENCH_VerifyContributionShares(aggregated, 100, 5, false, true, 2)
|
||||
BENCH_VerifyContributionShares(aggregated, 400, 5, false, true, 1)
|
||||
BENCH_VerifyContributionShares(simple, 10, 5, false, 10)
|
||||
BENCH_VerifyContributionShares(simple, 100, 5, false, 10)
|
||||
BENCH_VerifyContributionShares(simple, 400, 5, false, 1)
|
||||
|
||||
BENCH_VerifyContributionShares(parallel, 10, 5, true, false, 200)
|
||||
BENCH_VerifyContributionShares(parallel, 100, 5, true, false, 2)
|
||||
BENCH_VerifyContributionShares(parallel, 400, 5, true, false, 1)
|
||||
|
||||
BENCH_VerifyContributionShares(parallel_aggregated, 10, 5, true, true, 150)
|
||||
BENCH_VerifyContributionShares(parallel_aggregated, 100, 5, true, true, 4)
|
||||
BENCH_VerifyContributionShares(parallel_aggregated, 400, 5, true, true, 1)
|
||||
BENCH_VerifyContributionShares(aggregated, 10, 5, true, 100)
|
||||
BENCH_VerifyContributionShares(aggregated, 100, 5, true, 10)
|
||||
BENCH_VerifyContributionShares(aggregated, 400, 5, true, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user