Skip to content

Commit

Permalink
fix: seed
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Mar 6, 2024
1 parent ca322c5 commit f4eb64d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/check/redundancy/redundancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interf
return fmt.Errorf("get clients: %w", err)
}

root, data, chunks, err := c.generateChunks(ctx, opts.DataSize, redundancy.Level(i), opts.Seed)
root, data, chunks, err := c.generateChunks(ctx, opts.DataSize, redundancy.Level(i))
if err != nil {
return fmt.Errorf("get chunks: %w", err)
}
Expand All @@ -83,7 +83,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interf
}

// happy path
err = c.uploadChunks(ctx, uploadClient, chunks, redundancy.Level(i), opts.Seed, batchID, true)
err = c.uploadChunks(ctx, uploadClient, chunks, redundancy.Level(i), batchID, true)
if err != nil {
return fmt.Errorf("upload chunks: %w", err)
}
Expand All @@ -99,12 +99,12 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interf
}

// non-happy path
root, data, chunks, err = c.generateChunks(ctx, opts.DataSize, redundancy.Level(i), opts.Seed)
root, data, chunks, err = c.generateChunks(ctx, opts.DataSize, redundancy.Level(i))

Check failure on line 102 in pkg/check/redundancy/redundancy.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

ineffectual assignment to data (ineffassign)
if err != nil {
return fmt.Errorf("get chunks: %w", err)
}
c.logger.Infof("root hash: %s, chunks: %d", root.String(), len(chunks))
err = c.uploadChunks(ctx, uploadClient, chunks, redundancy.Level(i), opts.Seed, batchID, false)
err = c.uploadChunks(ctx, uploadClient, chunks, redundancy.Level(i), batchID, false)
if err != nil {
return fmt.Errorf("upload chunks: %w", err)
}
Expand All @@ -119,13 +119,13 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interf
return nil
}

func (c *Check) generateChunks(ctx context.Context, size int64, rLevel redundancy.Level, seed int64) (swarm.Address, []byte, []swarm.Chunk, error) {
func (c *Check) generateChunks(ctx context.Context, size int64, rLevel redundancy.Level) (swarm.Address, []byte, []swarm.Chunk, error) {
putter := &splitPutter{
chunks: make([]swarm.Chunk, 0),
}

buf := make([]byte, size)
rnd := random.PseudoGenerator(seed)
rnd := random.PseudoGenerator(time.Now().UnixNano())
_, err := rnd.Read(buf)
if err != nil {
return swarm.ZeroAddress, nil, nil, err
Expand All @@ -140,7 +140,7 @@ func (c *Check) generateChunks(ctx context.Context, size int64, rLevel redundanc
return rootAddr, buf, putter.chunks, nil
}

func (c *Check) uploadChunks(ctx context.Context, client *bee.Client, chunks []swarm.Chunk, rLevel redundancy.Level, seed int64, batchID string, shouldDownload bool) error {
func (c *Check) uploadChunks(ctx context.Context, client *bee.Client, chunks []swarm.Chunk, rLevel redundancy.Level, batchID string, shouldDownload bool) error {
rate := 0.0
if shouldDownload {
switch rLevel {
Expand All @@ -166,7 +166,7 @@ func (c *Check) uploadChunks(ctx context.Context, client *bee.Client, chunks []s
}
}

rnd := random.PseudoGenerator(seed)
rnd := random.PseudoGenerator(time.Now().UnixNano())
indices := rnd.Perm(len(chunks) - 1)
offset := int(rate * float64(len(chunks)))
indices = append(indices[offset:], len(chunks)-1)
Expand Down

0 comments on commit f4eb64d

Please sign in to comment.