-
Notifications
You must be signed in to change notification settings - Fork 2k
Roll CoinStore
, BlockStore
and BlockHeightMap
into ConsensusStore
#19949
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?
Conversation
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.
Pull Request Overview
This PR creates a new ConsensusStore
class that combines CoinStore
, BlockStore
, and BlockHeightMap
into a unified interface to reduce dependencies between chia.full_node
and chia.consensus
modules. This refactoring prepares for future RocksDB integration by consolidating consensus-related storage operations.
Key changes:
- Introduces
ConsensusStore
andConsensusStoreProtocol
to wrap existing storage components - Updates
Blockchain
constructor to accept a singleConsensusStore
instead of separate stores - Modifies all test files and utilities to use the new consolidated store pattern
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
chia/full_node/full_node.py | Updates to create and use ConsensusStore instead of passing individual stores |
chia/consensus/consensus_store_protocol.py | New protocol defining the unified interface for consensus storage operations |
chia/consensus/consensus_store.py | Implementation of ConsensusStore that delegates to underlying stores |
chia/consensus/blockchain.py | Major refactoring to use ConsensusStore instead of individual store references |
chia/_tests/util/blockchain.py | Test utility updated to use new store pattern |
chia/_tests/core/test_db_validation.py | Test updated to create and use ConsensusStore |
chia/_tests/core/test_db_conversion.py | Test updated to create and use ConsensusStore |
chia/_tests/core/full_node/stores/test_coin_store.py | Test updated to create and use ConsensusStore |
chia/_tests/core/full_node/stores/test_block_store.py | Test updated to create and use ConsensusStore |
chia/_tests/core/full_node/ram_db.py | Test utility updated to use new store pattern |
benchmarks/block_ref.py | Benchmark updated to use new store pattern |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -266,12 +267,11 @@ async def manage(self) -> AsyncIterator[None]: | |||
multiprocessing_start_method = process_config_start_method(config=self.config, log=self.log) | |||
self.multiprocessing_context = multiprocessing.get_context(method=multiprocessing_start_method) | |||
selected_network = self.config.get("selected_network") | |||
height_map = await BlockHeightMap.create(self.db_path.parent, self._db_wrapper, selected_network) | |||
height_map = await BlockHeightMap.create(self.db_path.parent, self.db_wrapper, selected_network) |
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.
The attribute reference has been changed from self._db_wrapper
to self.db_wrapper
, but this may be incorrect if the class uses a private attribute naming convention. Verify that self.db_wrapper
is the correct public attribute name.
height_map = await BlockHeightMap.create(self.db_path.parent, self.db_wrapper, selected_network) | |
height_map = await BlockHeightMap.create(self.db_path.parent, self._db_wrapper, selected_network) |
Copilot uses AI. Check for mistakes.
39decfe
to
22f5bcb
Compare
a832787
to
8bf99bf
Compare
8bf99bf
to
7bac71d
Compare
@@ -157,7 +157,7 @@ class FullNode: | |||
_db_wrapper: Optional[DBWrapper2] = None | |||
_hint_store: Optional[HintStore] = None | |||
_block_store: Optional[BlockStore] = None | |||
_coin_store: Optional[CoinStoreProtocol] = None | |||
_coin_store: Optional[CoinStore] = None |
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.
does this need to be getting more specific?
the consensus-related data in the blockchain. | ||
""" | ||
|
||
# Block store methods |
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.
ending up grouping these with comments makes me wonder if it would be useful to just allow access to the attributes directly instead of requiring wrapper methods. presumably the coin/height map/blockstore would have their own satisfactory protocols instead of concrete types.
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.
My goal is to get rid of these other protocols. All they do is leak implementation details. The user of a ConsensusStore
wants to do some puts and gets, and wants to be able to do sequences of atomic writes (and maybe sequences of consistent reads). It shouldn't much care how or where the data is stored as long as it's not too slow.
|
||
|
||
@dataclasses.dataclass | ||
class ConsensusStoreSQLite3(ConsensusStoreProtocol): |
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.
generally don't inherit protocols when implementing them. here's our existing pattern for expressing that a given protocol is intended to be implemented and for making an explicit mypy check against it that provides a clear explanation of deviations in more cases than other options do.
chia-blockchain/chia/full_node/full_node.py
Lines 118 to 124 in 8539ae8
@final | |
@dataclasses.dataclass | |
class FullNode: | |
if TYPE_CHECKING: | |
from chia.rpc.rpc_server import RpcServiceProtocol | |
_protocol_check: ClassVar[RpcServiceProtocol] = cast("FullNode", None) |
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.
Not a big fan of this pattern, although I see the value of having the error be closer to the source. I asked ChatGPT and it came up with
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from my_protocols import RpcServiceProtocol
from typing import assert_type # or use reveal_type
def _assert_protocol(x: RpcServiceProtocol) -> None: ...
_assert_protocol(FullNode()) # mypy will check this
I like this a little better because at least it doesn't pollute the class, and it can be put at the end of the file. So I may try that.
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.
does that provide the clear output that my suggestion does? i didn't pick it because i liked the form. i picked it because of all the options it was the most useful (and i haven't gotten back to trying to get my PR improving mypy output done).
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.
how about this, we can revisit this pattern but let's keep this pr granular instead of having it start introducing replacement hinting practices to be debated?
the consensus-related data in the blockchain. | ||
""" | ||
|
||
def transaction(self) -> AbstractAsyncContextManager[Any]: ... |
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.
-1
Two purposes:
chia.full_node
fromchia.consensus
Towards RocksDB brain transplant.