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

feat(store/mem_file): add in-memory eds file implementation #2992

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

walldiss
Copy link
Member

@walldiss walldiss commented Dec 6, 2023

Adds in-memory file implementation

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (protocol_v2@e6d39dc). Click here to learn what that means.

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.
📢 Have feedback on the report? Share it here.

@@ -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) {
Copy link
Member

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.

Suggested change
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) {

Comment on lines +56 to +81
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
}
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later

Comment on lines +92 to +101
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")
}
}
Copy link
Member

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

Copy link
Member

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)
Copy link
Member

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

Comment on lines 59 to 73
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
}
Copy link
Member

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

Copy link
Member Author

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
@walldiss walldiss merged commit 82150f2 into celestiaorg:protocol_v2 Dec 6, 2023
14 of 17 checks passed
walldiss added a commit that referenced this pull request May 8, 2024
walldiss added a commit that referenced this pull request Jun 10, 2024
walldiss added a commit that referenced this pull request Jun 10, 2024
walldiss added a commit to walldiss/celestia-node that referenced this pull request Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants