Skip to content

Commit

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

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

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

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)
if err != nil {
return fmt.Errorf("upload chunks: %w", err)
}
c.logger.Infof("upload completed. Downloading %s", root.String())
_, err = downloadClient.DownloadBytes(ctx, root, &api.DownloadOptions{RedundancyFallbackMode: &fallbackMode})
if err == nil {
return fmt.Errorf("expected download to fail")
}

c.logger.Infof("rLevel %d completed successfully", i)
}
return nil
Expand All @@ -123,17 +140,30 @@ 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) error {
func (c *Check) uploadChunks(ctx context.Context, client *bee.Client, chunks []swarm.Chunk, rLevel redundancy.Level, seed int64, batchID string, shouldDownload bool) error {
rate := 0.0
switch rLevel {
case redundancy.MEDIUM:
rate = 0.01
case redundancy.STRONG:
rate = 0.05
case redundancy.INSANE:
rate = 0.1
case redundancy.PARANOID:
rate = 0.35
if shouldDownload {
switch rLevel {
case redundancy.MEDIUM:
rate = 0.01
case redundancy.STRONG:
rate = 0.05
case redundancy.INSANE:
rate = 0.1
case redundancy.PARANOID:
rate = 0.35
}
} else {
switch rLevel {
case redundancy.MEDIUM:
rate = 0.1
case redundancy.STRONG:
rate = 0.15
case redundancy.INSANE:
rate = 0.2
case redundancy.PARANOID:
rate = 0.6
}
}

rnd := random.PseudoGenerator(seed)
Expand Down

0 comments on commit ca322c5

Please sign in to comment.