Skip to content
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

BlockchainInterface as a protocol #18486

Merged
merged 3 commits into from
Aug 22, 2024
Merged

BlockchainInterface as a protocol #18486

merged 3 commits into from
Aug 22, 2024

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Aug 18, 2024

This PR is best reviewed one commit at a time.

Purpose:

Prepare for adding a new implementation of BlockchainInterface by:

  • turn BlockchainInterface into a Protocol and fix-up BlockCache and WalletBlockchain. This enables mypy to check these classes and fail if they don't implement the protocol.
  • Split out a small subset of BlockchainInterface into its own protocol, BlockRecordsProtocol. BlockchainInterface subsumes it. Most functions that take a BlockchainInterface today really only need the, simpler, BlockRecordsProtocol. So transition some function calls to take it instead.
  • Break out a class BlockchainMock (essentially the same as BlockCache) that implements BlockchainInterface and simplify BlockCache to only implement BlockRecordsProtocol. This moves a large amount of code out from production to testing utilities. The main use case of the BlockchainInterface is in tests where we mock the blockchain class.

Current Behavior:

  • BlockchainInterface is of questionable value and does not help type checking.
  • Most functions that take the BlockchainInterface don't need most of its complexity.
  • most of the functionality of BlockCache is for the benefit of a few tests.

New Behavior:

  • BlockchainInterface is a python protocol, which subsumes (a simpler) BlockRecordsProtocol which most of production code uses.
  • BlockCache is simple and only supports what the production code requires (implementing BlockRecordInterface).
  • A new test class (BlockchainMock) implements the test functionality that previously was covered by BlockCache

Testing Notes:

@arvidn arvidn added the Changed Required label for PR that categorizes merge commit message as "Changed" for changelog label Aug 18, 2024
Copy link

coveralls-official bot commented Aug 18, 2024

Pull Request Test Coverage Report for Build 10468518822

Details

  • 165 of 189 (87.3%) changed or added relevant lines in 19 files are covered.
  • 33 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.003%) to 90.826%

Changes Missing Coverage Covered Lines Changed/Added Lines %
chia/_tests/util/blockchain_mock.py 69 80 86.25%
chia/wallet/wallet_blockchain.py 17 30 56.67%
Files with Coverage Reduction New Missed Lines %
chia/full_node/full_node.py 1 86.06%
chia/daemon/server.py 1 83.25%
chia/wallet/util/wallet_sync_utils.py 2 86.06%
chia/full_node/weight_proof.py 2 90.35%
chia/server/node_discovery.py 2 78.9%
chia/server/server.py 2 82.21%
chia/server/ws_connection.py 2 88.69%
chia/rpc/rpc_server.py 3 87.83%
chia/wallet/wallet_node.py 7 88.22%
chia/timelord/timelord.py 11 80.49%
Totals Coverage Status
Change from base Build 10461877247: -0.003%
Covered Lines: 101359
Relevant Lines: 111569

💛 - Coveralls

@arvidn arvidn requested a review from altendky August 19, 2024 10:29
@arvidn arvidn marked this pull request as ready for review August 19, 2024 10:30
@arvidn arvidn requested a review from a team as a code owner August 19, 2024 10:30
@arvidn
Copy link
Contributor Author

arvidn commented Aug 19, 2024

I'm not sure what to do about the test coverage.

  1. the BlockchainMock class (formerly BlockCache) has never had unit tests. Now it's also a pure test utility itself.
  2. The WalletBlockchain probably doesn't need to implement everything in BlockchainInterface, but the work to tease that a part to remove some of these unused functions is a bit of a rabbit hole (and a distraction from the goal I'm working towards)

chia/consensus/blockchain.py Show resolved Hide resolved
chia/consensus/blockchain.py Show resolved Hide resolved
chia/consensus/blockchain_interface.py Outdated Show resolved Hide resolved
chia/consensus/blockchain_interface.py Outdated Show resolved Hide resolved
chia/util/block_cache.py Outdated Show resolved Hide resolved
chia/util/block_cache.py Outdated Show resolved Hide resolved
Copy link
Contributor

File Coverage Missing Lines
chia/_tests/util/blockchain_mock.py 86.2% lines 43, 46, 73, 79, 97-100, 103, 106, 128
chia/wallet/wallet_blockchain.py 56.7% lines 216, 222, 225, 228, 231, 236, 239, 242, 248, 251-253, 258
Total Missing Coverage
189 lines 24 lines 87%

Copy link
Contributor

@wjblanke wjblanke left a comment

Choose a reason for hiding this comment

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

aok

@arvidn arvidn added the ready_to_merge Submitter and reviewers think this is ready label Aug 22, 2024
@pmaslana pmaslana merged commit 700a673 into main Aug 22, 2024
374 of 375 checks passed
@pmaslana pmaslana deleted the blockchain-interface branch August 22, 2024 17:02
@altendky altendky mentioned this pull request Sep 3, 2024
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 ready_to_merge Submitter and reviewers think this is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants