Skip to content

Commit e6f755e

Browse files
committed
more tests
1 parent 7138f3d commit e6f755e

File tree

8 files changed

+41
-52
lines changed

8 files changed

+41
-52
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/blockchain/test_blockchain.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4217,9 +4217,7 @@ async def get_fork_info(blockchain: Blockchain, block: FullBlock, peak: BlockRec
42174217
counter = 0
42184218
start = time.monotonic()
42194219
for height in range(fork_info.fork_height + 1, block.height):
4220-
fork_block: Optional[FullBlock] = await blockchain.consensus_store.get_full_block(
4221-
fork_chain[uint32(height)]
4222-
)
4220+
fork_block: Optional[FullBlock] = await blockchain.consensus_store.get_full_block(fork_chain[uint32(height)])
42234221
assert fork_block is not None
42244222
assert fork_block.height - 1 == fork_info.peak_height
42254223
assert fork_block.height == 0 or fork_block.prev_header_hash == fork_info.peak_hash

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ async def test_basic_reorg(tmp_dir: Path, db_version: int, bt: BlockTools) -> No
340340
assert record.confirmed_block_index == block.height
341341
assert record.spent_block_index == 0
342342

343-
blocks_reorg_chain = bt.get_consecutive_blocks(
344-
reorg_length, blocks[: initial_block_count - 10], seed=b"2"
345-
)
343+
blocks_reorg_chain = bt.get_consecutive_blocks(reorg_length, blocks[: initial_block_count - 10], seed=b"2")
346344

347345
fork_info = ForkInfo(-1, -1, bt.constants.GENESIS_CHALLENGE)
348346
for reorg_block in blocks_reorg_chain:

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 & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from chia.consensus.augmented_chain import AugmentedBlockchain
4848
from chia.consensus.block_body_validation import ForkInfo
4949
from chia.consensus.blockchain import Blockchain
50-
from chia.consensus.coin_store_protocol import CoinStoreProtocol
50+
from chia.consensus.consensus_store_protocol import ConsensusStoreProtocol
5151
from chia.consensus.get_block_challenge import get_block_challenge
5252
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_block
5353
from chia.consensus.pot_iterations import is_overflow_block
@@ -2505,7 +2505,7 @@ def print_coin_records(records: dict[bytes32, CoinRecord]) -> None: # pragma: n
25052505
print(f"{rec}")
25062506

25072507

2508-
async def validate_coin_set(coin_store: CoinStoreProtocol, blocks: list[FullBlock]) -> None:
2508+
async def validate_coin_set(consensus_store: ConsensusStoreProtocol, blocks: list[FullBlock]) -> None:
25092509
prev_height = blocks[0].height - 1
25102510
prev_hash = blocks[0].prev_header_hash
25112511
for block in blocks:
@@ -2514,7 +2514,7 @@ async def validate_coin_set(coin_store: CoinStoreProtocol, blocks: list[FullBloc
25142514
prev_height = int(block.height)
25152515
prev_hash = block.header_hash
25162516
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)}
2517+
records = {rec.coin.name(): rec for rec in await consensus_store.get_coins_added_at_height(block.height)}
25182518

25192519
# validate reward coins
25202520
for reward in rewards:
@@ -2550,7 +2550,7 @@ async def validate_coin_set(coin_store: CoinStoreProtocol, blocks: list[FullBloc
25502550
print_coin_records(records)
25512551
assert records == {}
25522552

2553-
records = {rec.coin.name(): rec for rec in await coin_store.get_coins_removed_at_height(block.height)}
2553+
records = {rec.coin.name(): rec for rec in await consensus_store.get_coins_removed_at_height(block.height)}
25542554
for name, rem in removals:
25552555
rec = records.pop(name)
25562556
assert rec is not None
@@ -2598,8 +2598,8 @@ async def test_long_reorg(
25982598
assert reorg_blocks[fork_point] == default_10000_blocks[fork_point]
25992599
assert reorg_blocks[fork_point + 1] != default_10000_blocks[fork_point + 1]
26002600

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

26042604
# one aspect of this test is to make sure we can reorg blocks that are
26052605
# not in the cache. We need to explicitly prune the cache to get that
@@ -2614,7 +2614,7 @@ async def test_long_reorg(
26142614
chain_2_weight = peak.weight
26152615
chain_2_peak = peak.header_hash
26162616

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

26192619
# if the reorg chain has lighter blocks, once we've re-orged onto it, we
26202620
# have a greater block height. If the reorg chain has heavier blocks, we
@@ -2639,7 +2639,7 @@ async def test_long_reorg(
26392639
assert peak.header_hash != chain_2_peak
26402640
assert peak.weight > chain_2_weight
26412641

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

26442644

26452645
@pytest.mark.anyio
@@ -2665,9 +2665,9 @@ async def test_long_reorg_nodes(
26652665
) -> None:
26662666
full_node_1, full_node_2, full_node_3 = three_nodes
26672667

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
2668+
assert full_node_1.full_node.blockchain.consensus_store is not None
2669+
assert full_node_2.full_node.blockchain.consensus_store is not None
2670+
assert full_node_3.full_node.blockchain.consensus_store is not None
26712671

26722672
if light_blocks:
26732673
if fork_point == 1500:
@@ -2724,8 +2724,8 @@ def check_nodes_in_sync() -> bool:
27242724
assert p2 is not None
27252725
assert p2.header_hash == reorg_blocks[-1].header_hash
27262726

2727-
await validate_coin_set(full_node_1.full_node._coin_store, reorg_blocks)
2728-
await validate_coin_set(full_node_2.full_node._coin_store, reorg_blocks)
2727+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, reorg_blocks)
2728+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, reorg_blocks)
27292729

27302730
blocks = default_10000_blocks[:reorg_height]
27312731

@@ -2765,9 +2765,9 @@ def check_nodes_in_sync2() -> bool:
27652765
print(f"reorg1 timing: {reorg1_timing:0.2f}s")
27662766
print(f"reorg2 timing: {reorg2_timing:0.2f}s")
27672767

2768-
await validate_coin_set(full_node_1.full_node._coin_store, blocks)
2769-
await validate_coin_set(full_node_2.full_node._coin_store, blocks)
2770-
await validate_coin_set(full_node_3.full_node._coin_store, blocks)
2768+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, blocks)
2769+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, blocks)
2770+
await validate_coin_set(full_node_3.full_node.blockchain.consensus_store, blocks)
27712771

27722772

27732773
@pytest.mark.anyio
@@ -2804,8 +2804,8 @@ def check_nodes_in_sync() -> bool:
28042804
return p1 == p2
28052805

28062806
await time_out_assert(10, check_nodes_in_sync)
2807-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain)
2808-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain)
2807+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain)
2808+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain)
28092809

28102810
# we spend a coin in the next block
28112811
spend_bundle = wallet_a.generate_signed_transaction(uint64(1_000), receiver_puzzlehash, all_coins.pop())
@@ -2837,8 +2837,8 @@ def check_nodes_in_sync() -> bool:
28372837
await add_blocks_in_batches(chain_a[-1:], full_node_1.full_node)
28382838

28392839
await time_out_assert(10, check_nodes_in_sync)
2840-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain_a)
2841-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain_a)
2840+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain_a)
2841+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain_a)
28422842

28432843
await add_blocks_in_batches(chain_b[-1:], full_node_1.full_node)
28442844

@@ -2848,8 +2848,8 @@ def check_nodes_in_sync() -> bool:
28482848
assert peak.header_hash == chain_b[-1].header_hash
28492849

28502850
await time_out_assert(10, check_nodes_in_sync)
2851-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain_b)
2852-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain_b)
2851+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain_b)
2852+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain_b)
28532853

28542854
# now continue building the chain on top of B
28552855
# since spend_bundle was supposed to have been reorged-out, we should be
@@ -2884,8 +2884,8 @@ def check_nodes_in_sync() -> bool:
28842884

28852885
await add_blocks_in_batches(chain[-4:], full_node_1.full_node)
28862886
await time_out_assert(10, check_nodes_in_sync)
2887-
await validate_coin_set(full_node_1.full_node.blockchain.coin_store, chain)
2888-
await validate_coin_set(full_node_2.full_node.blockchain.coin_store, chain)
2887+
await validate_coin_set(full_node_1.full_node.blockchain.consensus_store, chain)
2888+
await validate_coin_set(full_node_2.full_node.blockchain.consensus_store, chain)
28892889

28902890

28912891
@pytest.mark.anyio

chia/_tests/util/blockchain.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ async def create_blockchain(
2626
) -> AsyncIterator[tuple[Blockchain, DBWrapper2]]:
2727
db_uri = generate_in_memory_db_uri()
2828
async with DBWrapper2.managed(database=db_uri, uri=True, reader_count=1, db_version=db_version) as wrapper:
29-
3029
block_store = await BlockStore.create(wrapper)
3130
coin_store = await CoinStore.create(wrapper)
3231
height_map = await BlockHeightMap.create(Path("."), wrapper, None)

chia/full_node/full_node.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
from chia.consensus.block_height_map import BlockHeightMap
4343
from chia.consensus.blockchain import AddBlockResult, Blockchain, BlockchainMutexPriority, StateChangeSummary
4444
from chia.consensus.blockchain_interface import BlockchainInterface
45-
from chia.consensus.coin_store_protocol import CoinStoreProtocol
4645
from chia.consensus.condition_tools import pkm_pairs
4746
from chia.consensus.cost_calculator import NPCResult
4847
from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_difficulty
@@ -158,7 +157,7 @@ class FullNode:
158157
_db_wrapper: Optional[DBWrapper2] = None
159158
_hint_store: Optional[HintStore] = None
160159
_block_store: Optional[BlockStore] = None
161-
_coin_store: Optional[CoinStoreProtocol] = None
160+
_coin_store: Optional[CoinStore] = None
162161
_mempool_manager: Optional[MempoolManager] = None
163162
_init_weight_proof: Optional[asyncio.Task[None]] = None
164163
_blockchain: Optional[Blockchain] = None
@@ -419,7 +418,7 @@ def blockchain(self) -> Blockchain:
419418
return self._blockchain
420419

421420
@property
422-
def coin_store(self) -> CoinStoreProtocol:
421+
def coin_store(self) -> CoinStore:
423422
assert self._coin_store is not None
424423
return self._coin_store
425424

chia/full_node/full_node_rpc_api.py

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

@@ -538,7 +538,7 @@ async def get_block_record_by_height(self, request: dict[str, Any]) -> EndpointR
538538
record: Optional[BlockRecord] = self.service.blockchain.try_block_record(header_hash)
539539
if record is None:
540540
# Fetch from DB
541-
record = await self.service.blockchain.block_store.get_block_record(header_hash)
541+
record = await self.service.block_store.get_block_record(header_hash)
542542
if record is None:
543543
raise ValueError(f"Block {header_hash} does not exist")
544544
return {"block_record": record}
@@ -551,7 +551,7 @@ async def get_block_record(self, request: dict[str, Any]) -> EndpointResult:
551551
record: Optional[BlockRecord] = self.service.blockchain.try_block_record(header_hash)
552552
if record is None:
553553
# Fetch from DB
554-
record = await self.service.blockchain.block_store.get_block_record(header_hash)
554+
record = await self.service.block_store.get_block_record(header_hash)
555555
if record is None:
556556
raise ValueError(f"Block {header_hash.hex()} does not exist")
557557

@@ -634,7 +634,7 @@ async def get_coin_records_by_puzzle_hash(self, request: dict[str, Any]) -> Endp
634634
if "include_spent_coins" in request:
635635
kwargs["include_spent_coins"] = request["include_spent_coins"]
636636

637-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_puzzle_hash(**kwargs)
637+
coin_records = await self.service.coin_store.get_coin_records_by_puzzle_hash(**kwargs)
638638

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

@@ -656,7 +656,7 @@ async def get_coin_records_by_puzzle_hashes(self, request: dict[str, Any]) -> En
656656
if "include_spent_coins" in request:
657657
kwargs["include_spent_coins"] = request["include_spent_coins"]
658658

659-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_puzzle_hashes(**kwargs)
659+
coin_records = await self.service.coin_store.get_coin_records_by_puzzle_hashes(**kwargs)
660660

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

@@ -668,7 +668,7 @@ async def get_coin_record_by_name(self, request: dict[str, Any]) -> EndpointResu
668668
raise ValueError("Name not in request")
669669
name = bytes32.from_hexstr(request["name"])
670670

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

@@ -692,7 +692,7 @@ async def get_coin_records_by_names(self, request: dict[str, Any]) -> EndpointRe
692692
if "include_spent_coins" in request:
693693
kwargs["include_spent_coins"] = request["include_spent_coins"]
694694

695-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_names(**kwargs)
695+
coin_records = await self.service.coin_store.get_coin_records_by_names(**kwargs)
696696

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

@@ -714,7 +714,7 @@ async def get_coin_records_by_parent_ids(self, request: dict[str, Any]) -> Endpo
714714
if "include_spent_coins" in request:
715715
kwargs["include_spent_coins"] = request["include_spent_coins"]
716716

717-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_parent_ids(**kwargs)
717+
coin_records = await self.service.coin_store.get_coin_records_by_parent_ids(**kwargs)
718718

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

@@ -743,7 +743,7 @@ async def get_coin_records_by_hint(self, request: dict[str, Any]) -> EndpointRes
743743
if "include_spent_coins" in request:
744744
kwargs["include_spent_coins"] = request["include_spent_coins"]
745745

746-
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_names(**kwargs)
746+
coin_records = await self.service.coin_store.get_coin_records_by_names(**kwargs)
747747

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

@@ -1018,7 +1018,7 @@ async def get_fee_estimate(self, request: dict[str, Any]) -> dict[str, Any]:
10181018
assert last_peak_timestamp is not None # mypy
10191019
assert last_tx_block.fees is not None # mypy
10201020

1021-
record = await self.service.blockchain.block_store.get_full_block(last_tx_block.header_hash)
1021+
record = await self.service.block_store.get_full_block(last_tx_block.header_hash)
10221022

10231023
last_block_cost = 0
10241024
fee_rate_last_block = 0.0

0 commit comments

Comments
 (0)