Skip to content

Commit 6f336f8

Browse files
committed
resolve comments left by @walldiss
1 parent cf6ac2a commit 6f336f8

File tree

6 files changed

+27
-23
lines changed

6 files changed

+27
-23
lines changed

share/shwap/p2p/shrex/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (m *Metrics) observePayloadRequested(
107107
// this attribute can be used to filter successful throughput vs total
108108
incomplete := status != statusSuccess
109109

110-
m.payloadServed.Add(ctx, int64(payloadSize), metric.WithAttributes(
110+
m.payloadRequested.Add(ctx, int64(payloadSize), metric.WithAttributes(
111111
attribute.String("protocol", requestName),
112112
attribute.Bool("incomplete", incomplete),
113113
))

share/shwap/p2p/shrex/shrex_getter/shrex.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ func (sg *Getter) GetSamples(
9999
ctx context.Context,
100100
header *header.ExtendedHeader,
101101
coords []shwap.SampleCoords,
102-
) ([]shwap.Sample, error) {
102+
) (_ []shwap.Sample, err error) {
103103
// short circuit if the data root is empty
104104
if header.DAH.Equals(share.EmptyEDSRoots()) {
105105
return []shwap.Sample{}, nil
106106
}
107107

108-
var err error
109108
ctx, span := tracer.Start(ctx, "shrex/get-samples")
110109
defer func() {
111110
utils.SetStatusAndEnd(span, err)
@@ -435,13 +434,13 @@ func (sg *Getter) executeRequest(
435434
switch {
436435
case getErr == nil:
437436
setStatus(peers.ResultNoop)
438-
sg.metrics.recordAttempts(ctx, reqType, attempt, true)
439437
verifyErr := handle()
440438
if verifyErr != nil {
441439
getErr = verifyErr
442440
setStatus(peers.ResultBlacklistPeer)
443441
break
444442
}
443+
sg.metrics.recordAttempts(ctx, reqType, attempt, true)
445444
setStatus(peers.ResultNoop)
446445
return nil
447446
case errors.Is(getErr, context.DeadlineExceeded),

share/shwap/p2p/shrex/shrex_getter/shrex_test.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shrex_getter //nolint:stylecheck // underscore in pkg name will be fixed
22

33
import (
44
"context"
5+
"fmt"
56
"sync/atomic"
67
"testing"
78
"time"
@@ -241,7 +242,7 @@ func TestShrexGetter(t *testing.T) {
241242
})
242243

243244
t.Run("Samples_Available", func(t *testing.T) {
244-
ctx, cancel := context.WithTimeout(ctx, time.Second)
245+
ctx, cancel := context.WithTimeout(ctx, time.Minute)
245246
t.Cleanup(cancel)
246247

247248
// generate test data
@@ -257,20 +258,24 @@ func TestShrexGetter(t *testing.T) {
257258
Height: height,
258259
})
259260

260-
coords := []shwap.SampleCoords{
261-
{Row: 0, Col: 0},
262-
{Row: 0, Col: 1},
263-
{Row: 0, Col: 2},
264-
{Row: 0, Col: 3},
261+
odsSize := len(eh.DAH.RowRoots) / 2
262+
coords := make([]shwap.SampleCoords, odsSize*odsSize)
263+
total := 0
264+
for i := 0; i < odsSize; i++ {
265+
for j := 0; j < odsSize; j++ {
266+
coords[total] = shwap.SampleCoords{Row: i, Col: j}
267+
total++
268+
}
265269
}
270+
266271
got, err := getter.GetSamples(ctx, eh, coords)
267272
require.NoError(t, err)
268273
assert.Len(t, got, len(coords))
269274

270-
rowShares := randEDS.Row(0)
275+
odsShares := randEDS.FlattenedODS()
271276
require.NoError(t, err)
272277
for i, samples := range got {
273-
assert.Equal(t, rowShares[i], samples.ToBytes())
278+
assert.Equal(t, odsShares[i], samples.ToBytes(), fmt.Sprintf("sample %d", i))
274279
}
275280
})
276281

@@ -343,13 +348,16 @@ func TestShrexGetter(t *testing.T) {
343348
Height: height,
344349
})
345350

346-
row, err := getter.GetRow(ctx, eh, 0)
347-
require.NoError(t, err)
348-
shrs, err := row.Shares()
349-
require.NoError(t, err)
350-
edsRow := randEDS.Row(0)
351-
for i, shr := range shrs {
352-
require.Equal(t, edsRow[i], shr.ToBytes())
351+
odsSize := len(roots.RowRoots)
352+
for i := 0; i < odsSize; i++ {
353+
row, err := getter.GetRow(ctx, eh, i)
354+
require.NoError(t, err)
355+
shrs, err := row.Shares()
356+
require.NoError(t, err)
357+
edsRow := randEDS.Row(uint(i))
358+
for j, shr := range shrs {
359+
require.Equal(t, edsRow[j], shr.ToBytes())
360+
}
353361
}
354362
})
355363

share/shwap/range_namespace_data_id.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func (rngid RangeNamespaceDataID) ResponseReader(ctx context.Context, acc Access
170170
return nil, fmt.Errorf("getting rngdata from accessor: %w", err)
171171
}
172172

173-
// TODO(@vgonkivs): This is a temporary solution that will be reworked
174173
buf := &bytes.Buffer{}
175174
_, err = rngdata.WriteTo(buf)
176175
if err != nil {

share/shwap/row.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ func (rid RowID) ResponseReader(ctx context.Context, acc Accessor) (io.Reader, e
272272
if err != nil {
273273
return nil, fmt.Errorf("getting half row from accessor: %w", err)
274274
}
275-
row := halfRow.ToRow()
276275

277-
// TODO(@vgonkivs): This is a temporary solution that will be reworked
276+
row := halfRow.ToRow()
278277
buf := &bytes.Buffer{}
279278
_, err = row.WriteTo(buf)
280279
if err != nil {

share/shwap/sample_id.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ func (sid SampleID) ResponseReader(ctx context.Context, acc Accessor) (io.Reader
207207
return nil, fmt.Errorf("getting sample from accessor: %w", err)
208208
}
209209

210-
// TODO(@vgonkivs): This is a temporary solution that will be reworked
211210
buf := &bytes.Buffer{}
212211
_, err = sample.WriteTo(buf)
213212
if err != nil {

0 commit comments

Comments
 (0)