Skip to content

Commit e191f0a

Browse files
authored
Minor pos2 updates (#20200)
### Purpose: This PR collects a few minor changes, shaved off of my larger PR to integrate v2 plots. These 3 commits are best reviewed one at a time, and are somewhat independent. ### Current Behavior: * We still have some stub functions for the new chiapos2 API. * We use `log.warning()` and `log.error()` to log exceptions. * When farming v1 plots we always get the qualities, adjust them based on phase-out and check against difficulty. ### New Behavior: * The last chiapos2 stub APIs have been removed. * We use `log.exception()` to log exceptions. * When farming v1 plots we short cut and ignore them if the block height is past the end of the phase-out. This is an optimization to avoid scanning the plots for proofs that will never pass the difficulty.
2 parents 09aa4bb + 0879516 commit e191f0a

File tree

6 files changed

+31
-38
lines changed

6 files changed

+31
-38
lines changed

chia/_tests/core/custom_types/test_proof_of_space.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,23 @@ def b32(key: str) -> bytes32:
112112
id="v2 plot size 0",
113113
pos_challenge=bytes32(b"1" * 32),
114114
plot_size=PlotSize.make_v2(0),
115+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
115116
plot_public_key=G1Element(),
116-
pool_public_key=G1Element(),
117117
expected_error="Plot size (0) is lower than the minimum (28)",
118118
),
119119
ProofOfSpaceCase(
120120
id="v2 plot size 34",
121121
pos_challenge=bytes32(b"1" * 32),
122122
plot_size=PlotSize.make_v2(34),
123+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
123124
plot_public_key=G1Element(),
124-
pool_public_key=G1Element(),
125125
expected_error="Plot size (34) is higher than the maximum (32)",
126126
),
127127
ProofOfSpaceCase(
128128
id="Not passing the plot filter v2",
129-
pos_challenge=b32("3d29ea79d19b3f7e99ebf764ae53697cbe143603909873946af6ab1ece606861"),
129+
pos_challenge=b32("2b76a5fe5d4ae062ba9e80b5bcb0e9c1301f3a2787b8f3141e3fb458d1c1864c"),
130130
plot_size=PlotSize.make_v2(32),
131-
pool_public_key=g1(
132-
"b6449c2c68df97c19e884427e42ee7350982d4020571ead08732615ff39bd216bfd630b6460784982bec98b49fea79d0"
133-
),
131+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
134132
plot_public_key=g1(
135133
"879526b4e7b616cfd64984d8ad140d0798b048392a6f11e2faf09054ef467ea44dc0dab5e5edb2afdfa850c5c8b629cc"
136134
),
@@ -160,16 +158,15 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
160158
@datacases(
161159
ProofOfSpaceCase(
162160
id="v2 plot are not implemented",
163-
plot_size=PlotSize.make_v2(30),
164-
pos_challenge=b32("47deb938e145d25d7b3b3c85ca9e3972b76c01aeeb78a02fe5d3b040d282317e"),
161+
plot_size=PlotSize.make_v2(28),
162+
pos_challenge=b32("be7ac7436520a3fa259a618a2c54de4ca8b8d2319c1ec5b11a2ef4c025c2e0a6"),
165163
plot_public_key=g1(
166164
"afa3aaf09c03885154be49216ee7fb2e4581b9c4a4d7e9cc402e27280bf0cfdbdf1b9ba674e301fd1d1450234b3b1868"
167165
),
168-
pool_public_key=g1(
169-
"b6449c2c68df97c19e884427e42ee7350982d4020571ead08732615ff39bd216bfd630b6460784982bec98b49fea79d0"
170-
),
171-
expected_error="NotImplementedError",
166+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
167+
expected_error="Did not pass the plot filter",
172168
),
169+
# TODO: todo_v2_plots add test case that passes the plot filter
173170
)
174171
def test_verify_and_get_quality_string_v2(caplog: pytest.LogCaptureFixture, case: ProofOfSpaceCase) -> None:
175172
pos = make_pos(

chia/harvester/harvester_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ async def lookup_challenge(
398398
)
399399
passed += 1
400400
else:
401+
constants = self.harvester.constants
402+
# after the phase-out, ignore v1 plots
403+
if new_challenge.last_tx_height >= constants.HARD_FORK2_HEIGHT + constants.PLOT_V1_PHASE_OUT:
404+
continue
405+
401406
passed += 1
402407
awaitables.append(lookup_challenge(try_plot_filename, try_plot_info))
403408
self.harvester.log.debug(f"new_signage_point_harvester {passed} plots passed the plot filter")

chia/plot_sync/receiver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def __init__(
113113
async def trigger_callback(self, update: Optional[Delta] = None) -> None:
114114
try:
115115
await self._update_callback(self._connection.peer_node_id, update)
116-
except Exception as e:
117-
log.error(f"_update_callback: node_id {self.connection().peer_node_id}, raised {e}")
116+
except Exception:
117+
log.exception(f"_update_callback: node_id {self.connection().peer_node_id}")
118118

119119
def reset(self) -> None:
120120
log.info(f"reset: node_id {self.connection().peer_node_id}, current_sync: {self._current_sync}")
@@ -181,13 +181,13 @@ async def send_response(plot_sync_error: Optional[PlotSyncError] = None) -> None
181181
await method(message)
182182
await send_response()
183183
except InvalidIdentifierError as e:
184-
log.warning(f"_process: node_id {self.connection().peer_node_id}, InvalidIdentifierError {e}")
184+
log.exception(f"_process: node_id {self.connection().peer_node_id}")
185185
await send_response(PlotSyncError(int16(e.error_code), f"{e}", e.expected_identifier))
186186
except PlotSyncException as e:
187-
log.warning(f"_process: node_id {self.connection().peer_node_id}, Error {e}")
187+
log.exception(f"_process: node_id {self.connection().peer_node_id}")
188188
await send_response(PlotSyncError(int16(e.error_code), f"{e}", None))
189189
except Exception as e:
190-
log.warning(f"_process: node_id {self.connection().peer_node_id}, Exception {e}")
190+
log.exception(f"_process: node_id {self.connection().peer_node_id}")
191191
await send_response(PlotSyncError(int16(ErrorCodes.unknown), f"{e}", None))
192192

193193
def _validate_identifier(self, identifier: PlotSyncIdentifier, start: bool = False) -> None:

chia/plotting/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ def _refresh_task(self, sleep_interval_ms: int):
278278
f"total_result.removed {len(total_result.removed)}, "
279279
f"total_duration {total_result.duration:.2f} seconds"
280280
)
281-
except Exception as e:
282-
log.error(f"_refresh_callback raised: {e} with the traceback: {traceback.format_exc()}")
281+
except Exception:
282+
log.exception("_refresh_callback raised")
283283
self.reset()
284284

285285
def refresh_batch(self, plot_paths: list[Path], plot_directories: set[Path]) -> PlotRefreshResult:

chia/simulator/block_tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,8 @@ def get_pospaces_for_challenge(
15531553
f"cannot be used for farming: {plot_info.prover.get_filename()}"
15541554
)
15551555
continue
1556+
elif prev_transaction_b_height >= constants.HARD_FORK2_HEIGHT + constants.PLOT_V1_PHASE_OUT:
1557+
continue
15561558

15571559
new_challenge: bytes32 = calculate_pos_challenge(plot_id, challenge_hash, signage_point)
15581560

chia/types/blockchain_format/proof_of_space.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Optional, cast
55

66
from bitstring import BitArray
7-
from chia_rs import AugSchemeMPL, ConsensusConstants, G1Element, PlotSize, PrivateKey, ProofOfSpace
7+
from chia_rs import AugSchemeMPL, ConsensusConstants, G1Element, PlotSize, PrivateKey, ProofOfSpace, validate_proof_v2
88
from chia_rs.sized_bytes import bytes32
99
from chia_rs.sized_ints import uint8, uint32
1010
from chiapos import Verifier
@@ -13,22 +13,6 @@
1313

1414
log = logging.getLogger(__name__)
1515

16-
# These are temporary stubs for chiapos2, that we build against until it's ready to be integrated.
17-
18-
19-
# returns quality string for v2 plot, or None if invalid
20-
def validate_proof_v2(
21-
plot_id: bytes32, size: uint8, required_plot_strength: uint8, challenge: bytes32, proof: bytes
22-
) -> Optional[bytes32]:
23-
# TODO: todo_v2_plots call into new chiapos library
24-
raise NotImplementedError
25-
26-
27-
# given a partial proof, computes the quality. This is used to compute required iters.
28-
def quality_for_partial_proof(partial_proof: bytes, challenge: bytes32) -> bytes32:
29-
# TODO: todo_v2_plots call into new chiapos library
30-
return std_hash(partial_proof + challenge)
31-
3216

3317
def make_pos(
3418
challenge: bytes32,
@@ -115,7 +99,7 @@ def verify_and_get_quality_string(
11599
new_challenge: bytes32 = calculate_pos_challenge(plot_id, original_challenge_hash, signage_point)
116100

117101
if new_challenge != pos.challenge:
118-
log.error("Calculated pos challenge doesn't match the provided one")
102+
log.error(f"Calculated pos challenge doesn't match the provided one {new_challenge}")
119103
return None
120104

121105
# we use different plot filter prefix sizes depending on v1 or v2 plots
@@ -137,7 +121,12 @@ def verify_and_get_quality_string(
137121
assert plot_size.size_v2 is not None
138122

139123
return validate_proof_v2(
140-
plot_id, plot_size.size_v2, constants.PLOT_STRENGTH_INITIAL, pos.challenge, bytes(pos.proof)
124+
plot_id,
125+
plot_size.size_v2,
126+
pos.challenge,
127+
constants.PLOT_STRENGTH_INITIAL,
128+
constants.QUALITY_PROOF_SCAN_FILTER,
129+
pos.proof,
141130
)
142131

143132

0 commit comments

Comments
 (0)