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

Consider refactoring Share type #1443

Closed
rootulp opened this issue Mar 3, 2023 · 1 comment
Closed

Consider refactoring Share type #1443

rootulp opened this issue Mar 3, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@rootulp
Copy link
Collaborator

rootulp commented Mar 3, 2023

Context

// Share contains the raw share data (including namespace ID).
type Share []byte
func NewShare(data []byte) (Share, error) {
if len(data) != appconsts.ShareSize {
return nil, fmt.Errorf("share data must be %d bytes, got %d", appconsts.ShareSize, len(data))
}
return Share(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.

@rootulp rootulp added the enhancement New feature or request label Mar 3, 2023
@mojtaba-esk mojtaba-esk self-assigned this Mar 3, 2023
mojtaba-esk added a commit that referenced this issue Mar 16, 2023
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>
@rootulp rootulp added this to the Mainnet milestone Mar 30, 2023
@rootulp
Copy link
Collaborator Author

rootulp commented Apr 11, 2023

@mojtaba-esk was this closed by #1462?

@rootulp rootulp closed this as completed May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants