|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import pytest |
4 | 3 | from chia_rs import PlotSize |
5 | 4 | from chia_rs.sized_ints import uint8, uint16, uint32, uint64, uint128 |
6 | 5 | from pytest import raises |
|
10 | 9 | from chia.consensus.pot_iterations import ( |
11 | 10 | calculate_ip_iters, |
12 | 11 | calculate_iterations_quality, |
13 | | - calculate_phase_out, |
14 | 12 | calculate_sp_interval_iters, |
15 | 13 | calculate_sp_iters, |
16 | 14 | is_overflow_block, |
@@ -84,17 +82,7 @@ def test_calculate_ip_iters(self): |
84 | 82 | assert ip_iters == (sp_iters + test_constants.NUM_SP_INTERVALS_EXTRA * sp_interval_iters + required_iters) % ssi |
85 | 83 | assert sp_iters > ip_iters |
86 | 84 |
|
87 | | - @pytest.mark.parametrize( |
88 | | - "height", |
89 | | - [ |
90 | | - uint32(0), |
91 | | - test_constants.HARD_FORK2_HEIGHT - 1, |
92 | | - test_constants.HARD_FORK2_HEIGHT, |
93 | | - test_constants.HARD_FORK2_HEIGHT + test_constants.PLOT_V1_PHASE_OUT, |
94 | | - test_constants.HARD_FORK2_HEIGHT + test_constants.PLOT_V1_PHASE_OUT + 1, |
95 | | - ], |
96 | | - ) |
97 | | - def test_win_percentage(self, height: uint32): |
| 85 | + def test_win_percentage(self): |
98 | 86 | """ |
99 | 87 | Tests that the percentage of blocks won is proportional to the space of each farmer, |
100 | 88 | with the assumption that all farmers have access to the same VDF speed. |
@@ -129,59 +117,19 @@ def test_win_percentage(self, height: uint32): |
129 | 117 | quality = std_hash( |
130 | 118 | slot_index.to_bytes(4, "big") + plot_k_val.to_bytes(1, "big") + bytes(farmer_index) |
131 | 119 | ) |
132 | | - required_iters = calculate_iterations_quality( |
133 | | - constants, quality, k, difficulty, sp_hash, sub_slot_iters, height |
134 | | - ) |
| 120 | + required_iters = calculate_iterations_quality(constants, quality, k, difficulty, sp_hash) |
135 | 121 | if required_iters < sp_interval_iters: |
136 | 122 | wins[k] += 1 |
137 | 123 | total_wins_in_slot += 1 |
138 | 124 |
|
139 | | - if height < test_constants.HARD_FORK2_HEIGHT + test_constants.PLOT_V1_PHASE_OUT: |
140 | | - total_space = sum(farmer_space.values()) |
141 | | - percentage_space = {k: float(sp / total_space) for k, sp in farmer_space.items()} |
142 | | - else: |
143 | | - # after the phase-out, v1 plots don't count |
144 | | - # all wins are by v2 plots |
145 | | - total_space = sum(0 if k.size_v2 is None else sp for k, sp in farmer_space.items()) |
146 | | - percentage_space = { |
147 | | - k: 0.0 if k.size_v2 is None else float(sp / total_space) for k, sp in farmer_space.items() |
148 | | - } |
| 125 | + total_space = sum(farmer_space.values()) |
| 126 | + percentage_space = {k: float(sp / total_space) for k, sp in farmer_space.items()} |
149 | 127 |
|
150 | 128 | win_percentage = {k: wins[k] / sum(wins.values()) for k in farmer_ks.keys()} |
151 | 129 | for k in farmer_ks.keys(): |
152 | 130 | # Win rate is proportional to percentage of space |
153 | 131 | assert abs(win_percentage[k] - percentage_space[k]) < 0.01 |
154 | 132 |
|
155 | | - @pytest.mark.parametrize("sp_interval", [uint64(6250000000), uint64(1), uint64(2), uint64(10), uint64(10000000000)]) |
156 | | - def test_calculate_phase_out(self, sp_interval: uint64): |
157 | | - constants = test_constants |
158 | | - sub_slot_iters = uint64(sp_interval * constants.NUM_SPS_SUB_SLOT) |
159 | | - # Before or at HARD_FORK2_HEIGHT, should return 0 |
160 | | - assert calculate_phase_out(constants, sub_slot_iters, uint32(constants.HARD_FORK2_HEIGHT - 1)) == 0 |
161 | | - assert calculate_phase_out(constants, sub_slot_iters, constants.HARD_FORK2_HEIGHT) == 0 |
162 | | - # after HARD_FORK2_HEIGHT, should return value = delta/phase_out_period * sp_interval |
163 | | - assert ( |
164 | | - calculate_phase_out(constants, sub_slot_iters, uint32(constants.HARD_FORK2_HEIGHT + 1)) |
165 | | - == sp_interval // constants.PLOT_V1_PHASE_OUT |
166 | | - ) |
167 | | - assert ( |
168 | | - calculate_phase_out( |
169 | | - constants, sub_slot_iters, uint32(constants.HARD_FORK2_HEIGHT + constants.PLOT_V1_PHASE_OUT // 2) |
170 | | - ) |
171 | | - == sp_interval // 2 |
172 | | - ) |
173 | | - assert ( |
174 | | - calculate_phase_out( |
175 | | - constants, sub_slot_iters, uint32(constants.HARD_FORK2_HEIGHT + constants.PLOT_V1_PHASE_OUT) |
176 | | - ) |
177 | | - == sp_interval |
178 | | - ) |
179 | | - |
180 | | - # Test with maximum uint32 height to ensure no overflow |
181 | | - max_uint32_height = uint32(0xFFFFFFFF) |
182 | | - result_max_height = calculate_phase_out(constants, sub_slot_iters, max_uint32_height) |
183 | | - assert result_max_height == sp_interval # Should cap at sp_interval |
184 | | - |
185 | 133 |
|
186 | 134 | def test_expected_plot_size_v1() -> None: |
187 | 135 | last_size = 2_400_000 |
|
0 commit comments