Skip to content

Commit

Permalink
one more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Nov 19, 2024
1 parent 8696237 commit 560087a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 79 deletions.
77 changes: 0 additions & 77 deletions share/availability/light/availability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,82 +260,6 @@ func TestParallelAvailability(t *testing.T) {
require.Len(t, samplingResult.Available, int(avail.params.SampleAmount))
}

type onceGetter struct {
*sync.Mutex
sampled map[Sample]int
}

func newOnceGetter() onceGetter {
return onceGetter{
Mutex: &sync.Mutex{},
sampled: make(map[Sample]int),
}
}

func (g onceGetter) addSamples(samples []Sample) {
g.Lock()
defer g.Unlock()

for _, r := range samples {
s := Sample{Row: r.Row, Col: r.Col}
g.sampled[s]++
}
}

func (g onceGetter) sampledList() []Sample {
g.Lock()
defer g.Unlock()
samples := make([]Sample, 0, len(g.sampled))
for s := range g.sampled {
samples = append(samples, s)
}
return samples
}

func (g onceGetter) checkOnce(t *testing.T) {
g.Lock()
defer g.Unlock()
for s, count := range g.sampled {
if count > 1 {
t.Errorf("sample %v was called more than once", s)
}
}
}

func (g onceGetter) GetSamples(_ context.Context, hdr *header.ExtendedHeader,
indices []shwap.SampleIndex,
) ([]shwap.Sample, error) {
g.Lock()
defer g.Unlock()

smpls := make([]shwap.Sample, 0, len(indices))
for _, idx := range indices {
rowIdx, colIdx, err := idx.Coordinates(len(hdr.DAH.RowRoots))
if err != nil {
return nil, err
}

s := Sample{Row: rowIdx, Col: colIdx}
if _, ok := g.sampled[s]; ok {
delete(g.sampled, s)
smpls = append(smpls, shwap.Sample{Proof: &nmt.Proof{}})
}
}
return smpls, nil
}

func (g onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) {
panic("not implemented")
}

func (g onceGetter) GetNamespaceData(
_ context.Context,
_ *header.ExtendedHeader,
_ libshare.Namespace,
) (shwap.NamespaceData, error) {
panic("not implemented")
}

type successGetter struct {
*sync.Mutex
sampled map[Sample]int
Expand Down Expand Up @@ -370,7 +294,6 @@ func (g successGetter) GetSamples(_ context.Context, hdr *header.ExtendedHeader,
s := Sample{Row: rowIdx, Col: colIdx}
g.sampled[s]++
smpls = append(smpls, shwap.Sample{Proof: &nmt.Proof{}})

}
return smpls, nil
}
Expand Down
4 changes: 2 additions & 2 deletions share/availability/light/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func selectRandomSamples(squareSize, sampleCount int) []Sample {
return maps.Keys(samples)
}

func randInt(max int) int {
n, err := crand.Int(crand.Reader, big.NewInt(int64(max)))
func randInt(m int) int {
n, err := crand.Int(crand.Reader, big.NewInt(int64(m)))
if err != nil {
panic(err) // won't panic as rand.Reader is endless
}
Expand Down

0 comments on commit 560087a

Please sign in to comment.