Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop 1-Weso squaring on reaching target iterations #174

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/1weso_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char const* argv[]) try
uint64_t iter = iter_multiplier;
OneWesolowskiCallback weso(D, f, iter);
FastStorage* fast_storage = nullptr;
std::thread vdf_worker(repeated_square, f, D, L, &weso, fast_storage, std::ref(stopped));
std::thread vdf_worker(repeated_square, iter, f, D, L, &weso, fast_storage, std::ref(stopped));
Proof const proof = ProveOneWesolowski(iter, D, f, &weso, stopped);
stopped = true;
vdf_worker.join();
Expand Down
2 changes: 1 addition & 1 deletion src/2weso_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char const* argv[]) try
two_weso = true;
TwoWesolowskiCallback weso(D, f);
FastStorage* fast_storage = NULL;
std::thread vdf_worker(repeated_square, f, D, L, &weso, fast_storage, std::ref(stopped));
std::thread vdf_worker(repeated_square, 0, f, D, L, &weso, fast_storage, std::ref(stopped));
// Test 1 - 1 million iters.
uint64_t iteration = 1 * iter_multiplier;
Proof proof = ProveTwoWeso(D, f, iteration, 0, &weso, 0, stopped);
Expand Down
2 changes: 1 addition & 1 deletion src/prover_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main() {
if (multi_proc_machine) {
fast_storage = new FastStorage((FastAlgorithmCallback*)weso);
}
std::thread vdf_worker(repeated_square, f, D, L, weso, fast_storage, std::ref(stopped));
std::thread vdf_worker(repeated_square, 0, f, D, L, weso, fast_storage, std::ref(stopped));
ProverManager pm(D, (FastAlgorithmCallback*)weso, fast_storage, segments, thread_count);
pm.start();
std::vector<std::thread> threads;
Expand Down
7 changes: 6 additions & 1 deletion src/vdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void repeated_square_original(vdf_original &vdfo, form& f, const integer& D, con
}

// thread safe; but it is only called from the main thread
void repeated_square(form f, const integer& D, const integer& L,
void repeated_square(uint64_t iterations, form f, const integer& D, const integer& L,
WesolowskiCallback* weso, FastStorage* fast_storage, std::atomic<bool>& stopped)
{
#ifdef VDF_TEST
Expand Down Expand Up @@ -221,6 +221,11 @@ void repeated_square(form f, const integer& D, const integer& L,
last_checkpoint += (1 << 15);
}

if (iterations != 0 && num_iterations > iterations) {
weso->iterations = num_iterations;
break;
}

#ifdef VDF_TEST
if (vdf_test_correctness) {
form f_copy_2=f;
Expand Down
6 changes: 3 additions & 3 deletions src/vdf_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void SessionFastAlgorithm(tcp::socket& sock) {
fast_storage = new FastStorage((FastAlgorithmCallback*)weso);
}
std::atomic<bool> stopped(false);
std::thread vdf_worker(repeated_square, f, std::ref(D), std::ref(L), weso, fast_storage, std::ref(stopped));
std::thread vdf_worker(repeated_square, 0, f, std::ref(D), std::ref(L), weso, fast_storage, std::ref(stopped));
ProverManager pm(D, (FastAlgorithmCallback*)weso, fast_storage, segments, thread_count);
pm.start();

Expand Down Expand Up @@ -211,7 +211,7 @@ void SessionOneWeso(tcp::socket& sock) {
std::atomic<bool> stopped(false);
WesolowskiCallback* weso = new OneWesolowskiCallback(D, f, iter);
FastStorage* fast_storage = NULL;
std::thread vdf_worker(repeated_square, f, std::ref(D), std::ref(L), weso, fast_storage, std::ref(stopped));
std::thread vdf_worker(repeated_square, iter, f, std::ref(D), std::ref(L), weso, fast_storage, std::ref(stopped));
std::thread th_prover(CreateAndWriteProofOneWeso, iter, std::ref(D), f, (OneWesolowskiCallback*)weso, std::ref(stopped), std::ref(sock));
iter = ReadIteration(sock);
while (iter != 0) {
Expand Down Expand Up @@ -247,7 +247,7 @@ void SessionTwoWeso(tcp::socket& sock) {
std::set<std::pair<uint64_t, uint64_t> > seen_iterations;
WesolowskiCallback* weso = new TwoWesolowskiCallback(D, f);
FastStorage* fast_storage = NULL;
std::thread vdf_worker(repeated_square, f, std::ref(D), std::ref(L), weso, fast_storage, std::ref(stopped));
std::thread vdf_worker(repeated_square, 0, f, std::ref(D), std::ref(L), weso, fast_storage, std::ref(stopped));

while (!stopped) {
uint64_t iters = ReadIteration(sock);
Expand Down