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
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion chia/consensus/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,12 @@ async def lookup_block_generators(self, header_hash: bytes32, generator_refs: Se
# need to find the fork point
peak_block = await self.get_block_record_from_db(header_hash)
assert peak_block is not None
if self.height_to_hash(peak_block.height) != header_hash:
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.

log.info(f"No header hash found for height {peak_block.height}. We must be on a fork.")
if height_hash != header_hash: # we are on a fork
peak: Optional[BlockRecord] = self.get_peak()
assert peak is not None
reorg_chain: Dict[uint32, bytes32]
Expand Down
Loading