Skip to content

Commit

Permalink
Fix deadlock in vdf_client (#97)
Browse files Browse the repository at this point in the history
Add missing logic to handle stopped signal in one-weso proofs.

For one-weso proofs, vdf_client launches two threads to do its work. One
repeatedly squares until a given number of iterations, the second waits
until the first is done squaring and then computes a proof.

The squaring-thread properly handles the "stopped" signal and aborts
early, if signaled. That way, it never reaches the targeted iterations.
The 1weso-thread waits until the target iterations are reached, but does
not handle the "stopped" signal. Thus, for stopped iters, it waits
infinitely.

This situation regularly occurs, vdf_client is running for a bluebox
timelord. Whenever the timelord (Python) process restarts, network
communication errors out, killing the squaring thread. But instead of
the while vdf_client exiting (which would lead to the timelord launcher
cleanly restarting a fresh one), the 1weso thread keeps the vdf_client
alive infinitely.
  • Loading branch information
xearl4 committed Mar 28, 2022
1 parent 11a7dd2 commit cb47a9b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/vdf.h
Expand Up @@ -242,9 +242,11 @@ void repeated_square(form f, const integer& D, const integer& L,
Proof ProveOneWesolowski(uint64_t iters, integer& D, form f, OneWesolowskiCallback* weso,
std::atomic<bool>& stopped)
{
while (weso->iterations < iters) {
while (!stopped && weso->iterations < iters) {
this_thread::sleep_for(1s);
}
if (stopped)
return Proof();
Segment sg(
/*start=*/0,
/*length=*/iters,
Expand Down

0 comments on commit cb47a9b

Please sign in to comment.