Skip to content

Commit

Permalink
fix: end exclusive data commitment range fix (#1058) (#1060)
Browse files Browse the repository at this point in the history
## Description

Cherry pick #1058 to
main

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

## Description

_Please add a description of the changes that this PR introduces and the
files that
are the most critical to review._ 

If this PR is non-trivial/large/complex, please ensure that you have
either
created an issue that the team's had a chance to respond to, or had some
discussion with the team prior to submitting substantial pull requests.
The team
can be reached via GitHub Discussions or the Cosmos Network Discord
server in
the #cometbft channel. GitHub Discussions is preferred over Discord as
it
allows us to keep track of conversations topically.
https://github.com/cometbft/cometbft/discussions

If the work in this PR is not aligned with the team's current
priorities, please
be advised that it may take some time before it is merged - especially
if it has
not yet been discussed with the team.

See the project board for the team's current priorities:
https://github.com/orgs/cometbft/projects/1

-->

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

Co-authored-by: Rootul P <rootulp@gmail.com>
  • Loading branch information
rach-id and rootulp committed Aug 11, 2023
1 parent d02553f commit c695476
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions rpc/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,10 @@ func validateDataCommitmentRange(start uint64, end uint64) error {
if start >= end {
return fmt.Errorf("last block is smaller than first block")
}
if end > uint64(env.BlockStore.Height()) {
// the data commitment range is end exclusive
if end > uint64(env.BlockStore.Height())+1 {
return fmt.Errorf(
"last block %d is higher than current chain height %d",
"end block %d is higher than current chain height %d",
end,
env.BlockStore.Height(),
)
Expand Down
11 changes: 8 additions & 3 deletions rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func TestDataCommitmentResults(t *testing.T) {
{0, 1000, false},
{0, 10, false},
{10, 8, false},
// to test the end exclusive support for ranges.
// the end block could be equal to (height+1), but the data commitment would only
// take up to height. So we should be able to send request having end block equal
// to (height+1).
{int(env.BlockStore.Height()) - 100, int(env.BlockStore.Height()) + 1, true},
}

for i, tc := range testCases {
Expand Down Expand Up @@ -334,10 +339,10 @@ func (indexer mockBlockIndexer) Search(ctx context.Context, _ *query.Query) ([]i
return results, nil
}

// randomBlocks generates a set of random blocks up to the provided height.
// randomBlocks generates a set of random blocks up to (and including) the provided height.
func randomBlocks(height int64) []*types.Block {
blocks := make([]*types.Block, height)
for i := int64(0); i < height; i++ {
blocks := make([]*types.Block, height+1)
for i := int64(0); i <= height; i++ {
blocks[i] = randomBlock(i)
}
return blocks
Expand Down

0 comments on commit c695476

Please sign in to comment.