Skip to content

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

richardkiss
Copy link
Contributor

Two purposes:

  • remove the dependency of chia.full_node from chia.consensus
  • prep for modifying full node code to separate out consensus concerns from block archive storage and "coin explorer" functionality

Towards RocksDB brain transplant.

@richardkiss richardkiss requested a review from a team as a code owner August 12, 2025 23:49
@richardkiss richardkiss marked this pull request as draft August 12, 2025 23:49
@richardkiss richardkiss requested a review from Copilot August 12, 2025 23:49
Copy link

@Copilot Copilot AI left a 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 and ConsensusStoreProtocol to wrap existing storage components
  • Updates Blockchain constructor to accept a single ConsensusStore 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)
Copy link
Preview

Copilot AI Aug 12, 2025

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.

Suggested change
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.

@richardkiss richardkiss force-pushed the consensus_store branch 2 times, most recently from 39decfe to 22f5bcb Compare August 13, 2025 22:10
@richardkiss richardkiss added the Changed Required label for PR that categorizes merge commit message as "Changed" for changelog label Aug 13, 2025
@richardkiss richardkiss force-pushed the consensus_store branch 3 times, most recently from a832787 to 8bf99bf Compare August 13, 2025 22:24
@@ -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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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):
Copy link
Contributor

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.

@final
@dataclasses.dataclass
class FullNode:
if TYPE_CHECKING:
from chia.rpc.rpc_server import RpcServiceProtocol
_protocol_check: ClassVar[RpcServiceProtocol] = cast("FullNode", None)

Copy link
Contributor Author

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.

Copy link
Contributor

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).

Copy link
Contributor

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]: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changed Required label for PR that categorizes merge commit message as "Changed" for changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants