Skip to content

Commit

Permalink
rename to SampleCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Nov 20, 2024
1 parent 7bc54ae commit fddcf4a
Show file tree
Hide file tree
Showing 33 changed files with 91 additions and 75 deletions.
18 changes: 9 additions & 9 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ func TestBlobService_Get(t *testing.T) {
shareOffset := 0
for i := range blobs {
row, col := calculateIndex(len(h.DAH.RowRoots), blobs[i].index)
idx := shwap.SampleIndex{Row: row, Col: col}
idx := shwap.SampleCoords{Row: row, Col: col}
require.NoError(t, err)
smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleIndex{idx})
smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleCoords{idx})
require.NoError(t, err)
require.True(t, bytes.Equal(smpls[0].Share.ToBytes(), resultShares[shareOffset].ToBytes()),
fmt.Sprintf("issue on %d attempt. ROW:%d, COL: %d, blobIndex:%d", i, row, col, blobs[i].index),
Expand Down Expand Up @@ -489,10 +489,10 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) {
h, err := service.headerGetter(ctx, 1)
require.NoError(t, err)
row, col := calculateIndex(len(h.DAH.RowRoots), newBlob.index)
idx := shwap.SampleIndex{Row: row, Col: col}
idx := shwap.SampleCoords{Row: row, Col: col}
require.NoError(t, err)

smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleIndex{idx})
smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleCoords{idx})
require.NoError(t, err)

assert.Equal(t, smpls[0].Share, resultShares[0])
Expand Down Expand Up @@ -526,10 +526,10 @@ func TestService_Get(t *testing.T) {
assert.Equal(t, b.Commitment, blob.Commitment)

row, col := calculateIndex(len(h.DAH.RowRoots), b.index)
idx := shwap.SampleIndex{Row: row, Col: col}
idx := shwap.SampleCoords{Row: row, Col: col}
require.NoError(t, err)

smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleIndex{idx})
smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleCoords{idx})
require.NoError(t, err)

assert.Equal(t, smpls[0].Share, resultShares[shareOffset], fmt.Sprintf("issue on %d attempt", i))
Expand Down Expand Up @@ -588,10 +588,10 @@ func TestService_GetAllWithoutPadding(t *testing.T) {
require.True(t, blobs[i].compareCommitments(blob.Commitment))

row, col := calculateIndex(len(h.DAH.RowRoots), blob.index)
idx := shwap.SampleIndex{Row: row, Col: col}
idx := shwap.SampleCoords{Row: row, Col: col}
require.NoError(t, err)

smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleIndex{idx})
smpls, err := service.shareGetter.GetSamples(ctx, h, []shwap.SampleCoords{idx})
require.NoError(t, err)

assert.Equal(t, smpls[0].Share, resultShares[shareOffset])
Expand Down Expand Up @@ -914,7 +914,7 @@ func createService(ctx context.Context, t testing.TB, shares []libshare.Share) *
return nd, err
})
shareGetter.EXPECT().GetSamples(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().
DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, indices []shwap.SampleIndex) ([]shwap.Sample, error) {
DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, indices []shwap.SampleCoords) ([]shwap.Sample, error) {
smpl, err := accessor.Sample(ctx, indices[0])
return []shwap.Sample{smpl}, err
})
Expand Down
16 changes: 16 additions & 0 deletions nodebuilder/share/mocks/api.go

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

12 changes: 6 additions & 6 deletions nodebuilder/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Module interface {
// GetShare gets a Share by coordinates in EDS.
GetShare(ctx context.Context, height uint64, row, col int) (libshare.Share, error)
// GetSamples gets sample for given indices.
GetSamples(ctx context.Context, header *header.ExtendedHeader, indices []shwap.SampleIndex) ([]shwap.Sample, error)
GetSamples(ctx context.Context, header *header.ExtendedHeader, indices []shwap.SampleCoords) ([]shwap.Sample, error)
// GetEDS gets the full EDS identified by the given extended header.
GetEDS(ctx context.Context, height uint64) (*rsmt2d.ExtendedDataSquare, error)
// GetNamespaceData gets all shares from an EDS within the given namespace.
Expand All @@ -71,7 +71,7 @@ type API struct {
GetSamples func(
ctx context.Context,
header *header.ExtendedHeader,
indices []shwap.SampleIndex,
indices []shwap.SampleCoords,
) ([]shwap.Sample, error) `perm:"read"`
GetEDS func(
ctx context.Context,
Expand Down Expand Up @@ -99,7 +99,7 @@ func (api *API) GetShare(ctx context.Context, height uint64, row, col int) (libs
}

func (api *API) GetSamples(ctx context.Context, header *header.ExtendedHeader,
indices []shwap.SampleIndex,
indices []shwap.SampleCoords,
) ([]shwap.Sample, error) {
return api.Internal.GetSamples(ctx, header, indices)
}
Expand Down Expand Up @@ -132,9 +132,9 @@ func (m module) GetShare(ctx context.Context, height uint64, row, col int) (libs
return libshare.Share{}, err
}

idx := shwap.SampleIndex{Row: row, Col: col}
idx := shwap.SampleCoords{Row: row, Col: col}

smpls, err := m.getter.GetSamples(ctx, header, []shwap.SampleIndex{idx})
smpls, err := m.getter.GetSamples(ctx, header, []shwap.SampleCoords{idx})
if err != nil {
return libshare.Share{}, err
}
Expand All @@ -143,7 +143,7 @@ func (m module) GetShare(ctx context.Context, height uint64, row, col int) (libs
}

func (m module) GetSamples(ctx context.Context, header *header.ExtendedHeader,
indices []shwap.SampleIndex,
indices []shwap.SampleCoords,
) ([]shwap.Sample, error) {
return m.getter.GetSamples(ctx, header, indices)
}
Expand Down
6 changes: 3 additions & 3 deletions share/availability/light/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header

log.Debugw("starting sampling session", "root", dah.String())

idxs := make([]shwap.SampleIndex, len(samples.Remaining))
idxs := make([]shwap.SampleCoords, len(samples.Remaining))
for i, s := range samples.Remaining {
idxs[i] = shwap.SampleIndex{Row: s.Row, Col: s.Col}
idxs[i] = shwap.SampleCoords{Row: s.Row, Col: s.Col}
}

smpls, err := la.getter.GetSamples(ctx, header, idxs)
Expand Down Expand Up @@ -197,7 +197,7 @@ func (la *ShareAvailability) Prune(ctx context.Context, h *header.ExtendedHeader

// delete stored samples
for _, sample := range result.Available {
idx := shwap.SampleIndex{Row: sample.Row, Col: sample.Col}
idx := shwap.SampleCoords{Row: sample.Row, Col: sample.Col}

blk, err := bitswap.NewEmptySampleBlock(h.Height(), idx, len(h.DAH.RowRoots))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions share/availability/light/availability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestSharesAvailableSuccess(t *testing.T) {
getter.EXPECT().
GetSamples(gomock.Any(), eh, gomock.Any()).
DoAndReturn(
func(_ context.Context, hdr *header.ExtendedHeader, indices []shwap.SampleIndex) ([]shwap.Sample, error) {
func(_ context.Context, hdr *header.ExtendedHeader, indices []shwap.SampleCoords) ([]shwap.Sample, error) {
acc := eds.Rsmt2D{ExtendedDataSquare: square}
smpls := make([]shwap.Sample, len(indices))
for i, idx := range indices {
Expand Down Expand Up @@ -279,7 +279,7 @@ func (g successGetter) sampledList() []Sample {
}

func (g successGetter) GetSamples(_ context.Context, hdr *header.ExtendedHeader,
indices []shwap.SampleIndex,
indices []shwap.SampleCoords,
) ([]shwap.Sample, error) {
g.Lock()
defer g.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion share/eds/accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Accessor interface {
// Sample returns share and corresponding proof for row and column indices. Implementation can
// choose which axis to use for proof. Chosen axis for proof should be indicated in the returned
// Sample.
Sample(ctx context.Context, idx shwap.SampleIndex) (shwap.Sample, error)
Sample(ctx context.Context, idx shwap.SampleCoords) (shwap.Sample, error)
// AxisHalf returns half of shares axis of the given type and index. Side is determined by
// implementation. Implementations should indicate the side in the returned AxisHalf.
AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error)
Expand Down
2 changes: 1 addition & 1 deletion share/eds/close_once.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *closeOnce) AxisRoots(ctx context.Context) (*share.AxisRoots, error) {
return c.f.AxisRoots(ctx)
}

func (c *closeOnce) Sample(ctx context.Context, idx shwap.SampleIndex) (shwap.Sample, error) {
func (c *closeOnce) Sample(ctx context.Context, idx shwap.SampleCoords) (shwap.Sample, error) {
if c.closed.Load() {
return shwap.Sample{}, errAccessorClosed
}
Expand Down
6 changes: 3 additions & 3 deletions share/eds/close_once_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestWithClosedOnce(t *testing.T) {
stub := &stubEdsAccessorCloser{}
closedOnce := WithClosedOnce(stub)

_, err := closedOnce.Sample(ctx, shwap.SampleIndex{})
_, err := closedOnce.Sample(ctx, shwap.SampleCoords{})
require.NoError(t, err)
_, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0)
require.NoError(t, err)
Expand All @@ -33,7 +33,7 @@ func TestWithClosedOnce(t *testing.T) {
require.True(t, stub.closed)

// Ensure that the underlying file is not accessible after closing
_, err = closedOnce.Sample(ctx, shwap.SampleIndex{})
_, err = closedOnce.Sample(ctx, shwap.SampleCoords{})
require.ErrorIs(t, err, errAccessorClosed)
_, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0)
require.ErrorIs(t, err, errAccessorClosed)
Expand All @@ -59,7 +59,7 @@ func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*share.AxisRoots, er
return &share.AxisRoots{}, nil
}

func (s *stubEdsAccessorCloser) Sample(context.Context, shwap.SampleIndex) (shwap.Sample, error) {
func (s *stubEdsAccessorCloser) Sample(context.Context, shwap.SampleCoords) (shwap.Sample, error) {
return shwap.Sample{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion share/eds/proofs_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *proofsCache) AxisRoots(ctx context.Context) (*share.AxisRoots, error) {
return roots, nil
}

func (c *proofsCache) Sample(ctx context.Context, idx shwap.SampleIndex) (shwap.Sample, error) {
func (c *proofsCache) Sample(ctx context.Context, idx shwap.SampleCoords) (shwap.Sample, error) {
axisType, axisIdx, shrIdx := rsmt2d.Row, idx.Row, idx.Col
ax, err := c.axisWithProofs(ctx, axisType, axisIdx)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions share/eds/rsmt2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (eds *Rsmt2D) AxisRoots(context.Context) (*share.AxisRoots, error) {
// Sample returns share and corresponding proof for row and column indices.
func (eds *Rsmt2D) Sample(
_ context.Context,
idx shwap.SampleIndex,
idx shwap.SampleCoords,
) (shwap.Sample, error) {
return eds.SampleForProofAxis(idx, rsmt2d.Row)
}

// SampleForProofAxis samples a share from an Extended Data Square based on the provided
// row and column indices and proof axis. It returns a sample with the share and proof.
func (eds *Rsmt2D) SampleForProofAxis(
idx shwap.SampleIndex,
idx shwap.SampleCoords,
proofType rsmt2d.Axis,
) (shwap.Sample, error) {
axisIdx, shrIdx := relativeIndexes(idx.Row, idx.Col, proofType)
Expand Down
2 changes: 1 addition & 1 deletion share/eds/rsmt2d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestRsmt2dSampleForProofAxis(t *testing.T) {
for _, proofType := range []rsmt2d.Axis{rsmt2d.Row, rsmt2d.Col} {
for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ {
for colIdx := 0; colIdx < odsSize*2; colIdx++ {
idx := shwap.SampleIndex{Row: rowIdx, Col: colIdx}
idx := shwap.SampleCoords{Row: rowIdx, Col: colIdx}

sample, err := accessor.SampleForProofAxis(idx, proofType)
require.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions share/eds/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func testAccessorSample(
// t.Parallel() this fails the test for some reason
for rowIdx := 0; rowIdx < width; rowIdx++ {
for colIdx := 0; colIdx < width; colIdx++ {
idx := shwap.SampleIndex{Row: rowIdx, Col: colIdx}
idx := shwap.SampleCoords{Row: rowIdx, Col: colIdx}
testSample(ctx, t, acc, roots, idx)
}
}
Expand All @@ -163,8 +163,8 @@ func testAccessorSample(
for rowIdx := 0; rowIdx < width; rowIdx++ {
for colIdx := 0; colIdx < width; colIdx++ {
wg.Add(1)
idx := shwap.SampleIndex{Row: rowIdx, Col: colIdx}
go func(idx shwap.SampleIndex) {
idx := shwap.SampleCoords{Row: rowIdx, Col: colIdx}
go func(idx shwap.SampleCoords) {
defer wg.Done()
testSample(ctx, t, acc, roots, idx)
}(idx)
Expand All @@ -186,7 +186,7 @@ func testAccessorSample(
defer wg.Done()
rowIdx := rand.IntN(int(eds.Width())) //nolint:gosec
colIdx := rand.IntN(int(eds.Width())) //nolint:gosec
testSample(ctx, t, acc, roots, shwap.SampleIndex{Row: rowIdx, Col: colIdx})
testSample(ctx, t, acc, roots, shwap.SampleCoords{Row: rowIdx, Col: colIdx})
}()
}
wg.Wait()
Expand All @@ -198,7 +198,7 @@ func testSample(
t *testing.T,
acc Accessor,
roots *share.AxisRoots,
idx shwap.SampleIndex,
idx shwap.SampleCoords,
) {
shr, err := acc.Sample(ctx, idx)
require.NoError(t, err)
Expand Down Expand Up @@ -447,7 +447,7 @@ func BenchGetSampleFromAccessor(
name := fmt.Sprintf("Size:%v/quadrant:%s", size, q)
b.Run(name, func(b *testing.B) {
rowIdx, colIdx := q.coordinates(acc.Size(ctx))
idx := shwap.SampleIndex{Row: rowIdx, Col: colIdx}
idx := shwap.SampleCoords{Row: rowIdx, Col: colIdx}

// warm up cache
_, err := acc.Sample(ctx, idx)
Expand Down
2 changes: 1 addition & 1 deletion share/eds/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (f validation) Size(ctx context.Context) int {
return int(size)
}

func (f validation) Sample(ctx context.Context, idx shwap.SampleIndex) (shwap.Sample, error) {
func (f validation) Sample(ctx context.Context, idx shwap.SampleCoords) (shwap.Sample, error) {
_, err := shwap.NewSampleID(1, idx, f.Size(ctx))
if err != nil {
return shwap.Sample{}, fmt.Errorf("sample validation: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion share/eds/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestValidation_Sample(t *testing.T) {
accessor := &Rsmt2D{ExtendedDataSquare: randEDS}
validation := WithValidation(AccessorAndStreamer(accessor, nil))

idx := shwap.SampleIndex{Row: tt.rowIdx, Col: tt.colIdx}
idx := shwap.SampleCoords{Row: tt.rowIdx, Col: tt.colIdx}

_, err := validation.Sample(context.Background(), idx)
if tt.expectFail {
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Getter interface {
// GetSamples gets samples by their indices.
// Returns Sample slice with requested number of samples in the requested order.
// May return partial response with some samples being empty if they weren't found.
GetSamples(ctx context.Context, header *header.ExtendedHeader, indices []SampleIndex) ([]Sample, error)
GetSamples(ctx context.Context, header *header.ExtendedHeader, indices []SampleCoords) ([]Sample, error)

// GetEDS gets the full EDS identified by the given extended header.
GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error)
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/getters/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewCascadeGetter(getters []shwap.Getter) *CascadeGetter {

// GetSamples gets samples from any of registered shwap.Getters in cascading order.
func (cg *CascadeGetter) GetSamples(ctx context.Context, hdr *header.ExtendedHeader,
indices []shwap.SampleIndex,
indices []shwap.SampleCoords,
) ([]shwap.Sample, error) {
ctx, span := tracer.Start(ctx, "cascade/get-samples", trace.WithAttributes(
attribute.Int("amount", len(indices)),
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/getters/cascade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCascadeGetter(t *testing.T) {
getter := NewCascadeGetter(getters)
t.Run("GetShare", func(t *testing.T) {
for _, eh := range headers {
sh, err := getter.GetSamples(ctx, eh, []shwap.SampleIndex{{}})
sh, err := getter.GetSamples(ctx, eh, []shwap.SampleCoords{{}})
assert.NoError(t, err)
assert.NotEmpty(t, sh)
}
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/getters/mock/getter.go

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

2 changes: 1 addition & 1 deletion share/shwap/getters/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type SingleEDSGetter struct {

// GetSamples get samples from a kept EDS if exist and if the correct root is given.
func (seg *SingleEDSGetter) GetSamples(ctx context.Context, hdr *header.ExtendedHeader,
indices []shwap.SampleIndex,
indices []shwap.SampleCoords,
) ([]shwap.Sample, error) {
err := seg.checkRoots(hdr.DAH)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/p2p/bitswap/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (g *Getter) Stop() {
func (g *Getter) GetSamples(
ctx context.Context,
hdr *header.ExtendedHeader,
indices []shwap.SampleIndex,
indices []shwap.SampleCoords,
) ([]shwap.Sample, error) {
if len(indices) == 0 {
return nil, fmt.Errorf("no sample indicies to fetch")
Expand Down
4 changes: 2 additions & 2 deletions share/shwap/p2p/bitswap/sample_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type SampleBlock struct {
}

// NewEmptySampleBlock constructs a new empty SampleBlock.
func NewEmptySampleBlock(height uint64, idx shwap.SampleIndex, edsSize int) (*SampleBlock, error) {
func NewEmptySampleBlock(height uint64, idx shwap.SampleCoords, edsSize int) (*SampleBlock, error) {
id, err := shwap.NewSampleID(height, idx, edsSize)
if err != nil {
return nil, err
Expand Down Expand Up @@ -94,7 +94,7 @@ func (sb *SampleBlock) Marshal() ([]byte, error) {
}

func (sb *SampleBlock) Populate(ctx context.Context, eds eds.Accessor) error {
idx := shwap.SampleIndex{Row: sb.ID.RowIndex, Col: sb.ID.ShareIndex}
idx := shwap.SampleCoords{Row: sb.ID.RowIndex, Col: sb.ID.ShareIndex}

smpl, err := eds.Sample(ctx, idx)
if err != nil {
Expand Down
Loading

0 comments on commit fddcf4a

Please sign in to comment.