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

Why rebuild extended shares? #196

Closed
rootulp opened this issue Jun 26, 2023 · 3 comments · Fixed by #197
Closed

Why rebuild extended shares? #196

rootulp opened this issue Jun 26, 2023 · 3 comments · Fixed by #197
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@rootulp
Copy link
Collaborator

rootulp commented Jun 26, 2023

Context

func (eds *ExtendedDataSquare) rebuildShares(
isExtendedPartIncomplete bool,
shares [][]byte,
) ([][]byte, bool, error) {
rebuiltShares, err := eds.codec.Decode(shares)
if err != nil {
// repair unsuccessful
return nil, false, nil
}
if isExtendedPartIncomplete {
// If needed, rebuild the parity shares too.
rebuiltExtendedShares, err := eds.codec.Encode(rebuiltShares[0:eds.originalDataWidth])
if err != nil {
return nil, true, err
}
startIndex := len(rebuiltExtendedShares) - int(eds.originalDataWidth)
rebuiltShares = append(
rebuiltShares[0:eds.originalDataWidth],
rebuiltExtendedShares[startIndex:]...,
)
} 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
}

Question

Given that Decode returns the original shares + parity shares, why does rebuildShares have logic to separately rebuild extended shares? It seems possible to entirely remove the isExtendedPartIncomplete conditional.

@rootulp rootulp added enhancement New feature or request question Further information is requested labels Jun 26, 2023
@rootulp rootulp self-assigned this Jun 26, 2023
@adlerjohn
Copy link
Member

adlerjohn commented Jun 26, 2023

IIRC, Infectious behaves differently and Decode doesn't return all shares. Could you confirm?

The other reason for this is probably refactoring that left redundant code in.

@rootulp
Copy link
Collaborator Author

rootulp commented Jun 26, 2023

Ahh I see, thanks for pointing this out. It appears Infectious Decode did only return the rebuilt shares here.

@adlerjohn
Copy link
Member

This should probably have been originally fixed within the Infectious codec IMO, rather that doubling work for other codecs.

rootulp added a commit that referenced this issue Jun 28, 2023
Closes #196

Since
[`Decode`](https://github.com/rootulp/rsmt2d/blob/1f1904acc114b41dff838ad1d530feacc1d9f199/leopard.go#L46-L54)
returns original + parity shares, there is no need to separately rebuild
the parity shares. This PR removes an unnecessary conditional inside
`rebuildShares` which let us also remove a param to that function. After
the refactor, a few helper methods were no longer used so they were also
removed.
0xchainlover pushed a commit to celestia-org/rsmt2d that referenced this issue Aug 1, 2024
Closes celestiaorg/rsmt2d#196

Since
[`Decode`](https://github.com/rootulp/rsmt2d/blob/1f1904acc114b41dff838ad1d530feacc1d9f199/leopard.go#L46-L54)
returns original + parity shares, there is no need to separately rebuild
the parity shares. This PR removes an unnecessary conditional inside
`rebuildShares` which let us also remove a param to that function. After
the refactor, a few helper methods were no longer used so they were also
removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants