From 9d1bc137a3ebaa45a76ebaee20504e70586e4d20 Mon Sep 17 00:00:00 2001 From: "xchdata.io" Date: Sat, 11 Dec 2021 00:55:20 +0100 Subject: [PATCH] Fix deadlock in vdf_client 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. --- src/vdf.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vdf.h b/src/vdf.h index 6c92fe6a..0f5f1e9f 100644 --- a/src/vdf.h +++ b/src/vdf.h @@ -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& 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,