Skip to content

Commit

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

Fixes celestiaorg/orchestrator-relayer#432

#### 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 authored Aug 10, 2023
1 parent 61fb662 commit 819b969
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 @@ -318,9 +318,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 @@ -333,10 +338,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 819b969

Please sign in to comment.