You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Share contains the raw share data (including namespace ID).
typeShare []byte
funcNewShare(data []byte) (Share, error) {
iflen(data) !=appconsts.ShareSize {
returnnil, fmt.Errorf("share data must be %d bytes, got %d", appconsts.ShareSize, len(data))
}
returnShare(data), nil
}
Problem
Currently Share is a byte slice. Since the byte slice doesn't guarantee a length, methods like share.NamespaceID() and share.InfoByte() must perform checks on the length of the byte slice prior to returning information. In other words, since the byte slice can't enforce invariants like len(share) == appconsts.ShareSize, all methods that deal with shares must do additional error handling.
Proposal
We may be able to refactor the Share type to be a struct that enforces invariants (e.g. share length). On a related note, we may be able to leverage a builder pattern to encapsulate the logic for constructing shares. Currently a large portion of the share package must operate on byte slices so when we make changes to the share format, several files need to be updated. We could constrain these modifications to a single file (i.e. share.go) if the Share type didn't expose direct byte manipulation to external callers.
The text was updated successfully, but these errors were encountered:
context in the issue #1443
<!--
Please read and fill out this form before submitting your PR.
Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->
## Overview
<!--
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue.
-->
## Checklist
<!--
Please complete the checklist to ensure that the PR is ready to be
reviewed.
IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->
- [ ] New and updated code has appropriate documentation
- [ ] New and updated code has new and/or updated testing
- [ ] Required CI checks are passing
- [ ] Visual proof for any user facing features like CLI or
documentation updates
- [ ] Linked issues closed with keywords
---------
Co-authored-by: Rootul P <rootulp@gmail.com>
Context
celestia-app/pkg/shares/shares.go
Lines 11 to 19 in e6bbc30
Problem
Currently
Share
is a byte slice. Since the byte slice doesn't guarantee a length, methods likeshare.NamespaceID()
andshare.InfoByte()
must perform checks on the length of the byte slice prior to returning information. In other words, since the byte slice can't enforce invariants likelen(share) == appconsts.ShareSize
, all methods that deal with shares must do additional error handling.Proposal
We may be able to refactor the
Share
type to be a struct that enforces invariants (e.g. share length). On a related note, we may be able to leverage a builder pattern to encapsulate the logic for constructing shares. Currently a large portion of the share package must operate on byte slices so when we make changes to the share format, several files need to be updated. We could constrain these modifications to a single file (i.e.share.go
) if theShare
type didn't expose direct byte manipulation to external callers.The text was updated successfully, but these errors were encountered: