Skip to content

Commit

Permalink
feat(share/eds): introduce List method for the Store (#2494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan authored Aug 2, 2023
1 parent 08ffb69 commit d0e271e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions share/eds/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -409,6 +410,20 @@ func (s *Store) Has(ctx context.Context, root share.DataHash) (bool, error) {
}
}

// List lists all the registered EDSes.
func (s *Store) List() ([]share.DataHash, error) {
shards := s.dgstr.AllShardsInfo()
hashes := make([]share.DataHash, 0, len(shards))
for shrd := range shards {
hash, err := hex.DecodeString(shrd.String())
if err != nil {
return nil, err
}
hashes = append(hashes, hash)
}
return hashes, nil
}

func setupPath(basepath string) error {
err := os.MkdirAll(basepath+blocksPath, os.ModePerm)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions share/eds/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ func TestEDSStore(t *testing.T) {
_, err = edsStore.cache.Get(shardKey)
assert.NoError(t, err, errCacheMiss)
})

t.Run("List", func(t *testing.T) {
const amount = 10
hashes := make([]share.DataHash, 0, amount)
for range make([]byte, amount) {
eds, dah := randomEDS(t)
err = edsStore.Put(ctx, dah.Hash(), eds)
require.NoError(t, err)
hashes = append(hashes, dah.Hash())
}

hashesOut, err := edsStore.List()
require.NoError(t, err)
for _, hash := range hashes {
assert.Contains(t, hashesOut, hash)
}
})
}

// TestEDSStore_GC verifies that unused transient shards are collected by the GC periodically.
Expand Down

0 comments on commit d0e271e

Please sign in to comment.