Skip to content

Commit fcc0415

Browse files
authored
[CHIA-3701] cleanup check_plots (#19981)
* use monotonic clock to time check_plots operations * move exception block up to save a level of indentation * fix call to validate_proof()
1 parent 27bcf4b commit fcc0415

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

chia/plotting/check_plots.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections import Counter
66
from pathlib import Path
77
from threading import Lock
8-
from time import sleep, time
8+
from time import monotonic, sleep
99
from typing import Optional
1010

1111
from chia_rs import G1Element
@@ -172,45 +172,16 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
172172
challenge = std_hash(i.to_bytes(32, "big"))
173173
# Some plot errors cause get_qualities_for_challenge to throw a RuntimeError
174174
try:
175-
quality_start_time = round(time() * 1000)
176-
for index, quality_str in enumerate(pr.get_qualities_for_challenge(challenge)):
177-
quality_spent_time = round(time() * 1000) - quality_start_time
178-
if quality_spent_time > 8000:
179-
log.warning(
180-
f"\tLooking up qualities took: {quality_spent_time} ms. This should be below 8 seconds "
181-
f"to minimize risk of losing rewards. Filepath: {plot_path}"
182-
)
183-
else:
184-
log.info(f"\tLooking up qualities took: {quality_spent_time} ms. Filepath: {plot_path}")
185-
186-
# Other plot errors cause get_full_proof or validate_proof to throw an AssertionError
187-
try:
188-
proof_start_time = round(time() * 1000)
189-
# TODO : todo_v2_plots handle v2 plots
190-
proof = pr.get_full_proof(challenge, index, parallel_read)
191-
proof_spent_time = round(time() * 1000) - proof_start_time
192-
if proof_spent_time > 15000:
193-
log.warning(
194-
f"\tFinding proof took: {proof_spent_time} ms. This should be below 15 seconds "
195-
f"to minimize risk of losing rewards. Filepath: {plot_path}"
196-
)
197-
else:
198-
log.info(f"\tFinding proof took: {proof_spent_time} ms. Filepath: {plot_path}")
199-
200-
ver_quality_str = v.validate_proof(pr.get_id(), pr.get_size(), challenge, proof)
201-
if quality_str == ver_quality_str:
202-
total_proofs += 1
203-
else:
204-
log.warning(
205-
f"\tQuality doesn't match with proof. Filepath: {plot_path} "
206-
"This can occasionally happen with a compressed plot."
207-
)
208-
except AssertionError as e:
209-
log.error(
210-
f"{type(e)}: {e} error in proving/verifying for plot {plot_path}. Filepath: {plot_path}"
211-
)
212-
caught_exception = True
213-
quality_start_time = round(time() * 1000)
175+
quality_start_time = round(monotonic() * 1000)
176+
qualities = pr.get_qualities_for_challenge(challenge)
177+
quality_spent_time = round(monotonic() * 1000) - quality_start_time
178+
if quality_spent_time > 8000:
179+
log.warning(
180+
f"\tLooking up qualities took: {quality_spent_time} ms. This should be below 8 seconds "
181+
f"to minimize risk of losing rewards. Filepath: {plot_path}"
182+
)
183+
else:
184+
log.info(f"\tLooking up qualities took: {quality_spent_time} ms. Filepath: {plot_path}")
214185
except KeyboardInterrupt:
215186
log.warning("Interrupted, closing")
216187
return
@@ -224,9 +195,40 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
224195
else:
225196
log.error(f"{type(e)}: {e} error in getting challenge qualities for plot {plot_path}")
226197
caught_exception = True
198+
continue
227199
except Exception as e:
228200
log.error(f"{type(e)}: {e} error in getting challenge qualities for plot {plot_path}")
229201
caught_exception = True
202+
break
203+
204+
for index, quality_str in enumerate(qualities):
205+
# Other plot errors cause get_full_proof or validate_proof to throw an AssertionError
206+
try:
207+
proof_start_time = round(monotonic() * 1000)
208+
# TODO : todo_v2_plots handle v2 plots
209+
proof = pr.get_full_proof(challenge, index, parallel_read)
210+
proof_spent_time = round(monotonic() * 1000) - proof_start_time
211+
if proof_spent_time > 15000:
212+
log.warning(
213+
f"\tFinding proof took: {proof_spent_time} ms. This should be below 15 seconds "
214+
f"to minimize risk of losing rewards. Filepath: {plot_path}"
215+
)
216+
else:
217+
log.info(f"\tFinding proof took: {proof_spent_time} ms. Filepath: {plot_path}")
218+
219+
ver_quality_str = v.validate_proof(pr.get_id(), pr.get_size().size_v1, challenge, proof)
220+
if quality_str == ver_quality_str:
221+
total_proofs += 1
222+
else:
223+
log.warning(
224+
f"\tQuality doesn't match with proof. Filepath: {plot_path} "
225+
"This can occasionally happen with a compressed plot."
226+
)
227+
except AssertionError as e:
228+
log.error(
229+
f"{type(e)}: {e} error in proving/verifying for plot {plot_path}. Filepath: {plot_path}"
230+
)
231+
caught_exception = True
230232
if caught_exception is True:
231233
break
232234

0 commit comments

Comments
 (0)