-
Notifications
You must be signed in to change notification settings - Fork 969
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
feat(shwap): Add ODS file #3482
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
735ba7d
add ods file
walldiss 47141b8
various fixes + applied review suggestion
walldiss b289c2d
fix lint
walldiss 1868dd8
fix old linter
walldiss 4d7810d
apply review suggestions
walldiss ce65121
small tests refactoring
walldiss faffbc2
improve comments
walldiss 2a1ab4c
fix lint
walldiss 4eb12ad
fix lint
walldiss d11413c
improve after review 2
walldiss 221d8d3
remove todo
walldiss 60670d7
fix naming
walldiss 951440e
fix review suggestions
walldiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package eds | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/celestiaorg/celestia-node/share/sharetest" | ||
) | ||
|
||
func TestExtendAxisHalf(t *testing.T) { | ||
shares := sharetest.RandShares(t, 16) | ||
|
||
original := AxisHalf{ | ||
Shares: shares, | ||
IsParity: false, | ||
} | ||
|
||
extended, err := original.Extended() | ||
require.NoError(t, err) | ||
require.Len(t, extended, len(shares)*2) | ||
|
||
parity := AxisHalf{ | ||
Shares: extended[len(shares):], | ||
IsParity: true, | ||
} | ||
|
||
parityExtended, err := parity.Extended() | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, extended, parityExtended) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,10 +164,14 @@ func (rnd RowNamespaceData) Validate(dah *share.Root, namespace share.Namespace, | |
// verifyInclusion checks the inclusion of the row's shares in the provided root using NMT. | ||
func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Namespace) bool { | ||
leaves := make([][]byte, 0, len(rnd.Shares)) | ||
for _, shr := range rnd.Shares { | ||
namespaceBytes := share.GetNamespace(shr) | ||
leaves = append(leaves, append(namespaceBytes, shr...)) | ||
for _, sh := range rnd.Shares { | ||
namespaceBytes := share.GetNamespace(sh) | ||
leave := make([]byte, len(sh)+len(namespaceBytes)) | ||
copy(leave, namespaceBytes) | ||
copy(leave[len(namespaceBytes):], sh) | ||
leaves = append(leaves, leave) | ||
Comment on lines
+168
to
+172
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. Is this a refactoring from appends to copies? 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 like that you noticed. There was a very nasty mutations bug that took me few hours to fix. |
||
} | ||
|
||
return rnd.Proof.VerifyNamespace( | ||
share.NewSHA256Hasher(), | ||
namespace.ToNMT(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package file | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/klauspost/reedsolomon" | ||
) | ||
|
||
var codec Codec | ||
Wondertan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func init() { | ||
codec = NewCodec() | ||
} | ||
|
||
type Codec interface { | ||
Encoder(len int) (reedsolomon.Encoder, error) | ||
} | ||
|
||
type codecCache struct { | ||
cache sync.Map | ||
} | ||
|
||
func NewCodec() Codec { | ||
return &codecCache{} | ||
} | ||
|
||
func (l *codecCache) Encoder(len int) (reedsolomon.Encoder, error) { | ||
enc, ok := l.cache.Load(len) | ||
if !ok { | ||
var err error | ||
enc, err = reedsolomon.New(len/2, len/2, reedsolomon.WithLeopardGF(true)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
l.cache.Store(len, enc) | ||
} | ||
return enc.(reedsolomon.Encoder), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package file | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/klauspost/reedsolomon" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/celestiaorg/celestia-node/share/sharetest" | ||
) | ||
|
||
func BenchmarkCodec(b *testing.B) { | ||
minSize, maxSize := 32, 128 | ||
|
||
for size := minSize; size <= maxSize; size *= 2 { | ||
walldiss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// BenchmarkCodec/Leopard/size:32-10 409194 2793 ns/op | ||
// BenchmarkCodec/Leopard/size:64-10 190969 6170 ns/op | ||
// BenchmarkCodec/Leopard/size:128-10 82821 14287 ns/op | ||
b.Run(fmt.Sprintf("Leopard/size:%v", size), func(b *testing.B) { | ||
enc, err := reedsolomon.New(size/2, size/2, reedsolomon.WithLeopardGF(true)) | ||
require.NoError(b, err) | ||
|
||
shards := newShards(b, size, true) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
err = enc.Encode(shards) | ||
require.NoError(b, err) | ||
} | ||
}) | ||
|
||
// BenchmarkCodec/default/size:32-10 222153 5364 ns/op | ||
// BenchmarkCodec/default/size:64-10 58831 20349 ns/op | ||
// BenchmarkCodec/default/size:128-10 14940 80471 ns/op | ||
b.Run(fmt.Sprintf("default/size:%v", size), func(b *testing.B) { | ||
enc, err := reedsolomon.New(size/2, size/2, reedsolomon.WithLeopardGF(false)) | ||
require.NoError(b, err) | ||
|
||
shards := newShards(b, size, true) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
err = enc.Encode(shards) | ||
require.NoError(b, err) | ||
} | ||
}) | ||
|
||
// BenchmarkCodec/default-reconstructSome/size:32-10 1263585 954.4 ns/op | ||
// BenchmarkCodec/default-reconstructSome/size:64-10 762273 1554 ns/op | ||
// BenchmarkCodec/default-reconstructSome/size:128-10 429268 2974 ns/op | ||
b.Run(fmt.Sprintf("default-reconstructSome/size:%v", size), func(b *testing.B) { | ||
enc, err := reedsolomon.New(size/2, size/2, reedsolomon.WithLeopardGF(false)) | ||
require.NoError(b, err) | ||
|
||
shards := newShards(b, size, false) | ||
targets := make([]bool, size) | ||
target := size - 2 | ||
targets[target] = true | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
err = enc.ReconstructSome(shards, targets) | ||
require.NoError(b, err) | ||
shards[target] = nil | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func newShards(b require.TestingT, size int, fillParity bool) [][]byte { | ||
shards := make([][]byte, size) | ||
original := sharetest.RandShares(b, size/2) | ||
copy(shards, original) | ||
|
||
if fillParity { | ||
// fill with parity empty Shares | ||
for j := len(original); j < len(shards); j++ { | ||
shards[j] = make([]byte, len(original[0])) | ||
} | ||
} | ||
return shards | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Feels like there is an optimization opportunity to avoid copying that we can return to later
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.
Need to prealloc shares anyway, so copying is necessary. Can do implicitly by append tho