Skip to content

Commit aa51352

Browse files
committed
simplify diffs
1 parent f9c5c22 commit aa51352

File tree

6 files changed

+26
-69
lines changed

6 files changed

+26
-69
lines changed

chia/_tests/blockchain/blockchain_test_utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616

1717

1818
async def check_block_store_invariant(bc: Blockchain):
19-
# This function checks the invariant of the sqlite database.
20-
# Only operate on the sqlite block store.
2119
assert isinstance(bc.consensus_store, ConsensusStoreSQLite3)
2220

23-
db_wrapper = bc.consensus_store.block_store.db_wrapper
24-
25-
if db_wrapper.db_version == 1:
21+
if bc.consensus_store.block_store.db_wrapper == 1:
2622
return
2723

2824
in_chain = set()

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

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
1919
from chia._tests.util.db_connection import DBConnection, PathDBConnection
2020
from chia.consensus.block_body_validation import ForkInfo
21-
from chia.consensus.block_height_map import BlockHeightMap
2221
from chia.consensus.blockchain import AddBlockResult, Blockchain
2322
from chia.consensus.default_constants import DEFAULT_CONSTANTS
2423
from chia.consensus.full_block_to_block_record import header_block_to_sub_block_record
2524
from chia.full_node.block_store import BlockStore
26-
from chia.full_node.coin_store import CoinStore
2725
from chia.full_node.consensus_store_sqlite3 import ConsensusStoreSQLite3
2826
from chia.full_node.full_block_utils import GeneratorBlockInfo
2927
from chia.simulator.block_tools import BlockTools
@@ -72,10 +70,7 @@ async def test_block_store(tmp_dir: Path, db_version: int, bt: BlockTools, use_c
7270

7371
async with DBConnection(db_version) as db_wrapper, DBConnection(db_version) as db_wrapper_2:
7472
# Use a different file for the blockchain
75-
coin_store_2 = await CoinStore.create(db_wrapper_2)
76-
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
77-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
78-
consensus_store = ConsensusStoreSQLite3(store_2, coin_store_2, height_map)
73+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper_2, tmp_dir, use_cache=use_cache)
7974
bc = await Blockchain.create(consensus_store, bt.constants, 2)
8075

8176
store = await BlockStore.create(db_wrapper, use_cache=use_cache)
@@ -233,10 +228,7 @@ async def test_deadlock(tmp_dir: Path, db_version: int, bt: BlockTools, use_cach
233228

234229
async with PathDBConnection(db_version) as wrapper, PathDBConnection(db_version) as wrapper_2:
235230
store = await BlockStore.create(wrapper, use_cache=use_cache)
236-
coin_store_2 = await CoinStore.create(wrapper_2)
237-
store_2 = await BlockStore.create(wrapper_2)
238-
height_map = await BlockHeightMap.create(tmp_dir, wrapper_2)
239-
consensus_store = ConsensusStoreSQLite3(store_2, coin_store_2, height_map)
231+
consensus_store = await ConsensusStoreSQLite3.create(wrapper_2, tmp_dir, use_cache=use_cache)
240232
bc = await Blockchain.create(consensus_store, bt.constants, 2)
241233
block_records = []
242234
for block in blocks:
@@ -327,10 +319,8 @@ async def test_count_compactified_blocks(bt: BlockTools, tmp_dir: Path, db_versi
327319
blocks = bt.get_consecutive_blocks(10)
328320

329321
async with DBConnection(db_version) as db_wrapper:
330-
coin_store = await CoinStore.create(db_wrapper)
331-
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
332-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
333-
consensus_store = ConsensusStoreSQLite3(block_store, coin_store, height_map)
322+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper, tmp_dir, use_cache=use_cache)
323+
block_store = consensus_store.block_store
334324
bc = await Blockchain.create(consensus_store, bt.constants, 2)
335325

336326
count = await block_store.count_compactified_blocks()
@@ -349,10 +339,8 @@ async def test_count_uncompactified_blocks(bt: BlockTools, tmp_dir: Path, db_ver
349339
blocks = bt.get_consecutive_blocks(10)
350340

351341
async with DBConnection(db_version) as db_wrapper:
352-
coin_store = await CoinStore.create(db_wrapper)
353-
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
354-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
355-
consensus_store = ConsensusStoreSQLite3(block_store, coin_store, height_map)
342+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper, tmp_dir, use_cache=use_cache)
343+
block_store = consensus_store.block_store
356344
bc = await Blockchain.create(consensus_store, bt.constants, 2)
357345

358346
count = await block_store.count_uncompactified_blocks()
@@ -378,10 +366,8 @@ def rand_vdf_proof() -> VDFProof:
378366
)
379367

380368
async with DBConnection(db_version) as db_wrapper:
381-
coin_store = await CoinStore.create(db_wrapper)
382-
block_store = await BlockStore.create(db_wrapper, use_cache=use_cache)
383-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
384-
consensus_store = ConsensusStoreSQLite3(block_store, coin_store, height_map)
369+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper, tmp_dir, use_cache=use_cache)
370+
block_store = consensus_store.block_store
385371
bc = await Blockchain.create(consensus_store, bt.constants, 2)
386372
for block in blocks:
387373
await _validate_and_add_block(bc, block)
@@ -460,10 +446,7 @@ async def test_get_blocks_by_hash(tmp_dir: Path, bt: BlockTools, db_version: int
460446

461447
async with DBConnection(db_version) as db_wrapper, DBConnection(db_version) as db_wrapper_2:
462448
# Use a different file for the blockchain
463-
coin_store_2 = await CoinStore.create(db_wrapper_2)
464-
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
465-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
466-
consensus_store = ConsensusStoreSQLite3(store_2, coin_store_2, height_map)
449+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper_2, tmp_dir, use_cache=use_cache)
467450
bc = await Blockchain.create(consensus_store, bt.constants, 2)
468451

469452
store = await BlockStore.create(db_wrapper, use_cache=use_cache)
@@ -501,10 +484,8 @@ async def test_get_block_bytes_in_range(tmp_dir: Path, bt: BlockTools, db_versio
501484

502485
async with DBConnection(db_version) as db_wrapper_2:
503486
# Use a different file for the blockchain
504-
coin_store_2 = await CoinStore.create(db_wrapper_2)
505-
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
506-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
507-
consensus_store = ConsensusStoreSQLite3(store_2, coin_store_2, height_map)
487+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper_2, tmp_dir, use_cache=use_cache)
488+
store_2 = consensus_store.block_store
508489
bc = await Blockchain.create(consensus_store, bt.constants, 2)
509490

510491
await BlockStore.create(db_wrapper_2)
@@ -575,10 +556,7 @@ async def test_get_prev_hash(tmp_dir: Path, bt: BlockTools, db_version: int, use
575556

576557
async with DBConnection(db_version) as db_wrapper, DBConnection(db_version) as db_wrapper_2:
577558
# Use a different file for the blockchain
578-
coin_store_2 = await CoinStore.create(db_wrapper_2)
579-
store_2 = await BlockStore.create(db_wrapper_2, use_cache=use_cache)
580-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper_2)
581-
consensus_store = ConsensusStoreSQLite3(store_2, coin_store_2, height_map)
559+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper_2, tmp_dir, use_cache=use_cache)
582560
bc = await Blockchain.create(consensus_store, bt.constants, 2)
583561

584562
store = await BlockStore.create(db_wrapper, use_cache=use_cache)

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
from chia._tests.util.db_connection import DBConnection
1717
from chia._tests.util.misc import Marks, datacases
1818
from chia.consensus.block_body_validation import ForkInfo
19-
from chia.consensus.block_height_map import BlockHeightMap
2019
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
2120
from chia.consensus.blockchain import AddBlockResult, Blockchain
2221
from chia.consensus.coinbase import create_farmer_coin, create_pool_coin
23-
from chia.full_node.block_store import BlockStore
2422
from chia.full_node.coin_store import CoinStore
2523
from chia.full_node.consensus_store_sqlite3 import ConsensusStoreSQLite3
2624
from chia.full_node.hint_store import HintStore
@@ -316,10 +314,8 @@ async def test_basic_reorg(tmp_dir: Path, db_version: int, bt: BlockTools) -> No
316314
initial_block_count = 30
317315
reorg_length = 15
318316
blocks = bt.get_consecutive_blocks(initial_block_count)
319-
coin_store = await CoinStore.create(db_wrapper)
320-
store = await BlockStore.create(db_wrapper)
321-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
322-
consensus_store = ConsensusStoreSQLite3(store, coin_store, height_map)
317+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper, tmp_dir)
318+
coin_store = consensus_store.coin_store
323319
b: Blockchain = await Blockchain.create(consensus_store, bt.constants, 2)
324320
try:
325321
records: list[Optional[CoinRecord]] = []
@@ -384,10 +380,8 @@ async def test_get_puzzle_hash(tmp_dir: Path, db_version: int, bt: BlockTools) -
384380
pool_reward_puzzle_hash=pool_ph,
385381
guarantee_transaction_block=True,
386382
)
387-
coin_store = await CoinStore.create(db_wrapper)
388-
store = await BlockStore.create(db_wrapper)
389-
height_map = await BlockHeightMap.create(tmp_dir, db_wrapper)
390-
consensus_store = ConsensusStoreSQLite3(store, coin_store, height_map)
383+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper, tmp_dir)
384+
coin_store = consensus_store.coin_store
391385
b: Blockchain = await Blockchain.create(consensus_store, bt.constants, 2)
392386
for block in blocks:
393387
await _validate_and_add_block(b, block)

chia/_tests/core/test_db_conversion.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
from chia._tests.util.temp_file import TempFile
1111
from chia.cmds.db_upgrade_func import convert_v1_to_v2
1212
from chia.consensus.block_body_validation import ForkInfo
13-
from chia.consensus.block_height_map import BlockHeightMap
1413
from chia.consensus.blockchain import Blockchain
1514
from chia.consensus.multiprocess_validation import PreValidationResult
16-
from chia.full_node.block_store import BlockStore
17-
from chia.full_node.coin_store import CoinStore
1815
from chia.full_node.consensus_store_sqlite3 import ConsensusStoreSQLite3
1916
from chia.full_node.hint_store import HintStore
2017
from chia.simulator.block_tools import test_constants
@@ -55,15 +52,11 @@ async def test_blocks(default_1000_blocks, with_hints: bool):
5552
journal_mode="OFF",
5653
synchronous="OFF",
5754
) as db_wrapper1:
58-
block_store1 = await BlockStore.create(db_wrapper1)
59-
coin_store1 = await CoinStore.create(db_wrapper1)
55+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper1, Path("."))
6056
hint_store1 = await HintStore.create(db_wrapper1)
6157
if with_hints:
6258
for h in hints:
6359
await hint_store1.add_hints([(h[0], h[1])])
64-
65-
height_map = await BlockHeightMap.create(Path("."), db_wrapper1)
66-
consensus_store = ConsensusStoreSQLite3(block_store1, coin_store1, height_map)
6760
bc = await Blockchain.create(consensus_store, test_constants, reserved_cores=0)
6861
sub_slot_iters = test_constants.SUB_SLOT_ITERS_STARTING
6962
for block in blocks:
@@ -81,12 +74,14 @@ async def test_blocks(default_1000_blocks, with_hints: bool):
8174

8275
async with DBWrapper2.managed(database=in_file, reader_count=1, db_version=1) as db_wrapper1:
8376
async with DBWrapper2.managed(database=out_file, reader_count=1, db_version=2) as db_wrapper2:
84-
block_store1 = await BlockStore.create(db_wrapper1)
85-
coin_store1 = await CoinStore.create(db_wrapper1)
77+
consensus_store1 = await ConsensusStoreSQLite3.create(db_wrapper1, Path("."))
78+
block_store1 = consensus_store1.block_store
79+
coin_store1 = consensus_store1.coin_store
8680
hint_store1 = await HintStore.create(db_wrapper1)
8781

88-
block_store2 = await BlockStore.create(db_wrapper2)
89-
coin_store2 = await CoinStore.create(db_wrapper2)
82+
consensus_store2 = await ConsensusStoreSQLite3.create(db_wrapper2, Path("."))
83+
block_store2 = consensus_store2.block_store
84+
coin_store2 = consensus_store2.coin_store
9085
hint_store2 = await HintStore.create(db_wrapper2)
9186

9287
if with_hints:

chia/_tests/core/test_db_validation.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
from chia._tests.util.temp_file import TempFile
1414
from chia.cmds.db_validate_func import validate_v2
1515
from chia.consensus.block_body_validation import ForkInfo
16-
from chia.consensus.block_height_map import BlockHeightMap
1716
from chia.consensus.blockchain import Blockchain
1817
from chia.consensus.default_constants import DEFAULT_CONSTANTS
1918
from chia.consensus.multiprocess_validation import PreValidationResult
20-
from chia.full_node.block_store import BlockStore
21-
from chia.full_node.coin_store import CoinStore
2219
from chia.full_node.consensus_store_sqlite3 import ConsensusStoreSQLite3
2320
from chia.simulator.block_tools import test_constants
2421
from chia.util.db_wrapper import DBWrapper2
@@ -139,10 +136,7 @@ async def make_db(db_file: Path, blocks: list[FullBlock]) -> None:
139136
await conn.execute("CREATE TABLE database_version(version int)")
140137
await conn.execute("INSERT INTO database_version VALUES (2)")
141138

142-
block_store = await BlockStore.create(db_wrapper)
143-
coin_store = await CoinStore.create(db_wrapper)
144-
height_map = await BlockHeightMap.create(Path("."), db_wrapper)
145-
consensus_store = ConsensusStoreSQLite3(block_store, coin_store, height_map)
139+
consensus_store = await ConsensusStoreSQLite3.create(db_wrapper, Path("."))
146140
bc = await Blockchain.create(consensus_store, test_constants, reserved_cores=0)
147141
sub_slot_iters = test_constants.SUB_SLOT_ITERS_STARTING
148142
for block in blocks:

chia/full_node/full_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ async def manage(self) -> AsyncIterator[None]:
267267
multiprocessing_start_method = process_config_start_method(config=self.config, log=self.log)
268268
self.multiprocessing_context = multiprocessing.get_context(method=multiprocessing_start_method)
269269
selected_network = self.config.get("selected_network")
270-
height_map = await BlockHeightMap.create(self.db_path.parent, self.db_wrapper, selected_network)
270+
height_map = await BlockHeightMap.create(self.db_path.parent, self._db_wrapper, selected_network)
271271
consensus_store = ConsensusStoreSQLite3(self.block_store, self.coin_store, height_map)
272272
self._blockchain = await Blockchain.create(
273273
consensus_store=consensus_store,

0 commit comments

Comments
 (0)