Skip to content

Commit 22f5bcb

Browse files
committed
more tests
1 parent e43fb07 commit 22f5bcb

File tree

4 files changed

+37
-41
lines changed

4 files changed

+37
-41
lines changed

chia/_tests/blockchain/blockchain_test_utils.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@
1515

1616

1717
async def check_block_store_invariant(bc: Blockchain):
18-
db_wrapper = bc.block_store.db_wrapper
19-
20-
if db_wrapper.db_version == 1:
21-
return
22-
2318
in_chain = set()
2419
max_height = -1
25-
async with bc.block_store.transaction() as conn:
20+
async with bc.consensus_store.transaction() as conn:
2621
async with conn.execute("SELECT height, in_main_chain FROM full_blocks") as cursor:
2722
rows = await cursor.fetchall()
2823
for row in rows:

chia/_tests/core/full_node/test_conditions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ async def check_spend_bundle_validity(
8383

8484
if expected_err is None:
8585
await _validate_and_add_block(blockchain, newest_block)
86-
coins_added = await blockchain.coin_store.get_coins_added_at_height(uint32(len(blocks)))
87-
coins_removed = await blockchain.coin_store.get_coins_removed_at_height(uint32(len(blocks)))
86+
coins_added = await blockchain.consensus_store.get_coins_added_at_height(uint32(len(blocks)))
87+
coins_removed = await blockchain.consensus_store.get_coins_removed_at_height(uint32(len(blocks)))
8888
else:
8989
await _validate_and_add_block(blockchain, newest_block, expected_error=expected_err)
9090
coins_added = []

chia/_tests/core/full_node/test_full_node.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from chia.consensus.block_body_validation import ForkInfo
4949
from chia.consensus.blockchain import Blockchain
5050
from chia.consensus.coin_store_protocol import CoinStoreProtocol
51+
from chia.consensus.consensus_store_protocol import ConsensusStoreProtocol
5152
from chia.consensus.get_block_challenge import get_block_challenge
5253
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_block
5354
from chia.consensus.pot_iterations import is_overflow_block
@@ -2505,7 +2506,7 @@ def print_coin_records(records: dict[bytes32, CoinRecord]) -> None: # pragma: n
25052506
print(f"{rec}")
25062507

25072508

2508-
async def validate_coin_set(coin_store: CoinStoreProtocol, blocks: list[FullBlock]) -> None:
2509+
async def validate_coin_set(consensus_store: ConsensusStoreProtocol, blocks: list[FullBlock]) -> None:
25092510
prev_height = blocks[0].height - 1
25102511
prev_hash = blocks[0].prev_header_hash
25112512
for block in blocks:
@@ -2514,7 +2515,7 @@ async def validate_coin_set(coin_store: CoinStoreProtocol, blocks: list[FullBloc
25142515
prev_height = int(block.height)
25152516
prev_hash = block.header_hash
25162517
rewards = block.get_included_reward_coins()
2517-
records = {rec.coin.name(): rec for rec in await coin_store.get_coins_added_at_height(block.height)}
2518+
records = {rec.coin.name(): rec for rec in await consensus_store.get_coins_added_at_height(block.height)}
25182519

25192520
# validate reward coins
25202521
for reward in rewards:
@@ -2550,7 +2551,7 @@ async def validate_coin_set(coin_store: CoinStoreProtocol, blocks: list[FullBloc
25502551
print_coin_records(records)
25512552
assert records == {}
25522553

2553-
records = {rec.coin.name(): rec for rec in await coin_store.get_coins_removed_at_height(block.height)}
2554+
records = {rec.coin.name(): rec for rec in await consensus_store.get_coins_removed_at_height(block.height)}
25542555
for name, rem in removals:
25552556
rec = records.pop(name)
25562557
assert rec is not None
@@ -2598,8 +2599,8 @@ async def test_long_reorg(
25982599
assert reorg_blocks[fork_point] == default_10000_blocks[fork_point]
25992600
assert reorg_blocks[fork_point + 1] != default_10000_blocks[fork_point + 1]
26002601

2601-
assert node.full_node._coin_store is not None
2602-
await validate_coin_set(node.full_node._coin_store, blocks)
2602+
assert node.full_node.blockchain.consensus_store is not None
2603+
await validate_coin_set(node.full_node.blockchain.consensus_store, blocks)
26032604

26042605
# one aspect of this test is to make sure we can reorg blocks that are
26052606
# not in the cache. We need to explicitly prune the cache to get that
@@ -2614,7 +2615,7 @@ async def test_long_reorg(
26142615
chain_2_weight = peak.weight
26152616
chain_2_peak = peak.header_hash
26162617

2617-
await validate_coin_set(node.full_node._coin_store, reorg_blocks)
2618+
await validate_coin_set(node.full_node.blockchain.consensus_store, reorg_blocks)
26182619

26192620
# if the reorg chain has lighter blocks, once we've re-orged onto it, we
26202621
# have a greater block height. If the reorg chain has heavier blocks, we
@@ -2639,7 +2640,7 @@ async def test_long_reorg(
26392640
assert peak.header_hash != chain_2_peak
26402641
assert peak.weight > chain_2_weight
26412642

2642-
await validate_coin_set(node.full_node._coin_store, blocks)
2643+
await validate_coin_set(node.full_node.blockchain.consensus_store, blocks)
26432644

26442645

26452646
@pytest.mark.anyio
@@ -2665,9 +2666,9 @@ async def test_long_reorg_nodes(
26652666
) -> None:
26662667
full_node_1, full_node_2, full_node_3 = three_nodes
26672668

2668-
assert full_node_1.full_node._coin_store is not None
2669-
assert full_node_2.full_node._coin_store is not None
2670-
assert full_node_3.full_node._coin_store is not None
2669+
assert full_node_1.full_node.blockchain.consensus_store is not None
2670+
assert full_node_2.full_node.blockchain.consensus_store is not None
2671+
assert full_node_3.full_node.blockchain.consensus_store is not None
26712672

26722673
if light_blocks:
26732674
if fork_point == 1500:
@@ -2725,8 +2726,8 @@ def check_nodes_in_sync() -> bool:
27252726
assert p2 is not None
27262727
assert p2.header_hash == reorg_blocks[-1].header_hash
27272728

2728-
await validate_coin_set(full_node_1.full_node._coin_store, reorg_blocks)
2729-
await validate_coin_set(full_node_2.full_node._coin_store, reorg_blocks)
2729+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, reorg_blocks)
2730+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, reorg_blocks)
27302731

27312732
blocks = default_10000_blocks[:reorg_height]
27322733

@@ -2766,9 +2767,9 @@ def check_nodes_in_sync2() -> bool:
27662767
print(f"reorg1 timing: {reorg1_timing:0.2f}s")
27672768
print(f"reorg2 timing: {reorg2_timing:0.2f}s")
27682769

2769-
await validate_coin_set(full_node_1.full_node._coin_store, blocks)
2770-
await validate_coin_set(full_node_2.full_node._coin_store, blocks)
2771-
await validate_coin_set(full_node_3.full_node._coin_store, blocks)
2770+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, blocks)
2771+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, blocks)
2772+
await validate_coin_set(full_node_3.full_node.blockchain.consensus_store, blocks)
27722773

27732774

27742775
@pytest.mark.anyio
@@ -2805,8 +2806,8 @@ def check_nodes_in_sync() -> bool:
28052806
return p1 == p2
28062807

28072808
await time_out_assert(10, check_nodes_in_sync)
2808-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain)
2809-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain)
2809+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain)
2810+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain)
28102811

28112812
# we spend a coin in the next block
28122813
spend_bundle = wallet_a.generate_signed_transaction(uint64(1_000), receiver_puzzlehash, all_coins.pop())
@@ -2838,8 +2839,8 @@ def check_nodes_in_sync() -> bool:
28382839
await add_blocks_in_batches(chain_a[-1:], full_node_1.full_node)
28392840

28402841
await time_out_assert(10, check_nodes_in_sync)
2841-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain_a)
2842-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain_a)
2842+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain_a)
2843+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain_a)
28432844

28442845
await add_blocks_in_batches(chain_b[-1:], full_node_1.full_node)
28452846

@@ -2849,8 +2850,8 @@ def check_nodes_in_sync() -> bool:
28492850
assert peak.header_hash == chain_b[-1].header_hash
28502851

28512852
await time_out_assert(10, check_nodes_in_sync)
2852-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain_b)
2853-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain_b)
2853+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain_b)
2854+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain_b)
28542855

28552856
# now continue building the chain on top of B
28562857
# since spend_bundle was supposed to have been reorged-out, we should be
@@ -2885,8 +2886,8 @@ def check_nodes_in_sync() -> bool:
28852886

28862887
await add_blocks_in_batches(chain[-4:], full_node_1.full_node)
28872888
await time_out_assert(10, check_nodes_in_sync)
2888-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain)
2889-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain)
2889+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain)
2890+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain)
28902891

28912892

28922893
@pytest.mark.anyio

chia/full_node/full_node_rpc_api.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ async def get_block_records(self, request: dict[str, Any]) -> EndpointResult:
466466
record: Optional[BlockRecord] = self.service.blockchain.try_block_record(header_hash)
467467
if record is None:
468468
# Fetch from DB
469-
record = await self.service.blockchain.block_store.get_block_record(header_hash)
469+
record = await self.service.block_store.get_block_record(header_hash)
470470
if record is None:
471471
raise ValueError(f"Block {header_hash.hex()} does not exist")
472472

@@ -528,7 +528,7 @@ async def get_block_record_by_height(self, request: dict[str, Any]) -> EndpointR
528528
record: Optional[BlockRecord] = self.service.blockchain.try_block_record(header_hash)
529529
if record is None:
530530
# Fetch from DB
531-
record = await self.service.blockchain.block_store.get_block_record(header_hash)
531+
record = await self.service.block_store.get_block_record(header_hash)
532532
if record is None:
533533
raise ValueError(f"Block {header_hash} does not exist")
534534
return {"block_record": record}
@@ -541,7 +541,7 @@ async def get_block_record(self, request: dict[str, Any]) -> EndpointResult:
541541
record: Optional[BlockRecord] = self.service.blockchain.try_block_record(header_hash)
542542
if record is None:
543543
# Fetch from DB
544-
record = await self.service.blockchain.block_store.get_block_record(header_hash)
544+
record = await self.service.block_store.get_block_record(header_hash)
545545
if record is None:
546546
raise ValueError(f"Block {header_hash.hex()} does not exist")
547547

@@ -624,7 +624,7 @@ async def get_coin_records_by_puzzle_hash(self, request: dict[str, Any]) -> Endp
624624
if "include_spent_coins" in request:
625625
kwargs["include_spent_coins"] = request["include_spent_coins"]
626626

627-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_puzzle_hash(**kwargs)
627+
coin_records = await self.service.coin_store.get_coin_records_by_puzzle_hash(**kwargs)
628628

629629
return {"coin_records": [coin_record_dict_backwards_compat(cr.to_json_dict()) for cr in coin_records]}
630630

@@ -646,7 +646,7 @@ async def get_coin_records_by_puzzle_hashes(self, request: dict[str, Any]) -> En
646646
if "include_spent_coins" in request:
647647
kwargs["include_spent_coins"] = request["include_spent_coins"]
648648

649-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_puzzle_hashes(**kwargs)
649+
coin_records = await self.service.coin_store.get_coin_records_by_puzzle_hashes(**kwargs)
650650

651651
return {"coin_records": [coin_record_dict_backwards_compat(cr.to_json_dict()) for cr in coin_records]}
652652

@@ -658,7 +658,7 @@ async def get_coin_record_by_name(self, request: dict[str, Any]) -> EndpointResu
658658
raise ValueError("Name not in request")
659659
name = bytes32.from_hexstr(request["name"])
660660

661-
coin_record: Optional[CoinRecord] = await self.service.blockchain.coin_store.get_coin_record(name)
661+
coin_record: Optional[CoinRecord] = await self.service.coin_store.get_coin_record(name)
662662
if coin_record is None:
663663
raise ValueError(f"Coin record 0x{name.hex()} not found")
664664

@@ -682,7 +682,7 @@ async def get_coin_records_by_names(self, request: dict[str, Any]) -> EndpointRe
682682
if "include_spent_coins" in request:
683683
kwargs["include_spent_coins"] = request["include_spent_coins"]
684684

685-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_names(**kwargs)
685+
coin_records = await self.service.coin_store.get_coin_records_by_names(**kwargs)
686686

687687
return {"coin_records": [coin_record_dict_backwards_compat(cr.to_json_dict()) for cr in coin_records]}
688688

@@ -704,7 +704,7 @@ async def get_coin_records_by_parent_ids(self, request: dict[str, Any]) -> Endpo
704704
if "include_spent_coins" in request:
705705
kwargs["include_spent_coins"] = request["include_spent_coins"]
706706

707-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_parent_ids(**kwargs)
707+
coin_records = await self.service.coin_store.get_coin_records_by_parent_ids(**kwargs)
708708

709709
return {"coin_records": [coin_record_dict_backwards_compat(cr.to_json_dict()) for cr in coin_records]}
710710

@@ -733,7 +733,7 @@ async def get_coin_records_by_hint(self, request: dict[str, Any]) -> EndpointRes
733733
if "include_spent_coins" in request:
734734
kwargs["include_spent_coins"] = request["include_spent_coins"]
735735

736-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_names(**kwargs)
736+
coin_records = await self.service.coin_store.get_coin_records_by_names(**kwargs)
737737

738738
return {"coin_records": [coin_record_dict_backwards_compat(cr.to_json_dict()) for cr in coin_records]}
739739

@@ -1008,7 +1008,7 @@ async def get_fee_estimate(self, request: dict[str, Any]) -> dict[str, Any]:
10081008
assert last_peak_timestamp is not None # mypy
10091009
assert last_tx_block.fees is not None # mypy
10101010

1011-
record = await self.service.blockchain.block_store.get_full_block(last_tx_block.header_hash)
1011+
record = await self.service.block_store.get_full_block(last_tx_block.header_hash)
10121012

10131013
last_block_cost = 0
10141014
fee_rate_last_block = 0.0

0 commit comments

Comments
 (0)