-
Notifications
You must be signed in to change notification settings - Fork 920
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(store/mem_file): add in-memory eds file implementation #2992
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## protocol_v2 #2992 +/- ##
==============================================
Coverage ? 50.98%
==============================================
Files ? 169
Lines ? 11078
Branches ? 0
==============================================
Hits ? 5648
Misses ? 4919
Partials ? 511 ☔ View full report in Codecov by Sentry. |
@@ -73,15 +73,15 @@ func (ns NamespacedShares) Verify(root *Root, namespace Namespace) error { | |||
|
|||
for i, row := range ns { | |||
// verify row data against row hash from original root | |||
if !row.verify(originalRoots[i], namespace) { | |||
if !row.Verify(originalRoots[i], namespace) { |
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.
A minor change from local changes. It makes sure we don't segfault when proof is malformed.
if !row.Verify(originalRoots[i], namespace) { | |
if row.Proof == nil && row.Shares == nil { | |
return fmt.Errorf("row verification failed: no proofs and shares") | |
} | |
if !row.Verify(originalRoots[i], namespace) { |
bserv := ipld.NewMemBlockservice() | ||
batchAdder := ipld.NewNmtNodeAdder(context.TODO(), bserv, ipld.MaxSizeBatchOption(len(shares))) | ||
tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(rowIdx), | ||
nmt.NodeVisitor(batchAdder.Visit)) | ||
for _, shr := range shares { | ||
err := tree.Push(shr) | ||
if err != nil { | ||
return share.NamespacedRow{}, err | ||
} | ||
} | ||
|
||
root, err := tree.Root() | ||
if err != nil { | ||
return share.NamespacedRow{}, err | ||
} | ||
|
||
err = batchAdder.Commit() | ||
if err != nil { | ||
return share.NamespacedRow{}, err | ||
} | ||
|
||
cid := ipld.MustCidFromNamespacedSha256(root) | ||
row, proof, err := ipld.GetSharesByNamespace(context.TODO(), bserv, cid, namespace, len(shares)) | ||
if err != nil { | ||
return share.NamespacedRow{}, err | ||
} |
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.
We might want to dedup this 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.
Later
func (f *MemFile) axis(axisType rsmt2d.Axis, axisIdx int) []share.Share { | ||
switch axisType { | ||
case rsmt2d.Row: | ||
return f.Eds.Row(uint(axisIdx)) | ||
case rsmt2d.Col: | ||
return f.Eds.Col(uint(axisIdx)) | ||
default: | ||
panic("unknown axis") | ||
} | ||
} |
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.
I want this to be an rsmt2d method so bad
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.
(no actionable here)
) | ||
|
||
func TestMemFileShare(t *testing.T) { | ||
eds := edstest.RandEDS(t, 32) |
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.
kind big for the test but doesn't really matter
share/store/mem_file_test.go
Outdated
rand := mrand.New(mrand.NewSource(time.Now().UnixNano())) | ||
|
||
// choose random range in shares slice and set namespace to be the same for all shares in range | ||
from := rand.Intn(size * size) | ||
to := rand.Intn(size * size) | ||
if to < from { | ||
from, to = to, from | ||
} | ||
expected := shares[from] | ||
namespace := share.GetNamespace(expected) | ||
|
||
// change namespace for all shares in range | ||
for i := from; i <= to; i++ { | ||
shares[i] = expected | ||
} |
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.
I would leave a todo to make this a helper. I have tests where I need something similar
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.
I've extracted it to test pkg in last commit for you 🙂
- extract namespace data test function
Adds in-memory file implementation
Adds in-memory file implementation
Adds in-memory file implementation
…org#2992) Adds in-memory file implementation
Adds in-memory file implementation