Skip to content

Catch assertion error in height_to_hash() #18667

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 3 commits into
base: main
Choose a base branch
from

Conversation

matt-o-how
Copy link
Contributor

Purpose:

Currently get_hash() in block_height_map.py has an assert which can fail and is not caught in the calling height_to_hash() function in blockchain.py.
In this case we should treat it as though we are on a fork that is further ahead than us.

This PR adds in try except condition, a default value, and a log for when this case is hit.

Current Behavior:

Raises the exception.

New Behavior:

Catches, logs and proceeds

@matt-o-how matt-o-how added the Fixed Required label for PR that categorizes merge commit message as "Fixed" for changelog label Oct 3, 2024
height_hash: Optional[bytes32] = None
try:
height_hash = self.height_to_hash(peak_block.height)
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems risky to catch (and ignore) all exceptions. This would include assertion failures.
I think it would be more precise to either check if the current chain has the block height we're about to look up.

Copy link
Contributor

github-actions bot commented Oct 7, 2024

File Coverage Missing Lines
chia/consensus/blockchain.py 66.7% lines 1074-1075
Total Missing Coverage
6 lines 2 lines 66%

@arvidn
Copy link
Contributor

arvidn commented Oct 15, 2024

now that we've realized that height_to_hash() returns None rather than raise an exception, I don't think we need this patch anymore

Copy link
Contributor

This PR has been flagged as stale due to no activity for over 60 days. It will not be automatically closed, but it has been given a stale-pr label and should be manually reviewed by the relevant parties.

@github-actions github-actions bot added the stale-pr Flagged as stale and in need of manual review label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coverage-diff Fixed Required label for PR that categorizes merge commit message as "Fixed" for changelog stale-pr Flagged as stale and in need of manual review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants