-
Notifications
You must be signed in to change notification settings - Fork 2.1k
BlockStoreProtocol #19799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
BlockStoreProtocol #19799
Changes from all commits
49422b7
165f628
8046b01
67986f9
edb6d3f
f1f195e
f1a3dc0
6a4f2a1
2458f01
7fbc2f7
6a92c7a
6cee193
2c7c884
4ac3d58
2c71a1f
c97a282
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
from typing import Optional, cast | ||
|
||
from chia_rs import FullBlock, SpendBundleConditions | ||
from chia_rs.sized_ints import uint32, uint64 | ||
|
@@ -10,19 +10,20 @@ | |
from chia.consensus.blockchain import AddBlockResult, Blockchain | ||
from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_difficulty | ||
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_block | ||
from chia.full_node.block_store import BlockStore | ||
from chia.types.validation_state import ValidationState | ||
from chia.util.errors import Err | ||
|
||
|
||
async def check_block_store_invariant(bc: Blockchain): | ||
db_wrapper = bc.block_store.db_wrapper | ||
block_store = cast(BlockStore, bc.block_store) | ||
|
||
if db_wrapper.db_version == 1: | ||
if block_store.db_wrapper.db_version == 1: | ||
return | ||
|
||
in_chain = set() | ||
max_height = -1 | ||
async with bc.block_store.transaction() as conn: | ||
async with block_store.transaction() as conn: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
async with conn.execute("SELECT height, in_main_chain FROM full_blocks") as cursor: | ||
rows = await cursor.fetchall() | ||
for row in rows: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from contextlib import AbstractAsyncContextManager | ||
from typing import Any, Optional, Protocol | ||
|
||
from chia_rs import BlockRecord, FullBlock, SubEpochChallengeSegment | ||
from chia_rs.sized_bytes import bytes32 | ||
from chia_rs.sized_ints import uint32 | ||
|
||
|
||
class BlockStoreProtocol(Protocol): | ||
async def add_full_block(self, header_hash: bytes32, block: FullBlock, block_record: BlockRecord) -> None: ... | ||
def get_block_from_cache(self, header_hash: bytes32) -> Optional[FullBlock]: ... | ||
async def get_full_block(self, header_hash: bytes32) -> Optional[FullBlock]: ... | ||
async def get_generator(self, header_hash: bytes32) -> Optional[bytes]: ... | ||
async def get_generators_at(self, heights: set[uint32]) -> dict[uint32, bytes]: ... | ||
async def get_block_record(self, header_hash: bytes32) -> Optional[BlockRecord]: ... | ||
async def get_block_records_in_range(self, start: int, stop: int) -> dict[bytes32, BlockRecord]: ... | ||
async def get_block_records_by_hash(self, header_hashes: list[bytes32]) -> list[BlockRecord]: ... | ||
async def get_blocks_by_hash(self, header_hashes: list[bytes32]) -> list[FullBlock]: ... | ||
async def persist_sub_epoch_challenge_segments( | ||
self, ses_block_hash: bytes32, segments: list[SubEpochChallengeSegment] | ||
) -> None: ... | ||
async def get_sub_epoch_challenge_segments( | ||
self, | ||
ses_block_hash: bytes32, | ||
) -> Optional[list[SubEpochChallengeSegment]]: ... | ||
async def rollback(self, height: int) -> None: ... | ||
def rollback_cache_block(self, header_hash: bytes32) -> None: ... | ||
async def set_in_chain(self, header_hashes: list[tuple[bytes32]]) -> None: ... | ||
async def set_peak(self, header_hash: bytes32) -> None: ... | ||
async def get_block_records_close_to_peak( | ||
self, blocks_n: int | ||
) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]: ... | ||
async def get_prev_hash(self, header_hash: bytes32) -> bytes32: ... | ||
def transaction(self) -> AbstractAsyncContextManager[Any]: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a good reason to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, right now, the only concrete implementation of this protocol returns a I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it's dumb. The main goal of this PR is to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it almost seems that those things ought to happen in the opposite order. to avoid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to remove the circular dependencies between |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ path = "chia.consensus" | |
depends_on = [ | ||
"chia.types", | ||
"chia.util", | ||
{ path = "chia.full_node", deprecated = false }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
] | ||
|
||
[[modules]] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly for sure, but we can get away with it because we know that
bc
has been populated with aBlockStore
instance here.In future PRs, I expect I will have to rework some tests pretty significantly.