Skip to content

Commit 1d63e6b

Browse files
committed
bump chia_rs, cleanup
1 parent 813d715 commit 1d63e6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+299
-425
lines changed

benchmarks/block_ref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def main(db_path: Path) -> None:
6262
db_wrapper = DBWrapper2(connection, db_version=db_version)
6363
await db_wrapper.add_connection(await aiosqlite.connect(db_path))
6464

65-
block_store = await BlockStore.create(db_wrapper, DEFAULT_CONSTANTS)
65+
block_store = await BlockStore.create(db_wrapper)
6666
coin_store = await CoinStore.create(db_wrapper)
6767

6868
start_time = monotonic()

benchmarks/block_store.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
rand_vdf_proof,
3434
rewards,
3535
)
36-
from chia.consensus.default_constants import DEFAULT_CONSTANTS
3736
from chia.full_node.block_store import BlockStore
3837
from chia.types.blockchain_format.serialized_program import SerializedProgram
3938

@@ -58,7 +57,7 @@ async def run_add_block_benchmark(version: int) -> None:
5857
header_hashes = []
5958

6059
async with setup_db("block-store-benchmark.db", version) as db_wrapper:
61-
block_store = await BlockStore.create(db_wrapper, DEFAULT_CONSTANTS)
60+
block_store = await BlockStore.create(db_wrapper)
6261

6362
block_height = 1
6463
timestamp = uint64(1631794488)
@@ -100,7 +99,7 @@ async def run_add_block_benchmark(version: int) -> None:
10099
uint8(random.randint(0, 255)), # num_blocks_overflow: uint8
101100
None, # new_difficulty: Optional[uint64]
102101
None, # new_sub_slot_iters: Optional[uint64]
103-
bytes32.zeros, # challenge_merkle_root: bytes32
102+
None, # challenge_merkle_root: Optional[bytes32]
104103
)
105104

106105
has_pool_pk = random.randint(0, 1)
@@ -128,7 +127,7 @@ async def run_add_block_benchmark(version: int) -> None:
128127
rand_g2(), # reward_chain_sp_signature
129128
rand_vdf(), # reward_chain_ip_vdf
130129
rand_vdf() if deficit < 16 else None,
131-
None, # header_mmr_root - dummy for benchmark
130+
None, # header_mmr_root
132131
is_transaction,
133132
)
134133

chia/_tests/blockchain/test_block_commitments.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
import pytest
66
from chia_rs import FullBlock
77
from chia_rs.sized_bytes import bytes32
8-
from chia_rs.sized_ints import uint32
8+
from chia_rs.sized_ints import uint8, uint32
99

1010
from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block, _validate_and_add_block_no_error
1111
from chia._tests.conftest import ConsensusMode
1212
from chia._tests.core.node_height import node_height_exactly
13-
from chia._tests.simulation.test_simulation import test_constants
1413
from chia._tests.util.blockchain import create_blockchain
1514
from chia._tests.util.setup_nodes import setup_two_nodes
1615
from chia._tests.util.time_out_assert import time_out_assert
1716
from chia.consensus.get_block_challenge import pre_sp_tx_block_height
1817
from chia.protocols import full_node_protocol
18+
from chia.simulator.block_tools import test_constants
1919
from chia.types.peer_info import PeerInfo
2020
from chia.util.errors import Err
2121

@@ -34,10 +34,8 @@ async def test_add_fork_height_zero_blocks(
3434
blocks = fork_height2_0_1000_blocks
3535
constants = test_constants.replace(
3636
HARD_FORK2_HEIGHT=uint32(0),
37-
HARD_FORK_HEIGHT=uint32(2),
38-
PLOT_FILTER_128_HEIGHT=uint32(10),
39-
PLOT_FILTER_64_HEIGHT=uint32(15),
40-
PLOT_FILTER_32_HEIGHT=uint32(20),
37+
HARD_FORK_HEIGHT=uint32(0),
38+
PLOT_V1_PHASE_OUT_EPOCH_BITS=uint8(8),
4139
)
4240
passed_sp_or_slot = False
4341
async with create_blockchain(constants, 2) as (blockchain, _):
@@ -87,10 +85,8 @@ async def test_verify_fork_transition_point(
8785
blocks = fork_height2_500_1000_blocks
8886
constants = test_constants.replace(
8987
HARD_FORK2_HEIGHT=uint32(500),
90-
HARD_FORK_HEIGHT=uint32(2),
91-
PLOT_FILTER_128_HEIGHT=uint32(10),
92-
PLOT_FILTER_64_HEIGHT=uint32(15),
93-
PLOT_FILTER_32_HEIGHT=uint32(20),
88+
HARD_FORK_HEIGHT=uint32(0),
89+
PLOT_V1_PHASE_OUT_EPOCH_BITS=uint8(8),
9490
)
9591

9692
passed_fork = False
@@ -158,6 +154,8 @@ async def test_sync_fork_height_zero_blocks(
158154
blocks = fork_height2_0_1000_blocks
159155
constants = test_constants.replace(
160156
HARD_FORK2_HEIGHT=uint32(0),
157+
HARD_FORK_HEIGHT=uint32(0),
158+
PLOT_V1_PHASE_OUT_EPOCH_BITS=uint8(8),
161159
)
162160

163161
async with setup_two_nodes(constants, db_version, self_hostname) as (
@@ -206,10 +204,8 @@ async def test_sync_fork_height_500_blocks(
206204
blocks = fork_height2_500_1000_blocks
207205
constants = test_constants.replace(
208206
HARD_FORK2_HEIGHT=uint32(500),
209-
HARD_FORK_HEIGHT=uint32(2),
210-
PLOT_FILTER_128_HEIGHT=uint32(10),
211-
PLOT_FILTER_64_HEIGHT=uint32(15),
212-
PLOT_FILTER_32_HEIGHT=uint32(20),
207+
HARD_FORK_HEIGHT=uint32(0),
208+
PLOT_V1_PHASE_OUT_EPOCH_BITS=uint8(8),
213209
)
214210

215211
async with setup_two_nodes(constants, db_version, self_hostname) as (

chia/_tests/conftest.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,43 +476,36 @@ def default_10000_blocks_compact(bt, consensus_mode):
476476
)
477477

478478

479-
# Fixture for blocks with fork height = 0 (all blocks have new commitments)
480479
@pytest.fixture(scope="session")
481480
async def fork_height2_0_1000_blocks(consensus_mode, get_keychain, anyio_backend, testrun_uid: str):
482481
"""Creates 1000 blocks with HARD_FORK2_HEIGHT=0 so all blocks contain new commitments"""
483482
from chia._tests.util.blockchain import persistent_blocks
484483
from chia.simulator.block_tools import create_block_tools_async
485484

486-
# Create custom constants with HARD_FORK2_HEIGHT=0
487485
constants = test_constants.replace(
488486
HARD_FORK2_HEIGHT=uint32(0),
487+
HARD_FORK_HEIGHT=uint32(0),
488+
PLOT_V1_PHASE_OUT_EPOCH_BITS=uint8(8),
489489
)
490-
491-
# Create custom block tools with these constants
492490
bt_fork_zero = await create_block_tools_async(constants=constants, keychain=get_keychain, testrun_uid=testrun_uid)
493-
494491
version = "_fork_height_zero"
495492
if consensus_mode >= ConsensusMode.HARD_FORK_2_0:
496493
version += "_hardfork"
497-
498494
return persistent_blocks(1000, f"test_blocks_1000{version}.db", bt_fork_zero, seed=b"fork_zero")
499495

500496

501-
# Fixture for blocks with fork height = 500 (transition from old to new commitments)
502497
@pytest.fixture(scope="session")
503498
async def fork_height2_500_1000_blocks(consensus_mode, get_keychain, anyio_backend, testrun_uid: str):
504499
"""Creates 1000 blocks with HARD_FORK2_HEIGHT=500 so fork activates mid-chain"""
505500
from chia._tests.util.blockchain import persistent_blocks
506501
from chia.simulator.block_tools import create_block_tools_async
507502

508-
# Create custom constants with HARD_FORK2_HEIGHT=500
509503
constants = test_constants.replace(
510504
HARD_FORK2_HEIGHT=uint32(500),
505+
HARD_FORK_HEIGHT=uint32(0),
506+
PLOT_V1_PHASE_OUT_EPOCH_BITS=uint8(8),
511507
)
512-
513-
# Create custom block tools with these constants
514508
bt_fork_500 = await create_block_tools_async(constants=constants, keychain=get_keychain, testrun_uid=testrun_uid)
515-
516509
version = "_fork_height_500"
517510
if consensus_mode >= ConsensusMode.HARD_FORK_2_0:
518511
version += "_hardfork"

chia/_tests/core/custom_types/test_sub_epoch_summary.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_sub_epoch_summary_basic() -> None:
1313
num_blocks_overflow=uint8(7),
1414
new_difficulty=uint64(8),
1515
new_sub_slot_iters=uint64(9),
16-
challenge_merkle_root=bytes32.zeros, # placeholder
16+
challenge_merkle_root=None,
1717
)
1818

1919
# Test basic properties
@@ -22,7 +22,7 @@ def test_sub_epoch_summary_basic() -> None:
2222
assert ses.num_blocks_overflow == uint8(7)
2323
assert ses.new_difficulty == uint64(8)
2424
assert ses.new_sub_slot_iters == uint64(9)
25-
assert ses.challenge_merkle_root == bytes32.zeros
25+
assert ses.challenge_merkle_root is None
2626

2727

2828
def test_sub_epoch_summary_with_different_merkle_roots() -> None:
@@ -33,7 +33,7 @@ def test_sub_epoch_summary_with_different_merkle_roots() -> None:
3333
num_blocks_overflow=uint8(7),
3434
new_difficulty=uint64(8),
3535
new_sub_slot_iters=uint64(9),
36-
challenge_merkle_root=bytes32.zeros, # different value
36+
challenge_merkle_root=bytes32([1] * 32), # different value
3737
)
3838

3939
ses2 = SubEpochSummary(
@@ -42,7 +42,7 @@ def test_sub_epoch_summary_with_different_merkle_roots() -> None:
4242
num_blocks_overflow=uint8(7),
4343
new_difficulty=uint64(8),
4444
new_sub_slot_iters=uint64(9),
45-
challenge_merkle_root=bytes32([1] * 32), # different value
45+
challenge_merkle_root=bytes32([2] * 32), # different value
4646
)
4747

4848
# Different merkle roots should create different objects
@@ -57,7 +57,7 @@ def test_sub_epoch_summary_optional_fields() -> None:
5757
num_blocks_overflow=uint8(3),
5858
new_difficulty=None,
5959
new_sub_slot_iters=None,
60-
challenge_merkle_root=bytes32.zeros, # placeholder
60+
challenge_merkle_root=bytes32([2] * 32),
6161
)
6262

6363
assert ses.new_difficulty is None
@@ -70,7 +70,7 @@ def test_sub_epoch_summary_optional_fields() -> None:
7070
num_blocks_overflow=uint8(3),
7171
new_difficulty=uint64(4),
7272
new_sub_slot_iters=None,
73-
challenge_merkle_root=bytes32.zeros, # placeholder
73+
challenge_merkle_root=bytes32([2] * 32),
7474
)
7575

7676
assert ses2.new_difficulty == uint64(4)

chia/_tests/core/full_node/ram_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async def create_ram_blockchain(
2020
) -> AsyncIterator[tuple[DBWrapper2, Blockchain]]:
2121
uri = f"file:db_{random.randint(0, 99999999)}?mode=memory&cache=shared"
2222
async with DBWrapper2.managed(database=uri, uri=True, reader_count=1, db_version=2) as db_wrapper:
23-
block_store = await BlockStore.create(db_wrapper, consensus_constants)
23+
block_store = await BlockStore.create(db_wrapper)
2424
coin_store = await CoinStore.create(db_wrapper)
2525
height_map = await BlockHeightMap.create(Path("."), db_wrapper)
2626
blockchain = await Blockchain.create(coin_store, block_store, height_map, consensus_constants, 2)

chia/_tests/core/full_node/stores/test_block_store.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ async def test_block_store(tmp_dir: Path, db_version: int, bt: BlockTools, use_c
7373
async with DBConnection(db_version) as db_wrapper, DBConnection(db_version) as db_wrapper_2:
7474
# Use a different file for the blockchain
7575
coin_store_2 = await CoinStore.create(db_wrapper_2)
76-
store_2 = await BlockStore.create(db_wrapper_2, bt.constants, use_cache=use_cache)
76+
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
7777
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
7878
bc = await Blockchain.create(coin_store_2, store_2, height_map, bt.constants, 2)
7979

80-
store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
81-
await BlockStore.create(db_wrapper_2, bt.constants)
80+
store = await BlockStore.create(db_wrapper, use_cache=use_cache)
81+
await BlockStore.create(db_wrapper_2)
8282

8383
# Save/get block
8484
for block in blocks:
@@ -149,7 +149,7 @@ async def test_get_full_blocks_at(
149149
async with DBConnection(2) as db_wrapper:
150150
# Use a different file for the blockchain
151151
coin_store = await CoinStore.create(db_wrapper)
152-
block_store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
152+
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
153153
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
154154
bc = await Blockchain.create(coin_store, block_store, height_map, bt.constants, 2)
155155

@@ -177,7 +177,7 @@ async def test_get_block_records_in_range(
177177
async with DBConnection(2) as db_wrapper:
178178
# Use a different file for the blockchain
179179
coin_store = await CoinStore.create(db_wrapper)
180-
block_store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
180+
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
181181
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
182182
bc = await Blockchain.create(coin_store, block_store, height_map, bt.constants, 2)
183183

@@ -207,7 +207,7 @@ async def test_get_block_bytes_in_range_in_main_chain(
207207
async with DBConnection(2) as db_wrapper:
208208
# Use a different file for the blockchain
209209
coin_store = await CoinStore.create(db_wrapper)
210-
block_store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
210+
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
211211
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
212212
bc = await Blockchain.create(coin_store, block_store, height_map, bt.constants, 2)
213213
count = 0
@@ -234,9 +234,9 @@ async def test_deadlock(tmp_dir: Path, db_version: int, bt: BlockTools, use_cach
234234
blocks = bt.get_consecutive_blocks(10)
235235

236236
async with PathDBConnection(db_version) as wrapper, PathDBConnection(db_version) as wrapper_2:
237-
store = await BlockStore.create(wrapper, bt.constants, use_cache=use_cache)
237+
store = await BlockStore.create(wrapper, use_cache=use_cache)
238238
coin_store_2 = await CoinStore.create(wrapper_2)
239-
store_2 = await BlockStore.create(wrapper_2, bt.constants)
239+
store_2 = await BlockStore.create(wrapper_2)
240240
height_map = await BlockHeightMap.create(tmp_dir, wrapper_2)
241241
bc = await Blockchain.create(coin_store_2, store_2, height_map, bt.constants, 2)
242242
block_records = []
@@ -267,7 +267,7 @@ async def test_rollback(bt: BlockTools, tmp_dir: Path, use_cache: bool, default_
267267
async with DBConnection(2) as db_wrapper:
268268
# Use a different file for the blockchain
269269
coin_store = await CoinStore.create(db_wrapper)
270-
block_store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
270+
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
271271
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
272272
bc = await Blockchain.create(coin_store, block_store, height_map, bt.constants, 2)
273273

@@ -330,7 +330,7 @@ async def test_count_compactified_blocks(bt: BlockTools, tmp_dir: Path, db_versi
330330

331331
async with DBConnection(db_version) as db_wrapper:
332332
coin_store = await CoinStore.create(db_wrapper)
333-
block_store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
333+
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
334334
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
335335
bc = await Blockchain.create(coin_store, block_store, height_map, bt.constants, 2)
336336

@@ -351,7 +351,7 @@ async def test_count_uncompactified_blocks(bt: BlockTools, tmp_dir: Path, db_ver
351351

352352
async with DBConnection(db_version) as db_wrapper:
353353
coin_store = await CoinStore.create(db_wrapper)
354-
block_store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
354+
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
355355
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
356356
bc = await Blockchain.create(coin_store, block_store, height_map, bt.constants, 2)
357357

@@ -379,7 +379,7 @@ def rand_vdf_proof() -> VDFProof:
379379

380380
async with DBConnection(db_version) as db_wrapper:
381381
coin_store = await CoinStore.create(db_wrapper)
382-
block_store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
382+
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
383383
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
384384
bc = await Blockchain.create(coin_store, block_store, height_map, bt.constants, 2)
385385
for block in blocks:
@@ -416,7 +416,7 @@ def generator(i: int) -> SerializedProgram:
416416
return SerializedProgram.from_bytes(int_to_bytes(i + 1))
417417

418418
async with DBConnection(db_version) as db_wrapper:
419-
store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
419+
store = await BlockStore.create(db_wrapper, use_cache=use_cache)
420420

421421
new_blocks = []
422422
for i, original_block in enumerate(blocks):
@@ -460,12 +460,12 @@ async def test_get_blocks_by_hash(tmp_dir: Path, bt: BlockTools, db_version: int
460460
async with DBConnection(db_version) as db_wrapper, DBConnection(db_version) as db_wrapper_2:
461461
# Use a different file for the blockchain
462462
coin_store_2 = await CoinStore.create(db_wrapper_2)
463-
store_2 = await BlockStore.create(db_wrapper_2, bt.constants, use_cache=use_cache)
463+
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
464464
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
465465
bc = await Blockchain.create(coin_store_2, store_2, height_map, bt.constants, 2)
466466

467-
store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
468-
await BlockStore.create(db_wrapper_2, bt.constants)
467+
store = await BlockStore.create(db_wrapper, use_cache=use_cache)
468+
await BlockStore.create(db_wrapper_2)
469469

470470
print("starting test")
471471
hashes = []
@@ -500,11 +500,11 @@ async def test_get_block_bytes_in_range(tmp_dir: Path, bt: BlockTools, db_versio
500500
async with DBConnection(db_version) as db_wrapper_2:
501501
# Use a different file for the blockchain
502502
coin_store_2 = await CoinStore.create(db_wrapper_2)
503-
store_2 = await BlockStore.create(db_wrapper_2, bt.constants, use_cache=use_cache)
503+
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
504504
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
505505
bc = await Blockchain.create(coin_store_2, store_2, height_map, bt.constants, 2)
506506

507-
await BlockStore.create(db_wrapper_2, bt.constants)
507+
await BlockStore.create(db_wrapper_2)
508508

509509
# Save/get block
510510
for block in blocks:
@@ -525,13 +525,13 @@ async def test_get_block_bytes_in_range(tmp_dir: Path, bt: BlockTools, db_versio
525525
async def test_unsupported_version(tmp_dir: Path, use_cache: bool) -> None:
526526
with pytest.raises(RuntimeError, match="BlockStore does not support database schema v1"):
527527
async with DBConnection(1) as db_wrapper:
528-
await BlockStore.create(db_wrapper, DEFAULT_CONSTANTS, use_cache=use_cache)
528+
await BlockStore.create(db_wrapper, use_cache=use_cache)
529529

530530

531531
@pytest.mark.anyio
532532
async def test_get_peak(tmp_dir: Path, db_version: int, use_cache: bool) -> None:
533533
async with DBConnection(db_version) as db_wrapper:
534-
store = await BlockStore.create(db_wrapper, DEFAULT_CONSTANTS, use_cache=use_cache)
534+
store = await BlockStore.create(db_wrapper, use_cache=use_cache)
535535

536536
assert await store.get_peak() is None
537537

@@ -573,12 +573,12 @@ async def test_get_prev_hash(tmp_dir: Path, bt: BlockTools, db_version: int, use
573573
async with DBConnection(db_version) as db_wrapper, DBConnection(db_version) as db_wrapper_2:
574574
# Use a different file for the blockchain
575575
coin_store_2 = await CoinStore.create(db_wrapper_2)
576-
store_2 = await BlockStore.create(db_wrapper_2, bt.constants, use_cache=use_cache)
576+
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
577577
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
578578
bc = await Blockchain.create(coin_store_2, store_2, height_map, bt.constants, 2)
579579

580-
store = await BlockStore.create(db_wrapper, bt.constants, use_cache=use_cache)
581-
await BlockStore.create(db_wrapper_2, bt.constants)
580+
store = await BlockStore.create(db_wrapper, use_cache=use_cache)
581+
await BlockStore.create(db_wrapper_2)
582582

583583
# Save/get block
584584
for block in blocks:

0 commit comments

Comments
 (0)