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

!refactor: rename GetSharesByNamespace to GetNamespaceData #3902

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/gateway/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h *Handler) getShares(
height uint64,
namespace libshare.Namespace,
) ([]libshare.Share, error) {
shares, err := h.share.GetSharesByNamespace(ctx, height, namespace)
shares, err := h.share.GetNamespaceData(ctx, height, namespace)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (s *Service) retrieve(
getCtx, getSharesSpan := tracer.Start(ctx, "get-shares-by-namespace")

// collect shares for the requested namespace
namespacedShares, err := s.shareGetter.GetSharesByNamespace(getCtx, header, namespace)
namespacedShares, err := s.shareGetter.GetNamespaceData(getCtx, header, namespace)
if err != nil {
if errors.Is(err, shwap.ErrNotFound) {
err = ErrBlobNotFound
Expand Down
8 changes: 4 additions & 4 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,15 @@ func TestBlobService_Get(t *testing.T) {
innerGetter := service.shareGetter
getterWrapper := mock.NewMockGetter(ctrl)
getterWrapper.EXPECT().
GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).
GetNamespaceData(gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(
func(
ctx context.Context, h *header.ExtendedHeader, ns libshare.Namespace,
) (shwap.NamespaceData, error) {
if ns.Equals(blobsWithDiffNamespaces[0].Namespace()) {
return nil, errors.New("internal error")
}
return innerGetter.GetSharesByNamespace(ctx, h, ns)
return innerGetter.GetNamespaceData(ctx, h, ns)
}).AnyTimes()

service.shareGetter = getterWrapper
Expand Down Expand Up @@ -876,7 +876,7 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser
ctrl := gomock.NewController(t)
shareGetter := mock.NewMockGetter(ctrl)

shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().
shareGetter.EXPECT().GetNamespaceData(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().
DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns libshare.Namespace) (shwap.NamespaceData, error) {
idx := int(h.Height()) - 1
accessor := &eds.Rsmt2D{ExtendedDataSquare: edsses[idx]}
Expand All @@ -897,7 +897,7 @@ func createService(ctx context.Context, t testing.TB, shares []libshare.Share) *
accessor := &eds.Rsmt2D{ExtendedDataSquare: square}
ctrl := gomock.NewController(t)
shareGetter := mock.NewMockGetter(ctrl)
shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().
shareGetter.EXPECT().GetNamespaceData(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().
DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns libshare.Namespace) (shwap.NamespaceData, error) {
nd, err := eds.NamespaceData(ctx, accessor, ns)
return nd, err
Expand Down
20 changes: 18 additions & 2 deletions nodebuilder/da/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nodebuilder/share/cmd/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var getSharesByNamespaceCmd = &cobra.Command{
return err
}

shares, err := client.Share.GetSharesByNamespace(cmd.Context(), height, ns)
shares, err := client.Share.GetNamespaceData(cmd.Context(), height, ns)
return cmdnode.PrintOutput(shares, err, nil)
},
}
Expand Down
14 changes: 7 additions & 7 deletions nodebuilder/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type Module interface {
GetShare(ctx context.Context, height uint64, row, col int) (libshare.Share, error)
// GetEDS gets the full EDS identified by the given extended header.
GetEDS(ctx context.Context, height uint64) (*rsmt2d.ExtendedDataSquare, error)
// GetSharesByNamespace gets all shares from an EDS within the given namespace.
// GetNamespaceData gets all shares from an EDS within the given namespace.
// Shares are returned in a row-by-row order if the namespace spans multiple rows.
GetSharesByNamespace(
GetNamespaceData(
ctx context.Context, height uint64, namespace libshare.Namespace,
) (shwap.NamespaceData, error)
// GetRange gets a list of shares and their corresponding proof.
Expand All @@ -69,7 +69,7 @@ type API struct {
ctx context.Context,
height uint64,
) (*rsmt2d.ExtendedDataSquare, error) `perm:"read"`
GetSharesByNamespace func(
GetNamespaceData func(
ctx context.Context,
height uint64,
namespace libshare.Namespace,
Expand Down Expand Up @@ -98,12 +98,12 @@ func (api *API) GetRange(ctx context.Context, height uint64, start, end int) (*G
return api.Internal.GetRange(ctx, height, start, end)
}

func (api *API) GetSharesByNamespace(
func (api *API) GetNamespaceData(
ctx context.Context,
height uint64,
namespace libshare.Namespace,
) (shwap.NamespaceData, error) {
return api.Internal.GetSharesByNamespace(ctx, height, namespace)
return api.Internal.GetNamespaceData(ctx, height, namespace)
}

type module struct {
Expand Down Expand Up @@ -157,7 +157,7 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G
}, nil
}

func (m module) GetSharesByNamespace(
func (m module) GetNamespaceData(
ctx context.Context,
height uint64,
namespace libshare.Namespace,
Expand All @@ -166,5 +166,5 @@ func (m module) GetSharesByNamespace(
if err != nil {
return nil, err
}
return m.getter.GetSharesByNamespace(ctx, header, namespace)
return m.getter.GetNamespaceData(ctx, header, namespace)
}
10 changes: 5 additions & 5 deletions nodebuilder/tests/nd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func TestShrexNDFromLights(t *testing.T) {
require.NoError(t, err)

height := h.Height()
expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, height, ns)
expected, err := bridgeClient.Share.GetNamespaceData(reqCtx, height, ns)
require.NoError(t, err)
got, err := lightClient.Share.GetSharesByNamespace(reqCtx, height, ns)
got, err := lightClient.Share.GetNamespaceData(reqCtx, height, ns)
require.NoError(t, err)

require.True(t, len(got[0].Shares) > 0)
Expand Down Expand Up @@ -149,18 +149,18 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) {
height := h.Height()
ns, err := libshare.NewNamespaceFromBytes(namespace)
require.NoError(t, err)
expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, height, ns)
expected, err := bridgeClient.Share.GetNamespaceData(reqCtx, height, ns)
require.NoError(t, err)
require.True(t, len(expected[0].Shares) > 0)

// choose a random full to test
fN := fulls[len(fulls)/2]
fnClient := getAdminClient(ctx, fN, t)
gotFull, err := fnClient.Share.GetSharesByNamespace(reqCtx, height, ns)
gotFull, err := fnClient.Share.GetNamespaceData(reqCtx, height, ns)
require.NoError(t, err)
require.True(t, len(gotFull[0].Shares) > 0)

gotLight, err := lightClient.Share.GetSharesByNamespace(reqCtx, height, ns)
gotLight, err := lightClient.Share.GetNamespaceData(reqCtx, height, ns)
require.NoError(t, err)
require.True(t, len(gotLight[0].Shares) > 0)

Expand Down
2 changes: 1 addition & 1 deletion share/availability/light/availability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (g onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d
panic("not implemented")
}

func (g onceGetter) GetSharesByNamespace(
func (g onceGetter) GetNamespaceData(
_ context.Context,
_ *header.ExtendedHeader,
_ libshare.Namespace,
Expand Down
4 changes: 2 additions & 2 deletions share/shwap/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type Getter interface {
// GetEDS gets the full EDS identified by the given extended header.
GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error)

// GetSharesByNamespace gets all shares from an EDS within the given namespace.
// GetNamespaceData gets all shares from an EDS within the given namespace.
// Shares are returned in a row-by-row order if the namespace spans multiple rows.
// Inclusion of returned data could be verified using Verify method on NamespacedShares.
// If no shares are found for target namespace non-inclusion could be also verified by calling
// Verify method.
GetSharesByNamespace(context.Context, *header.ExtendedHeader, libshare.Namespace) (NamespaceData, error)
GetNamespaceData(context.Context, *header.ExtendedHeader, libshare.Namespace) (NamespaceData, error)
}
6 changes: 3 additions & 3 deletions share/shwap/getters/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func (cg *CascadeGetter) GetEDS(
return cascadeGetters(ctx, cg.getters, get)
}

// GetSharesByNamespace gets NamespacedShares from any of registered shwap.Getters in cascading
// GetNamespaceData gets NamespacedShares from any of registered shwap.Getters in cascading
// order.
func (cg *CascadeGetter) GetSharesByNamespace(
func (cg *CascadeGetter) GetNamespaceData(
ctx context.Context,
header *header.ExtendedHeader,
namespace libshare.Namespace,
Expand All @@ -91,7 +91,7 @@ func (cg *CascadeGetter) GetSharesByNamespace(
defer span.End()

get := func(ctx context.Context, get shwap.Getter) (shwap.NamespaceData, error) {
return get.GetSharesByNamespace(ctx, header, namespace)
return get.GetNamespaceData(ctx, header, namespace)
}

return cascadeGetters(ctx, cg.getters, get)
Expand Down
28 changes: 14 additions & 14 deletions share/shwap/getters/mock/getter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions share/shwap/getters/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestGetter(t *testing.T) (shwap.Getter, *header.ExtendedHeader) {
}

// SingleEDSGetter contains a single EDS where data is retrieved from.
// Its primary use is testing, and GetSharesByNamespace is not supported.
// Its primary use is testing, and GetNamespaceData is not supported.
type SingleEDSGetter struct {
EDS *rsmt2d.ExtendedDataSquare
}
Expand Down Expand Up @@ -65,10 +65,10 @@ func (seg *SingleEDSGetter) GetEDS(
return seg.EDS, nil
}

// GetSharesByNamespace returns NamespacedShares from a kept EDS if the correct root is given.
func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.ExtendedHeader, libshare.Namespace,
// GetNamespaceData returns NamespacedShares from a kept EDS if the correct root is given.
func (seg *SingleEDSGetter) GetNamespaceData(context.Context, *header.ExtendedHeader, libshare.Namespace,
) (shwap.NamespaceData, error) {
panic("SingleEDSGetter: GetSharesByNamespace is not implemented")
panic("SingleEDSGetter: GetNamespaceData is not implemented")
}

func (seg *SingleEDSGetter) checkRoots(roots *share.AxisRoots) error {
Expand Down
4 changes: 2 additions & 2 deletions share/shwap/p2p/bitswap/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func (g *Getter) GetEDS(
return square, nil
}

// GetSharesByNamespace uses [RowNamespaceDataBlock] and [Fetch] to get all the data
// GetNamespaceData uses [RowNamespaceDataBlock] and [Fetch] to get all the data
// by the given namespace. If data spans over multiple rows, the request is split into
// parallel RowNamespaceDataID requests per each row and then assembled back into NamespaceData.
func (g *Getter) GetSharesByNamespace(
func (g *Getter) GetNamespaceData(
ctx context.Context,
hdr *header.ExtendedHeader,
ns libshare.Namespace,
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/p2p/shrex/shrex_getter/shrex.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*r
}
}

func (sg *Getter) GetSharesByNamespace(
func (sg *Getter) GetNamespaceData(
ctx context.Context,
header *header.ExtendedHeader,
namespace libshare.Namespace,
Expand Down
10 changes: 5 additions & 5 deletions share/shwap/p2p/shrex/shrex_getter/shrex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestShrexGetter(t *testing.T) {
Height: height,
})

got, err := getter.GetSharesByNamespace(ctx, eh, namespace)
got, err := getter.GetNamespaceData(ctx, eh, namespace)
require.NoError(t, err)
require.NoError(t, got.Verify(roots, namespace))
})
Expand All @@ -102,7 +102,7 @@ func TestShrexGetter(t *testing.T) {
Height: height,
})

_, err := getter.GetSharesByNamespace(ctx, eh, namespace)
_, err := getter.GetNamespaceData(ctx, eh, namespace)
require.ErrorIs(t, err, shwap.ErrNotFound)
})

Expand Down Expand Up @@ -131,7 +131,7 @@ func TestShrexGetter(t *testing.T) {
require.NoError(t, err)
require.Len(t, rows, 1)

emptyShares, err := getter.GetSharesByNamespace(ctx, eh, nID)
emptyShares, err := getter.GetNamespaceData(ctx, eh, nID)
require.NoError(t, err)
// no shares should be returned
require.Nil(t, emptyShares.Flatten())
Expand All @@ -145,7 +145,7 @@ func TestShrexGetter(t *testing.T) {
require.NoError(t, err)
require.Len(t, rows, 0)

emptyShares, err = getter.GetSharesByNamespace(ctx, eh, nID)
emptyShares, err = getter.GetNamespaceData(ctx, eh, nID)
require.NoError(t, err)
// no shares should be returned
require.Nil(t, emptyShares.Flatten())
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestShrexGetter(t *testing.T) {
require.NoError(t, err)
require.Len(t, rows, 0)

emptyShares, err := getter.GetSharesByNamespace(ctx, eh, namespace)
emptyShares, err := getter.GetNamespaceData(ctx, eh, namespace)
require.NoError(t, err)
// no shares should be returned
require.Empty(t, emptyShares.Flatten())
Expand Down
2 changes: 1 addition & 1 deletion store/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (g *Getter) GetEDS(ctx context.Context, h *header.ExtendedHeader) (*rsmt2d.
return rsmt2d.ExtendedDataSquare, nil
}

func (g *Getter) GetSharesByNamespace(
func (g *Getter) GetNamespaceData(
ctx context.Context,
h *header.ExtendedHeader,
ns libshare.Namespace,
Expand Down
Loading
Loading