Skip to content

Commit cdf6d8b

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 6c69be3 commit cdf6d8b

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

chia/simulator/block_tools.py

Lines changed: 33 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,
@@ -91,10 +92,13 @@
9192
from chia.types.blockchain_format.proof_of_space import (
9293
calculate_pos_challenge,
9394
calculate_prefix_bits,
95+
calculate_required_plot_strength,
9496
generate_plot_public_key,
9597
generate_taproot_sk,
9698
make_pos,
9799
passes_plot_filter,
100+
quality_for_partial_proof,
101+
solve_proof,
98102
)
99103
from chia.types.blockchain_format.serialized_program import SerializedProgram
100104
from chia.types.blockchain_format.vdf import VDFInfo, VDFProof
@@ -1501,6 +1505,8 @@ def get_pospaces_for_challenge(
15011505
rng = random.Random()
15021506
rng.seed(seed)
15031507

1508+
required_plot_strength = calculate_required_plot_strength(constants, prev_transaction_b_height)
1509+
15041510
for plot_info in self.plot_manager.plots.values():
15051511
plot_id: bytes32 = plot_info.prover.get_id()
15061512
if force_plot_id is not None and plot_id != force_plot_id:
@@ -1509,10 +1515,29 @@ def get_pospaces_for_challenge(
15091515
if not passes_plot_filter(prefix_bits, plot_id, challenge_hash, signage_point):
15101516
continue
15111517

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

1515-
for proof_index, quality_str in enumerate(qualities):
1527+
# these are either qualities (v1) or partial proofs (v2)
1528+
proofs: Sequence[Union[bytes32, bytes]]
1529+
v = plot_info.prover.get_version()
1530+
if v == PlotVersion.V1:
1531+
proofs = plot_info.prover.get_qualities_for_challenge(new_challenge)
1532+
else:
1533+
proofs = plot_info.prover.get_partial_proofs_for_challenge(new_challenge, required_plot_strength)
1534+
1535+
for proof_index, proof in enumerate(proofs):
1536+
if v == PlotVersion.V2:
1537+
quality_str = quality_for_partial_proof(proof, new_challenge)
1538+
elif v == PlotVersion.V1:
1539+
quality_str = bytes32(proof)
1540+
15161541
required_iters = calculate_iterations_quality(
15171542
constants,
15181543
quality_str,
@@ -1525,7 +1550,11 @@ def get_pospaces_for_challenge(
15251550
if required_iters >= calculate_sp_interval_iters(constants, sub_slot_iters):
15261551
continue
15271552

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

15301559
# Look up local_sk from plot to save locked memory
15311560
(

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)