-
Notifications
You must be signed in to change notification settings - Fork 80
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
refactor: simplify rebuildShares
#197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,9 +136,8 @@ func (eds *ExtendedDataSquare) solveCrosswordRow( | |
shares[c] = vectorData[c] | ||
} | ||
|
||
isExtendedPartIncomplete := !eds.rowRangeNoMissingData(uint(r), eds.originalDataWidth, eds.width) | ||
// Attempt rebuild | ||
rebuiltShares, isDecoded, err := eds.rebuildShares(isExtendedPartIncomplete, shares) | ||
rebuiltShares, isDecoded, err := eds.rebuildShares(shares) | ||
if err != nil { | ||
return false, false, err | ||
} | ||
|
@@ -201,9 +200,8 @@ func (eds *ExtendedDataSquare) solveCrosswordCol( | |
|
||
} | ||
|
||
isExtendedPartIncomplete := !eds.colRangeNoMissingData(uint(c), eds.originalDataWidth, eds.width) | ||
// Attempt rebuild | ||
rebuiltShares, isDecoded, err := eds.rebuildShares(isExtendedPartIncomplete, shares) | ||
rebuiltShares, isDecoded, err := eds.rebuildShares(shares) | ||
if err != nil { | ||
return false, false, err | ||
} | ||
|
@@ -249,7 +247,6 @@ func (eds *ExtendedDataSquare) solveCrosswordCol( | |
// 2. Whether the original shares could be decoded from the shares parameter. | ||
// 3. [Optional] an error. | ||
func (eds *ExtendedDataSquare) rebuildShares( | ||
isExtendedPartIncomplete bool, | ||
shares [][]byte, | ||
) ([][]byte, bool, error) { | ||
rebuiltShares, err := eds.codec.Decode(shares) | ||
|
@@ -259,25 +256,6 @@ func (eds *ExtendedDataSquare) rebuildShares( | |
return nil, false, nil | ||
} | ||
|
||
if isExtendedPartIncomplete { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Question] I suppose there have not been any tests associated with this part of the code, as no test file has been updated in this PR, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. codecov claims these lines were covered: https://app.codecov.io/gh/celestiaorg/rsmt2d/blob/master/extendeddatacrossword.go I assume via https://github.com/rootulp/rsmt2d/blob/1f1904acc114b41dff838ad1d530feacc1d9f199/extendeddatacrossword_test.go#L21 |
||
// If needed, rebuild the parity shares too. | ||
rebuiltExtendedShares, err := eds.codec.Encode(rebuiltShares[0:eds.originalDataWidth]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Question] The only potential issue could arise if the parity portion is incomplete and the rebuilt extended shares obtained from In the original code, we initially decode the entire row, and if the extended part (before decoding) is incomplete, we discard that part from the decoded version and replace it with the encoding result. However, in the new version, we retain whatever the decode function provides us with. If we are confident that these two have the same result, then everything looks good to me! (I think they should be the same) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't expect this to happen because Decode calls Reconstruct here and the godoc for Reconstruct claims:
|
||
if err != nil { | ||
return nil, true, err | ||
} | ||
rebuiltShares = append( | ||
rebuiltShares[0:eds.originalDataWidth], | ||
rebuiltExtendedShares..., | ||
) | ||
} else { | ||
// Otherwise copy them from the EDS. | ||
startIndex := len(shares) - int(eds.originalDataWidth) | ||
rebuiltShares = append( | ||
rebuiltShares[0:eds.originalDataWidth], | ||
shares[startIndex:]..., | ||
) | ||
} | ||
|
||
return rebuiltShares, true, nil | ||
} | ||
|
||
|
@@ -427,21 +405,3 @@ func (eds *ExtendedDataSquare) computeSharesRootWithRebuiltShare(shares [][]byte | |
} | ||
return tree.Root() | ||
} | ||
|
||
func (eds *ExtendedDataSquare) rowRangeNoMissingData(r, start, end uint) bool { | ||
for c := start; c <= end && c < eds.width; c++ { | ||
if eds.squareRow[r][c] == nil { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func (eds *ExtendedDataSquare) colRangeNoMissingData(c, start, end uint) bool { | ||
for r := start; r <= end && r < eds.width; r++ { | ||
if eds.squareRow[r][c] == nil { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this function at all if its just decoding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question, I can explore deleting it entirely in a FLUP issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'm only creating a new issue rather than tackling in this PR b/c I don't want to dismiss existing approvals 😞 #199