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

Decode returns an error when failed to reconstruct #200

Open
rootulp opened this issue Jun 28, 2023 · 1 comment
Open

Decode returns an error when failed to reconstruct #200

rootulp opened this issue Jun 28, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@rootulp
Copy link
Collaborator

rootulp commented Jun 28, 2023

Context

If I understand correctly the Codec interface is meant to serve as a boundary between rsmt2d logic and different erasure coding libraries.

Problem

The leopard codec returns an error when it fails to reconstruct all shards

rsmt2d/leopard.go

Lines 52 to 53 in 2557620

err = enc.Reconstruct(data)
return data, err

This leads to janky error handling:

rebuiltShares, err := eds.codec.Decode(shares)
if err != nil {
// Decode was unsuccessful but don't propagate the error because that
// would halt the progress of solveCrosswordRow or solveCrosswordCol.
return nil, false, nil
}

because reconstruction is expected to fail while solving the extended data crossword iteratively. Since the error that is propagated is defined in klauspost/reedsolomon, in order to check if the error is of type ErrTooFewShards, the extendeddatacrossword.go has to import an error type directly from klauspost/reedsolomon. Such an import would leak implementation details that should ideally be contained to the codec interface in codecs.go and the implementation of that interface in leopard.go

Proposal

Option A

Define a new error in codecs.go like rsmt2d.ErrTooFewShards. In leopard.go if a reedsolomon.ErrTooFewShards is observed, return a new rsmt2d.ErrTooFewShards instead.

	// Decode attempts to reconstruct the missing shards in data. The `data`
	// parameter should contain all original + parity shards where missing shards
	// should be `nil`. If reconstruction is successful, the original + parity
	// shards are returned. If reconstruction is unsuccessful, an error is returned.
	Decode(data [][]byte) ([][]byte, error)

Option B

In leopard.go if a reedsolomon.ErrTooFewShards is observed don't propagate it. Instead, return all the shards with missing shards still set to nil.

	// Decode attempts to reconstruct the missing shards in data. The `data`
	// parameter should contain all original + parity shards where missing shards
	// should be `nil`. If reconstruction is successful, the original + parity
	// shards are returned. If reconstruction is unsuccessful, the parameter data 
        // is returned unmodified.
	Decode(data [][]byte) ([][]byte, error)
@rootulp
Copy link
Collaborator Author

rootulp commented Jun 30, 2023

Leaving this issue open b/c I think the error returned by Decode leaks implementation details from klauspost/reedsolomon.

@rootulp rootulp added the enhancement New feature or request label Jul 4, 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

Successfully merging a pull request may close this issue.

1 participant