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

feat: validate namespace in share constructor #87

Merged
merged 20 commits into from
Jun 26, 2024
Merged

Conversation

cmwaters
Copy link
Collaborator

Closes: #86

This PR also addresses the nits from @Rootul's review here

@cmwaters cmwaters requested review from a team as code owners June 21, 2024 09:07
@cmwaters cmwaters requested review from ramin, staheri14 and vgonkivs and removed request for a team June 21, 2024 09:07
@celestia-bot celestia-bot requested review from a team June 21, 2024 09:07
@cmwaters cmwaters marked this pull request as draft June 21, 2024 09:07
@cmwaters cmwaters self-assigned this Jun 21, 2024
Base automatically changed from cal/merge-pkgs to main June 24, 2024 07:33
@cmwaters cmwaters marked this pull request as ready for review June 24, 2024 07:37
@@ -110,6 +94,14 @@ func (n Namespace) ID() []byte {
return n.data[NamespaceVersionSize:]
}

func Validate(version uint8, id []byte) error {
Copy link
Member

Choose a reason for hiding this comment

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

Needs a little godoc.


err = validateID(bytes[VersionIndex], bytes[NamespaceVersionSize:])
if err != nil {
if err := Validate(bytes[VersionIndex], bytes[NamespaceVersionSize:]); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: to avoid confusing byte slicing you could do:

ns := Namespace{data: bytes}
err := Validate(ns.Version(), ns.ID())
if err != nil {
   return Namespace{}, err
}

return ns

Copy link
Member

Choose a reason for hiding this comment

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

Still, I'm not sure why we wouldn't add Validate as a method. (I know it's guaranteed to be valid after the construction but still)

Copy link
Collaborator Author

@cmwaters cmwaters Jun 24, 2024

Choose a reason for hiding this comment

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

It gets used by the share package (which keeps the namespace in bytes form). Maybe we could consider either caching the namespace in the share struct or merging the namespace package with the share package (and thus we can return the namespace without needing to validate it)

Copy link
Member

Choose a reason for hiding this comment

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

:merge-it:

panic(err)
}
return blob
func NewV0Blob(ns ns.Namespace, data []byte) (*Blob, error) {
Copy link
Member

Choose a reason for hiding this comment

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

godoc

@celestia-bot celestia-bot requested review from a team June 25, 2024 07:41
@cmwaters
Copy link
Collaborator Author

I plan to merge the namespace package into the shares package. This will mean that Validate no longer needs to be a public function

Copy link
Member

@ninabarbakadze ninabarbakadze left a comment

Choose a reason for hiding this comment

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

lgtm

@cmwaters cmwaters merged commit 3ac90d6 into main Jun 26, 2024
11 checks passed
@cmwaters cmwaters deleted the cal/validate-namespace branch June 26, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate the namespace in the Share constructor
4 participants