Skip to content

Commit d5d886b

Browse files
authored
[CHIA-3923] Chia rs new pos (#20567)
* update chia_rs dependency with the new ProofOfSpace type. use k-22 for v2 plots in simulator * use new test cache * review comments * update test plots and chains to use k-20 for v2 plots, and only alternate between strength 2 and 3 (not 4)
1 parent 73dbe1e commit d5d886b

34 files changed

+396
-222
lines changed

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
python-version: ["3.12"]
6060
env:
6161
CHIA_ROOT: ${{ github.workspace }}/.chia/mainnet
62-
BLOCKS_AND_PLOTS_VERSION: 0.45.3
62+
BLOCKS_AND_PLOTS_VERSION: 0.45.6
6363

6464
steps:
6565
- name: Clean workspace

.github/workflows/test-single.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
CHIA_ROOT: ${{ github.workspace }}/.chia/mainnet
131131
CHIA_SIMULATOR_ROOT: ${{ github.workspace }}/.chia/simulator
132132
JOB_FILE_NAME: tests_${{ matrix.os.file_name }}_python-${{ matrix.python.file_name }}_${{ matrix.configuration.module_import_path }}${{ matrix.configuration.file_name_index }}
133-
BLOCKS_AND_PLOTS_VERSION: 0.45.3
133+
BLOCKS_AND_PLOTS_VERSION: 0.45.6
134134

135135
steps:
136136
- name: Checkout code

benchmarks/block_store.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
TransactionsInfo,
2121
)
2222
from chia_rs.sized_bytes import bytes32
23-
from chia_rs.sized_ints import uint8, uint32, uint64, uint128
23+
from chia_rs.sized_ints import uint8, uint16, uint32, uint64, uint128
2424

2525
from benchmarks.utils import setup_db
2626
from chia._tests.util.benchmarks import (
@@ -109,7 +109,11 @@ async def run_add_block_benchmark(version: int) -> None:
109109
rand_g1() if has_pool_pk else None,
110110
rand_hash() if not has_pool_pk else None,
111111
rand_g1(), # plot_public_key
112-
uint8(32),
112+
uint8(0), # v1
113+
uint16(0), # plot_index
114+
uint8(0), # group_id
115+
uint8(0), # strength
116+
uint8(32), # size
113117
random.randbytes(8 * 32),
114118
)
115119

chia/_tests/blockchain/test_blockchain.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,10 @@ async def test_bad_pos(self, empty_blockchain: Blockchain, bt: BlockTools) -> No
12171217
)
12181218
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.INVALID_POSPACE)
12191219

1220-
block_bad = recursive_replace(blocks[-1], "reward_chain_block.proof_of_space.version_and_size", 62)
1220+
if blocks[-1].reward_chain_block.proof_of_space.version == 0:
1221+
block_bad = recursive_replace(blocks[-1], "reward_chain_block.proof_of_space.size", 62)
1222+
else:
1223+
block_bad = recursive_replace(blocks[-1], "reward_chain_block.proof_of_space.strength", 1)
12211224
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.INVALID_POSPACE)
12221225

12231226
block_bad = recursive_replace(
@@ -1226,16 +1229,24 @@ async def test_bad_pos(self, empty_blockchain: Blockchain, bt: BlockTools) -> No
12261229
AugSchemeMPL.key_gen(std_hash(b"1231n")).get_g1(),
12271230
)
12281231
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.INVALID_POSPACE)
1229-
block_bad = recursive_replace(
1230-
blocks[-1],
1231-
"reward_chain_block.proof_of_space.version_and_size",
1232-
32,
1233-
)
1232+
1233+
if blocks[-1].reward_chain_block.proof_of_space.version == 0:
1234+
block_bad = recursive_replace(
1235+
blocks[-1],
1236+
"reward_chain_block.proof_of_space.size",
1237+
32,
1238+
)
1239+
else:
1240+
block_bad = recursive_replace(
1241+
blocks[-1],
1242+
"reward_chain_block.proof_of_space.strength",
1243+
67,
1244+
)
12341245
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.INVALID_POSPACE)
12351246
block_bad = recursive_replace(
12361247
blocks[-1],
12371248
"reward_chain_block.proof_of_space.proof",
1238-
bytes([1] * int((blocks[-1].reward_chain_block.proof_of_space.version_and_size & 0x7F) * 64 / 8)),
1249+
bytes([1] * len(blocks[-1].reward_chain_block.proof_of_space.proof)),
12391250
)
12401251
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.INVALID_POSPACE)
12411252

@@ -1451,6 +1462,12 @@ async def test_pool_target_pre_farm(self, empty_blockchain: Blockchain, bt: Bloc
14511462
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.INVALID_PREFARM)
14521463

14531464
@pytest.mark.anyio
1465+
# TODO: todo_v2_plots fix this test and remove limit_consensus_modes
1466+
@pytest.mark.limit_consensus_modes(
1467+
allowed=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0, ConsensusMode.HARD_FORK_3_0],
1468+
reason="It seams ConsensusMode.HARD_FORK_3_0_AFTER_PHASE_OUT fails to "
1469+
"find any proofs with pool keys in a timely manner",
1470+
)
14541471
async def test_pool_target_signature(self, empty_blockchain: Blockchain, bt: BlockTools) -> None:
14551472
# 20b
14561473
blocks_initial = bt.get_consecutive_blocks(2)
@@ -3416,6 +3433,8 @@ async def test_long_reorg(
34163433
) -> None:
34173434
if light_blocks:
34183435
reorg_blocks = test_long_reorg_blocks_light[:1650]
3436+
elif consensus_mode >= ConsensusMode.HARD_FORK_3_0:
3437+
reorg_blocks = test_long_reorg_blocks[:1350]
34193438
else:
34203439
reorg_blocks = test_long_reorg_blocks[:1200]
34213440

@@ -4360,7 +4379,7 @@ async def test_get_header_blocks_in_range_tx_filter_non_tx_block(empty_blockchai
43604379
transactions filter, on a non transaction block.
43614380
"""
43624381
b = empty_blockchain
4363-
blocks = bt.get_consecutive_blocks(2)
4382+
blocks = bt.get_consecutive_blocks(10)
43644383
for block in blocks:
43654384
await _validate_and_add_block(b, block)
43664385
non_tx_block = next(block for block in blocks if not block.is_transaction_block())

chia/_tests/core/consensus/test_pot_iterations.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ def test_win_percentage(self):
9393
PlotParam.make_v1(34): 100,
9494
PlotParam.make_v1(35): 100,
9595
PlotParam.make_v1(36): 100,
96-
PlotParam.make_v2(2): 200,
97-
PlotParam.make_v2(3): 200,
98-
PlotParam.make_v2(4): 200,
96+
PlotParam.make_v2(0, 0, 2): 200,
97+
PlotParam.make_v2(0, 0, 3): 200,
98+
PlotParam.make_v2(0, 0, 4): 200,
9999
}
100100
farmer_space = {k: _expected_plot_size(k, test_constants) * count for k, count in farmer_ks.items()}
101101
wins = {k: 0 for k in farmer_ks.keys()}
@@ -141,5 +141,7 @@ def test_expected_plot_size_v1() -> None:
141141

142142
def test_expected_plot_size_v2() -> None:
143143
for strength in [2, 3, 4, 5, 6, 7]:
144-
plot_size = _expected_plot_size(PlotParam.make_v2(strength), test_constants)
145-
assert plot_size == 988_513_566
144+
for plot_index in [2, 300, 400, 500, 600, 700]:
145+
for group_id in [2, 3, 4, 5, 6, 7]:
146+
plot_size = _expected_plot_size(PlotParam.make_v2(plot_index, group_id, strength), test_constants)
147+
assert plot_size == 988_513_566

chia/_tests/core/custom_types/test_proof_of_space.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def b32(key: str) -> bytes32:
4343
return bytes32.from_hexstr(key)
4444

4545

46-
# TODO: todo_v2_plots more test cases
46+
# TODO: todo_v2_plots more test cases, cover plot_index and group_id
4747
@datacases(
4848
ProofOfSpaceCase(
4949
id="Neither pool public key nor pool contract puzzle hash",
@@ -113,23 +113,23 @@ def b32(key: str) -> bytes32:
113113
ProofOfSpaceCase(
114114
id="v2 plot strength 0",
115115
pos_challenge=bytes32(b"1" * 32),
116-
plot_size=PlotParam.make_v2(0),
116+
plot_size=PlotParam.make_v2(0, 0, 0),
117117
pool_contract_puzzle_hash=bytes32(b"1" * 32),
118118
plot_public_key=G1Element(),
119119
expected_error="Plot strength (0) is lower than the minimum (2)",
120120
),
121121
ProofOfSpaceCase(
122122
id="v2 plot strength 33",
123123
pos_challenge=bytes32(b"1" * 32),
124-
plot_size=PlotParam.make_v2(33),
124+
plot_size=PlotParam.make_v2(0, 0, 33),
125125
pool_contract_puzzle_hash=bytes32(b"1" * 32),
126126
plot_public_key=G1Element(),
127127
expected_error="Plot strength (33) is too high (max is 32)",
128128
),
129129
ProofOfSpaceCase(
130130
id="Not passing the plot filter v2",
131-
pos_challenge=b32("0cbb408989205e9a94cc012f0d2717e9336795b0853f972965ad0c75c5700ed9"),
132-
plot_size=PlotParam.make_v2(32),
131+
pos_challenge=b32("5862b9d5210b008c0c30e2673e327b4a6c98c34d93dd05c7a253320eb5db1712"),
132+
plot_size=PlotParam.make_v2(0, 0, 32),
133133
pool_contract_puzzle_hash=bytes32(b"1" * 32),
134134
plot_public_key=g1(
135135
"879526b4e7b616cfd64984d8ad140d0798b048392a6f11e2faf09054ef467ea44dc0dab5e5edb2afdfa850c5c8b629cc"
@@ -139,7 +139,7 @@ def b32(key: str) -> bytes32:
139139
ProofOfSpaceCase(
140140
id="v2 not activated",
141141
pos_challenge=bytes32(b"1" * 32),
142-
plot_size=PlotParam.make_v2(2),
142+
plot_size=PlotParam.make_v2(0, 0, 2),
143143
pool_contract_puzzle_hash=bytes32(b"1" * 32),
144144
plot_public_key=G1Element(),
145145
height=uint32(DEFAULT_CONSTANTS.HARD_FORK2_HEIGHT - 1),
@@ -153,13 +153,13 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
153153
pool_public_key=case.pool_public_key,
154154
pool_contract_puzzle_hash=case.pool_contract_puzzle_hash,
155155
plot_public_key=case.plot_public_key,
156-
version_and_size=case.plot_size,
156+
params=case.plot_size,
157157
proof=b"1",
158158
)
159159
quality_string = verify_and_get_quality_string(
160160
pos=pos,
161161
constants=DEFAULT_CONSTANTS,
162-
original_challenge_hash=b32("0x73490e166d0b88347c37d921660b216c27316aae9a3450933d3ff3b854e5831a"),
162+
original_challenge_hash=b32("73490e166d0b88347c37d921660b216c27316aae9a3450933d3ff3b854e5831a"),
163163
signage_point=b32("0x7b3e23dbd438f9aceefa9827e2c5538898189987f49b06eceb7a43067e77b531"),
164164
height=case.height,
165165
prev_transaction_block_height=case.height,
@@ -171,8 +171,8 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
171171
@datacases(
172172
ProofOfSpaceCase(
173173
id="not passing the plot filter v2",
174-
plot_size=PlotParam.make_v2(2),
175-
pos_challenge=b32("389f3f2f67d37a63d81a21d0e96898ff4eaa7007e1507630bea6a2608795a418"),
174+
plot_size=PlotParam.make_v2(0, 0, 2),
175+
pos_challenge=b32("9483df4e178307ae677d86664daaef4fc52689b2b6cd7825351f2a2ad7075adb"),
176176
plot_public_key=g1(
177177
"afa3aaf09c03885154be49216ee7fb2e4581b9c4a4d7e9cc402e27280bf0cfdbdf1b9ba674e301fd1d1450234b3b1868"
178178
),
@@ -187,7 +187,7 @@ def test_verify_and_get_quality_string_v2(caplog: pytest.LogCaptureFixture, case
187187
pool_public_key=case.pool_public_key,
188188
pool_contract_puzzle_hash=case.pool_contract_puzzle_hash,
189189
plot_public_key=case.plot_public_key,
190-
version_and_size=case.plot_size,
190+
params=case.plot_size,
191191
proof=b"1",
192192
)
193193
plot_param = pos.param()
@@ -197,7 +197,7 @@ def test_verify_and_get_quality_string_v2(caplog: pytest.LogCaptureFixture, case
197197
quality_string = verify_and_get_quality_string(
198198
pos=pos,
199199
constants=DEFAULT_CONSTANTS,
200-
original_challenge_hash=b32("0x73490e166d0b88347c37d921660b216c27316aae9a3450933d3ff3b854e5831a"),
200+
original_challenge_hash=b32("73490e166d0b88347c37d921660b216c27316aae9a3450933d3ff3b854e5831a"),
201201
signage_point=b32("0xf7c1bd874da5e709d4713d60c8a70639eb1167b367a9c3787c65c1e582e2e662"),
202202
height=case.height,
203203
prev_transaction_block_height=case.height,
@@ -223,11 +223,11 @@ def test_verify_and_get_quality_string_v2(caplog: pytest.LogCaptureFixture, case
223223
(PlotParam.make_v1(49), True),
224224
(PlotParam.make_v1(50), True),
225225
(PlotParam.make_v1(51), False), # too large
226-
(PlotParam.make_v2(1), False), # too small
227-
(PlotParam.make_v2(2), True),
228-
(PlotParam.make_v2(3), True),
229-
(PlotParam.make_v2(32), True),
230-
(PlotParam.make_v2(33), False), # strength too high
226+
(PlotParam.make_v2(0, 0, 1), False), # too small
227+
(PlotParam.make_v2(0, 0, 2), True),
228+
(PlotParam.make_v2(0, 0, 3), True),
229+
(PlotParam.make_v2(0, 0, 32), True),
230+
(PlotParam.make_v2(0, 0, 33), False), # strength too high
231231
],
232232
)
233233
def test_check_plot_param(plot_param: PlotParam, valid: bool) -> None:
@@ -290,7 +290,7 @@ def test_calculate_prefix_bits_v1(height: uint32, expected: int) -> None:
290290
],
291291
)
292292
def test_calculate_prefix_bits_v2(height: uint32, expected: int) -> None:
293-
assert calculate_prefix_bits(DEFAULT_CONSTANTS, height, PlotParam.make_v2(28)) == expected
293+
assert calculate_prefix_bits(DEFAULT_CONSTANTS, height, PlotParam.make_v2(0, 0, 28)) == expected
294294

295295

296296
def test_v1_phase_out() -> None:

chia/_tests/core/full_node/test_full_node.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,11 @@ async def test_unfinished_block_with_replaced_generator(
16411641
pos.pool_public_key,
16421642
pos.pool_contract_puzzle_hash,
16431643
public_key,
1644-
pos.version_and_size,
1644+
pos.version,
1645+
pos.plot_index,
1646+
pos.meta_group,
1647+
pos.strength,
1648+
pos.size,
16451649
pos.proof,
16461650
)
16471651

@@ -2153,13 +2157,14 @@ async def test_compact_protocol_invalid_messages(
21532157
wrong_challenge = block.reward_chain_block.challenge_chain_sp_vdf.challenge
21542158
wrong_iters = block.reward_chain_block.challenge_chain_sp_vdf.number_of_iterations
21552159

2156-
wrong_vdf_info, wrong_vdf_proof = get_vdf_info_and_proof(
2160+
wrong_vdf_info, _ = get_vdf_info_and_proof(
21572161
bt.constants,
21582162
ClassgroupElement.get_default_element(),
21592163
wrong_challenge,
21602164
wrong_iters,
21612165
True,
21622166
)
2167+
wrong_vdf_proof = VDFProof(uint8(0), b"1239819023890", True)
21632168
timelord_protocol_invalid_messages: list[timelord_protocol.RespondCompactProofOfTime] = []
21642169
full_node_protocol_invalid_messages: list[fnp.RespondCompactVDF] = []
21652170
for block in blocks_2[:2]:
@@ -2171,7 +2176,6 @@ async def test_compact_protocol_invalid_messages(
21712176
sub_slot.challenge_chain.challenge_chain_end_of_slot_vdf.number_of_iterations,
21722177
True,
21732178
)
2174-
assert wrong_vdf_proof != correct_vdf_proof
21752179
timelord_protocol_invalid_messages.append(
21762180
timelord_protocol.RespondCompactProofOfTime(
21772181
vdf_info,
@@ -2198,7 +2202,6 @@ async def test_compact_protocol_invalid_messages(
21982202
sub_slot.infused_challenge_chain.infused_challenge_chain_end_of_slot_vdf.number_of_iterations,
21992203
True,
22002204
)
2201-
assert wrong_vdf_proof != correct_vdf_proof
22022205
timelord_protocol_invalid_messages.append(
22032206
timelord_protocol.RespondCompactProofOfTime(
22042207
vdf_info,
@@ -2226,14 +2229,10 @@ async def test_compact_protocol_invalid_messages(
22262229
block.reward_chain_block.challenge_chain_sp_vdf.number_of_iterations,
22272230
True,
22282231
)
2229-
sp_vdf_proof = wrong_vdf_proof
2230-
if wrong_vdf_proof == correct_vdf_proof:
2231-
# This can actually happen...
2232-
sp_vdf_proof = VDFProof(uint8(0), b"1239819023890", True)
22332232
timelord_protocol_invalid_messages.append(
22342233
timelord_protocol.RespondCompactProofOfTime(
22352234
vdf_info,
2236-
sp_vdf_proof,
2235+
wrong_vdf_proof,
22372236
block.header_hash,
22382237
block.height,
22392238
uint8(CompressibleVDFField.CC_SP_VDF),
@@ -2245,7 +2244,7 @@ async def test_compact_protocol_invalid_messages(
22452244
block.header_hash,
22462245
uint8(CompressibleVDFField.CC_SP_VDF),
22472246
vdf_info,
2248-
sp_vdf_proof,
2247+
wrong_vdf_proof,
22492248
)
22502249
)
22512250

chia/_tests/core/full_node/test_generator_tools.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from __future__ import annotations
22

33
import pytest
4-
from chia_rs import Program as SerializedProgram
54
from chia_rs import (
5+
CoinSpend,
66
SpendBundleConditions,
77
SpendConditions,
88
get_spends_for_trusted_block,
99
get_spends_for_trusted_block_with_conditions,
1010
)
11+
from chia_rs import Program as SerializedProgram
12+
from chia_rs.sized_bytes import bytes32
1113
from chia_rs.sized_ints import uint32, uint64
1214

1315
from chia.consensus.generator_tools import tx_removals_and_additions
@@ -110,11 +112,31 @@ def test_get_spends_for_block(caplog: pytest.LogCaptureFixture) -> None:
110112
conditions = get_spends_for_trusted_block(
111113
test_constants, TEST_GENERATOR.program, TEST_GENERATOR.generator_refs, 100
112114
)
113-
assert conditions["block_spends"] == []
115+
assert conditions["block_spends"] == [
116+
CoinSpend(
117+
Coin(
118+
bytes32.fromhex("0101010101010101010101010101010101010101010101010101010101010101"),
119+
bytes32.fromhex("6c04a09251046f8dd47efe681af7e47f6e61e68fb2f9ad47c5031ec3e36c5564"),
120+
uint64(123),
121+
),
122+
SerializedProgram.fromhex("80"),
123+
SerializedProgram.fromhex("ff80ffff018080"),
124+
)
125+
]
114126

115127

116128
def test_get_spends_for_block_with_conditions(caplog: pytest.LogCaptureFixture) -> None:
117129
conditions = get_spends_for_trusted_block_with_conditions(
118130
test_constants, TEST_GENERATOR.program, TEST_GENERATOR.generator_refs, 100
119131
)
120-
assert conditions == []
132+
assert len(conditions) == 1
133+
assert conditions[0]["coin_spend"] == CoinSpend(
134+
Coin(
135+
bytes32.fromhex("0101010101010101010101010101010101010101010101010101010101010101"),
136+
bytes32.fromhex("6c04a09251046f8dd47efe681af7e47f6e61e68fb2f9ad47c5031ec3e36c5564"),
137+
uint64(123),
138+
),
139+
SerializedProgram.fromhex("80"),
140+
SerializedProgram.fromhex("ff80ffff018080"),
141+
)
142+
assert len(conditions[0]["conditions"]) == 1024

chia/_tests/core/mempool/test_mempool_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,15 +2764,15 @@ def transactions_1000_fixture(test_wallet: WalletTool, seeded_random: random.Ran
27642764
# if we try to fill the mempool with more than 550, all spends won't
27652765
# necessarily fit in the block, which the test assumes
27662766
@pytest.mark.anyio
2767-
@pytest.mark.parametrize("mempool_size", [1, 2, 100, 300, 400, 550, 730])
2767+
@pytest.mark.parametrize("mempool_size", [1, 2, 100, 300, 400, 550, 630])
27682768
@pytest.mark.parametrize("seed", [0, 1, 2, 3, 4])
27692769
@pytest.mark.parametrize("old", [True, False])
27702770
async def test_create_block_generator(
27712771
mempool_size: int, seed: int, old: bool, transactions_1000: list[SpendBundle]
27722772
) -> None:
27732773
# the old way of creating bloks doesn't fit this many transactions, so we
27742774
# expect it to fail
2775-
expect_failure = mempool_size == 730 and old
2775+
expect_failure = mempool_size == 630 and old
27762776

27772777
bundles = transactions_1000
27782778
all_coins = [s.coin for b in bundles for s in b.coin_spends]

0 commit comments

Comments
 (0)