Skip to content
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

fix: end exclusive data commitment range fix (#1058) #1060

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
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
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
Loading