Skip to content

Commit d62a61d

Browse files
authored
[CHIA-3701] Check plots v2 (#19982)
* support v2 plots in check-plots * review comments
1 parent b872728 commit d62a61d

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

chia/plotting/check_plots.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
import concurrent.futures
44
import logging
55
from collections import Counter
6+
from collections.abc import Sequence
67
from pathlib import Path
78
from threading import Lock
89
from time import monotonic, sleep
9-
from typing import Optional
10+
from typing import Optional, Union
1011

1112
from chia_rs import G1Element
13+
from chia_rs.sized_bytes import bytes32
1214
from chia_rs.sized_ints import uint8, uint32
1315
from chiapos import Verifier
1416

17+
from chia.consensus.default_constants import DEFAULT_CONSTANTS
1518
from chia.plotting.manager import PlotManager
19+
from chia.plotting.prover import PlotVersion
1620
from chia.plotting.util import (
1721
PlotInfo,
1822
PlotRefreshEvents,
@@ -22,6 +26,10 @@
2226
get_plot_filenames,
2327
parse_plot_info,
2428
)
29+
from chia.types.blockchain_format.proof_of_space import (
30+
quality_for_partial_proof,
31+
solve_proof,
32+
)
2533
from chia.util.bech32m import encode_puzzle_hash
2634
from chia.util.config import load_config
2735
from chia.util.cpu import available_logical_cores
@@ -168,12 +176,20 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
168176

169177
total_proofs = 0
170178
caught_exception: bool = False
179+
version = pr.get_version()
171180
for i in range(num_start, num_end):
172181
challenge = std_hash(i.to_bytes(32, "big"))
182+
# these are either qualities (v1) or partial proofs (v2)
183+
proofs: Sequence[Union[bytes32, bytes]]
173184
# Some plot errors cause get_qualities_for_challenge to throw a RuntimeError
174185
try:
175186
quality_start_time = round(monotonic() * 1000)
176-
qualities = pr.get_qualities_for_challenge(challenge)
187+
if version == PlotVersion.V1:
188+
proofs = pr.get_qualities_for_challenge(challenge)
189+
else:
190+
proofs = pr.get_partial_proofs_for_challenge(
191+
challenge, DEFAULT_CONSTANTS.PLOT_DIFFICULTY_INITIAL
192+
)
177193
quality_spent_time = round(monotonic() * 1000) - quality_start_time
178194
if quality_spent_time > 8000:
179195
log.warning(
@@ -201,13 +217,19 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
201217
caught_exception = True
202218
break
203219

204-
for index, quality_str in enumerate(qualities):
220+
for index, proof in enumerate(proofs):
205221
# Other plot errors cause get_full_proof or validate_proof to throw an AssertionError
206222
try:
207223
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
224+
if version == PlotVersion.V1:
225+
quality_str = bytes32(proof)
226+
full_proof = pr.get_full_proof(challenge, index, parallel_read)
227+
proof_spent_time = round(monotonic() * 1000) - proof_start_time
228+
else:
229+
quality_str = quality_for_partial_proof(proof, challenge)
230+
proof_spent_time = round(monotonic() * 1000) - proof_start_time
231+
full_proof = solve_proof(proof)
232+
211233
if proof_spent_time > 15000:
212234
log.warning(
213235
f"\tFinding proof took: {proof_spent_time} ms. This should be below 15 seconds "
@@ -216,7 +238,7 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
216238
else:
217239
log.info(f"\tFinding proof took: {proof_spent_time} ms. Filepath: {plot_path}")
218240

219-
ver_quality_str = v.validate_proof(pr.get_id(), pr.get_size().size_v1, challenge, proof)
241+
ver_quality_str = v.validate_proof(pr.get_id(), pr.get_size().size_v1, challenge, full_proof)
220242
if quality_str == ver_quality_str:
221243
total_proofs += 1
222244
else:

0 commit comments

Comments
 (0)