Skip to content

Commit 8f94802

Browse files
committed
support v2 plots in check-plots
1 parent b69ce03 commit 8f94802

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

chia/plotting/check_plots.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +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

1517
from chia.consensus.default_constants import DEFAULT_CONSTANTS
1618
from chia.plotting.manager import PlotManager
19+
from chia.plotting.prover import PlotVersion
1720
from chia.plotting.util import (
1821
PlotInfo,
1922
PlotRefreshEvents,
@@ -23,6 +26,10 @@
2326
get_plot_filenames,
2427
parse_plot_info,
2528
)
29+
from chia.types.blockchain_format.proof_of_space import (
30+
quality_for_partial_proof,
31+
solve_proof,
32+
)
2633
from chia.util.bech32m import encode_puzzle_hash
2734
from chia.util.config import load_config
2835
from chia.util.cpu import available_logical_cores
@@ -169,12 +176,20 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
169176

170177
total_proofs = 0
171178
caught_exception: bool = False
179+
version = pr.get_version()
172180
for i in range(num_start, num_end):
173181
challenge = std_hash(i.to_bytes(32, "big"))
182+
# these are either qualities (v1) or partial proofs (v2)
183+
proofs: Sequence[Union[bytes32, bytes]]
174184
# Some plot errors cause get_qualities_for_challenge to throw a RuntimeError
175185
try:
176186
quality_start_time = round(monotonic() * 1000)
177-
qualities = pr.get_qualities_for_challenge(challenge, DEFAULT_CONSTANTS.PLOT_DIFFICULTY_INITIAL)
187+
if version == PlotVersion.V1:
188+
proofs = pr.get_qualities_for_challenge(challenge, DEFAULT_CONSTANTS.PLOT_DIFFICULTY_INITIAL)
189+
else:
190+
proofs = pr.get_partial_proofs_for_challenge(
191+
challenge, DEFAULT_CONSTANTS.PLOT_DIFFICULTY_INITIAL
192+
)
178193
quality_spent_time = round(monotonic() * 1000) - quality_start_time
179194
if quality_spent_time > 8000:
180195
log.warning(
@@ -202,12 +217,17 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
202217
caught_exception = True
203218
break
204219

205-
for index, quality_str in enumerate(qualities):
220+
for index, proof in enumerate(proofs):
206221
# Other plot errors cause get_full_proof or validate_proof to throw an AssertionError
207222
try:
208223
proof_start_time = round(monotonic() * 1000)
209-
# TODO : todo_v2_plots handle v2 plots
210-
proof = pr.get_full_proof(challenge, index, parallel_read)
224+
if version == PlotVersion.V1:
225+
quality_str = bytes32(proof)
226+
full_proof = pr.get_full_proof(challenge, index, parallel_read)
227+
else:
228+
quality_str = quality_for_partial_proof(proof, challenge)
229+
full_proof = solve_proof(proof)
230+
211231
proof_spent_time = round(monotonic() * 1000) - proof_start_time
212232
if proof_spent_time > 15000:
213233
log.warning(
@@ -217,7 +237,7 @@ def process_plot(plot_path: Path, plot_info: PlotInfo, num_start: int, num_end:
217237
else:
218238
log.info(f"\tFinding proof took: {proof_spent_time} ms. Filepath: {plot_path}")
219239

220-
ver_quality_str = v.validate_proof(pr.get_id(), pr.get_size().size_v1, challenge, proof)
240+
ver_quality_str = v.validate_proof(pr.get_id(), pr.get_size().size_v1, challenge, full_proof)
221241
if quality_str == ver_quality_str:
222242
total_proofs += 1
223243
else:

0 commit comments

Comments
 (0)