Skip to content

Commit b2aab8a

Browse files
committed
Undo test changes and silly api
1 parent f8d30e4 commit b2aab8a

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

chia/_tests/blockchain/blockchain_test_utils.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,42 @@
1010
from chia.consensus.blockchain import AddBlockResult, Blockchain
1111
from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_difficulty
1212
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_block
13+
from chia.full_node.consensus_store_sqlite3 import ConsensusStoreSQLite3
1314
from chia.types.validation_state import ValidationState
1415
from chia.util.errors import Err
1516

1617

1718
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.
21+
if not isinstance(bc.consensus_store, ConsensusStoreSQLite3):
22+
return
23+
24+
db_wrapper = bc.consensus_store.block_store.db_wrapper
25+
26+
if db_wrapper.db_version == 1:
27+
return
28+
1829
in_chain = set()
1930
max_height = -1
20-
async for height in bc.consensus_store.get_block_heights_in_main_chain():
21-
# if this block is in-chain, ensure we haven't found another block
22-
# at this height that's also in chain. That would be an invariant
23-
# violation
24-
# make sure we don't have any duplicate heights. Each block
25-
# height can only have a single block with in_main_chain set
26-
assert height not in in_chain
27-
in_chain.add(height)
28-
max_height = max(max_height, height)
29-
30-
# make sure every height is represented in the set
31-
assert len(in_chain) == max_height + 1
31+
async with bc.consensus_store.block_store.transaction() as conn:
32+
async with conn.execute("SELECT height, in_main_chain FROM full_blocks") as cursor:
33+
rows = await cursor.fetchall()
34+
for row in rows:
35+
height = row[0]
36+
37+
# if this block is in-chain, ensure we haven't found another block
38+
# at this height that's also in chain. That would be an invariant
39+
# violation
40+
if row[1]:
41+
# make sure we don't have any duplicate heights. Each block
42+
# height can only have a single block with in_main_chain set
43+
assert height not in in_chain
44+
in_chain.add(height)
45+
max_height = max(max_height, height)
46+
47+
# make sure every height is represented in the set
48+
assert len(in_chain) == max_height + 1
3249

3350

3451
async def _validate_and_add_block(

chia/consensus/consensus_store_protocol.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from collections.abc import AsyncIterator, Collection
3+
from collections.abc import Collection
44
from types import TracebackType
55
from typing import Optional, Protocol
66

@@ -85,7 +85,6 @@ async def get_sub_epoch_challenge_segments(
8585
) -> Optional[list[SubEpochChallengeSegment]]: ...
8686
async def get_generator(self, header_hash: bytes32) -> Optional[bytes]: ...
8787
async def get_generators_at(self, heights: set[uint32]) -> dict[uint32, bytes]: ...
88-
def get_block_heights_in_main_chain(self) -> AsyncIterator[int]: ...
8988

9089
# Coin store reads
9190
async def get_coin_records(self, names: Collection[bytes32]) -> list[CoinRecord]: ...

chia/full_node/consensus_store_sqlite3.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from collections.abc import AsyncIterator, Collection
3+
from collections.abc import Collection
44
from contextlib import AbstractAsyncContextManager
55
from dataclasses import dataclass
66
from pathlib import Path
@@ -187,16 +187,6 @@ async def get_coins_added_at_height(self, height: uint32) -> list[CoinRecord]:
187187
async def get_coins_removed_at_height(self, height: uint32) -> list[CoinRecord]:
188188
return await self.coin_store.get_coins_removed_at_height(height)
189189

190-
def get_block_heights_in_main_chain(self) -> AsyncIterator[int]:
191-
async def gen() -> AsyncIterator[int]:
192-
async with self.block_store.transaction() as conn:
193-
async with conn.execute("SELECT height, in_main_chain FROM full_blocks") as cursor:
194-
async for row in cursor:
195-
if row[1]:
196-
yield row[0]
197-
198-
return gen()
199-
200190
# Height map methods
201191
def get_ses_heights(self) -> list[uint32]:
202192
return self.height_map.get_ses_heights()

0 commit comments

Comments
 (0)