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

chore!: check newChunk size #172

Merged
merged 5 commits into from
Jun 26, 2023
Merged

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Jun 19, 2023

Closes #170
Closes #127

Breaking b/c modifies the function signature of a public function: SetCell

@rootulp rootulp requested a review from evan-forbes June 19, 2023 16:57
@rootulp rootulp self-assigned this Jun 19, 2023
@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #172 (7d0b2ac) into master (36829ac) will increase coverage by 0.21%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #172      +/-   ##
==========================================
+ Coverage   81.00%   81.22%   +0.21%     
==========================================
  Files           7        7              
  Lines         516      522       +6     
==========================================
+ Hits          418      424       +6     
  Misses         58       58              
  Partials       40       40              
Impacted Files Coverage Δ
datasquare.go 93.93% <100.00%> (+0.22%) ⬆️

evan-forbes
evan-forbes previously approved these changes Jun 20, 2023
Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only one fix is needed for the tests.

datasquare_test.go Outdated Show resolved Hide resolved
datasquare_test.go Outdated Show resolved Hide resolved
datasquare_test.go Outdated Show resolved Hide resolved
@rootulp rootulp requested review from staheri14 and evan-forbes and removed request for adlerjohn June 23, 2023 18:24
@rootulp
Copy link
Collaborator Author

rootulp commented Jun 23, 2023

I just noticed #127 so tagging @Wondertan for review

@rootulp rootulp requested a review from Wondertan June 23, 2023 19:00
@rootulp rootulp marked this pull request as draft June 23, 2023 19:02
@rootulp
Copy link
Collaborator Author

rootulp commented Jun 23, 2023

Based on #127 (comment) we may not want to return an error here b/c that's not ergonomic for celestia-node. Open to alternatives

Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Wondertan
Copy link
Member

@rootulp, returning an error is ok. This PR closes the #127

I forgot to use permalinks in the issue🤦🏻

Comment on lines +289 to +308
// SetCell sets a specific cell. The cell to set must be `nil`. Returns an error
// if the cell to set is not `nil` or newChunk is not the correct size.
func (ds *dataSquare) SetCell(x uint, y uint, newChunk []byte) error {
if ds.squareRow[x][y] != nil {
panic(fmt.Sprintf("cannot set cell (%d, %d) as it already has a value %x", x, y, ds.squareRow[x][y]))
return fmt.Errorf("cannot set cell (%d, %d) as it already has a value %x", x, y, ds.squareRow[x][y])
}
if len(newChunk) != int(ds.chunkSize) {
return fmt.Errorf("cannot set cell with chunk size %d because dataSquare chunk size is %d", len(newChunk), ds.chunkSize)
}
ds.squareRow[x][y] = newChunk
ds.squareCol[y][x] = newChunk
ds.resetRoots()
return nil
}

// setCell sets a specific cell.
func (ds *dataSquare) setCell(x uint, y uint, newChunk []byte) {
// setCell sets a specific cell. setCell will overwrite any existing value.
// Returns an error if the newChunk is not the correct size.
func (ds *dataSquare) setCell(x uint, y uint, newChunk []byte) error {
if len(newChunk) != int(ds.chunkSize) {
return fmt.Errorf("cannot set cell with chunk size %d because dataSquare chunk size is %d", len(newChunk), ds.chunkSize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for having two setters? I don't remember

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is the exported SetCell shouldn't have access to overwrite populated cells but the internal setCell should 🤷‍♂️

@rootulp rootulp marked this pull request as ready for review June 23, 2023 23:18
@rootulp rootulp merged commit 9df814c into celestiaorg:master Jun 26, 2023
@rootulp rootulp deleted the rp/check-chunk-size branch June 30, 2023 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check chunk size Issue with panic in SetCell
4 participants