Skip to content

Commit 5a7c972

Browse files
committed
update block tools to support v2 plots when generating chains, as well as using the solve_proof() stub in the solver
1 parent 95a7525 commit 5a7c972

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

chia/simulator/block_tools.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from dataclasses import dataclass, replace
1515
from pathlib import Path
1616
from random import Random
17-
from typing import Any, Callable, Optional
17+
from typing import Any, Callable, Optional, Union
1818

1919
import anyio
2020
from chia_puzzles_py.programs import CHIALISP_DESERIALISATION, ROM_BOOTSTRAP_GENERATOR
@@ -64,6 +64,7 @@
6464
from chia.full_node.bundle_tools import simple_solution_generator, simple_solution_generator_backrefs
6565
from chia.plotting.create_plots import PlotKeys, create_plots
6666
from chia.plotting.manager import PlotManager
67+
from chia.plotting.prover import PlotVersion
6768
from chia.plotting.util import (
6869
Params,
6970
PlotRefreshEvents,
@@ -96,6 +97,8 @@
9697
generate_taproot_sk,
9798
make_pos,
9899
passes_plot_filter,
100+
quality_for_partial_proof,
101+
solve_proof,
99102
)
100103
from chia.types.blockchain_format.serialized_program import SerializedProgram
101104
from chia.types.blockchain_format.vdf import VDFInfo, VDFProof
@@ -1511,10 +1514,29 @@ def get_pospaces_for_challenge(
15111514
if not passes_plot_filter(prefix_bits, plot_id, challenge_hash, signage_point):
15121515
continue
15131516

1517+
# v2 plots aren't valid until after the hard fork
1518+
if (
1519+
prev_transaction_b_height < constants.HARD_FORK2_HEIGHT
1520+
and plot_info.prover.get_version() == PlotVersion.V2
1521+
):
1522+
continue
1523+
15141524
new_challenge: bytes32 = calculate_pos_challenge(plot_id, challenge_hash, signage_point)
1515-
qualities = plot_info.prover.get_qualities_for_challenge(new_challenge, plot_strength)
15161525

1517-
for proof_index, quality_str in enumerate(qualities):
1526+
# these are either qualities (v1) or partial proofs (v2)
1527+
proofs: Sequence[Union[bytes32, bytes]]
1528+
v = plot_info.prover.get_version()
1529+
if v == PlotVersion.V1:
1530+
proofs = plot_info.prover.get_qualities_for_challenge(new_challenge, plot_strength)
1531+
else:
1532+
proofs = plot_info.prover.get_partial_proofs_for_challenge(new_challenge, plot_strength)
1533+
1534+
for proof_index, proof in enumerate(proofs):
1535+
if v == PlotVersion.V2:
1536+
quality_str = quality_for_partial_proof(proof, new_challenge)
1537+
elif v == PlotVersion.V1:
1538+
quality_str = bytes32(proof)
1539+
15181540
required_iters = calculate_iterations_quality(
15191541
constants,
15201542
quality_str,
@@ -1527,7 +1549,11 @@ def get_pospaces_for_challenge(
15271549
if required_iters >= calculate_sp_interval_iters(constants, sub_slot_iters):
15281550
continue
15291551

1530-
proof_xs: bytes = plot_info.prover.get_full_proof(new_challenge, proof_index)
1552+
proof_xs: bytes
1553+
if v == PlotVersion.V1:
1554+
proof_xs = plot_info.prover.get_full_proof(new_challenge, proof_index)
1555+
else:
1556+
proof_xs = solve_proof(proof)
15311557

15321558
# Look up local_sk from plot to save locked memory
15331559
(

chia/solver/solver.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from chia.rpc.rpc_server import StateChangedProtocol, default_get_connections
1515
from chia.server.server import ChiaServer
1616
from chia.server.ws_connection import WSChiaConnection
17+
from chia.types.blockchain_format.proof_of_space import solve_proof
1718

1819
log = logging.getLogger(__name__)
1920

@@ -67,7 +68,10 @@ async def manage(self) -> AsyncIterator[None]:
6768

6869
def solve(self, partial_proof: bytes) -> Optional[bytes]:
6970
self.log.debug(f"Solve request: partial={partial_proof.hex()}")
70-
# TODO todo_v2_plots implement actualy calling the solver
71+
try:
72+
return solve_proof(partial_proof)
73+
except Exception:
74+
self.log.exception("solve_proof()")
7175
return None
7276

7377
def get_connections(self, request_node_type: Optional[NodeType]) -> list[dict[str, Any]]:

0 commit comments

Comments
 (0)