Skip to content

Conversation

DracoLi
Copy link
Contributor

@DracoLi DracoLi commented Sep 26, 2025

Why this should be merged

Fix the behaviour of HasBlock in x/blockdb. Currently if request a block below the min height of the database or a large block height that is not supported by the index file, then it returns an ErrInvalidBlockHeight error. Instead, we should just return false with no error as that makes more sense.

How this works

Treat both ErrInvalidBlockHeight and ErrBlockNotFound as expected errors for HasBlock

How this was tested

Add unit tests for HasBlock behaviour

Need to be documented in RELEASES.md?

@DracoLi DracoLi marked this pull request as ready for review September 26, 2025 16:20
@Copilot Copilot AI review requested due to automatic review settings September 26, 2025 16:20
Copy link
Contributor

@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 fixes the HasBlock method in the blockdb package to return false instead of an error when checking for blocks below the minimum height or above the maximum supported height. This change makes the API behavior more intuitive by treating out-of-range block heights as simply "not having" the block rather than throwing an error.

  • Modified HasBlock to treat ErrInvalidBlockHeight the same as ErrBlockNotFound
  • Added comprehensive unit tests covering edge cases including minimum height, maximum height, and missing blocks

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
x/blockdb/database.go Updated HasBlock to handle invalid block heights as missing blocks
x/blockdb/readblock_test.go Added comprehensive test cases for HasBlock behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@DracoLi DracoLi changed the title fix: blockdb has block don't error if below min height fix: blockdb has block don't error if invalid block height Sep 26, 2025
@DracoLi DracoLi requested review from a team and yacovm and removed request for a team September 26, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants