-
Notifications
You must be signed in to change notification settings - Fork 32
fix: gsoc and pss checks #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martinconic
wants to merge
1
commit into
master
Choose a base branch
from
fix/gsoc-pss-checks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,14 +29,16 @@ type Options struct { | |
| PostageTTL time.Duration | ||
| PostageDepth uint64 | ||
| PostageLabel string | ||
| Chunks int | ||
| } | ||
|
|
||
| // NewDefaultOptions returns new default options | ||
| func NewDefaultOptions() Options { | ||
| return Options{ | ||
| PostageTTL: 24 * time.Hour, | ||
| PostageDepth: 17, | ||
| PostageDepth: 22, | ||
| PostageLabel: "test-label", | ||
| Chunks: 3, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -95,14 +97,14 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any | |
| } | ||
|
|
||
| c.logger.Infof("send messages with different postage batches sequentially...") | ||
| err = run(ctx, uploadClient, listenClient, batches, c.logger, false) | ||
| err = run(ctx, uploadClient, listenClient, batches, c.logger, false, o.Chunks) | ||
| if err != nil { | ||
| return fmt.Errorf("sequential: %w", err) | ||
| } | ||
| c.logger.Infof("done") | ||
|
|
||
| c.logger.Infof("send messages with different postage batches parallel...") | ||
| err = run(ctx, uploadClient, listenClient, batches, c.logger, true) | ||
| err = run(ctx, uploadClient, listenClient, batches, c.logger, true, o.Chunks) | ||
| if err != nil { | ||
| return fmt.Errorf("parallel: %w", err) | ||
| } | ||
|
|
@@ -111,8 +113,10 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any | |
| return nil | ||
| } | ||
|
|
||
| func run(ctx context.Context, uploadClient *bee.Client, listenClient *bee.Client, batches []string, logger logging.Logger, parallel bool) error { | ||
| const numChunks = 10 | ||
| func run(ctx context.Context, uploadClient *bee.Client, listenClient *bee.Client, batches []string, logger logging.Logger, parallel bool, numChunks int) error { | ||
| if numChunks <= 0 { | ||
| numChunks = 3 | ||
| } | ||
| privKey, err := crypto.GenerateSecp256k1Key() | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -171,21 +175,49 @@ func run(ctx context.Context, uploadClient *bee.Client, listenClient *bee.Client | |
| return err | ||
| } | ||
|
|
||
| select { | ||
| case <-time.After(3 * time.Minute): | ||
| return fmt.Errorf("timeout: not all messages received") | ||
| case <-done: | ||
| } | ||
| // Wait for all messages to be received or timeout | ||
| ticker := time.NewTicker(30 * time.Second) | ||
| defer ticker.Stop() | ||
| timeout := time.After(3 * time.Minute) | ||
|
|
||
| receivedMtx.Lock() | ||
| defer receivedMtx.Unlock() | ||
| for i := range numChunks { | ||
| want := fmt.Sprintf("data %d", i) | ||
| if !received[want] { | ||
| return fmt.Errorf("message '%s' not received", want) | ||
| for { | ||
| select { | ||
| case <-done: | ||
| return nil | ||
| case <-timeout: | ||
| return fmt.Errorf("timeout: not all messages received") | ||
| case <-ticker.C: | ||
| receivedMtx.Lock() | ||
| if len(received) == numChunks { | ||
| receivedMtx.Unlock() | ||
| return nil | ||
| } | ||
|
|
||
| var missing []int | ||
| for i := range numChunks { | ||
| want := fmt.Sprintf("data %d", i) | ||
| if !received[want] { | ||
| missing = append(missing, i) | ||
| } | ||
| } | ||
| receivedMtx.Unlock() | ||
|
|
||
| if len(missing) == 0 { | ||
| continue | ||
| } | ||
|
|
||
| logger.Infof("gsoc: still missing %d chunks: %v. retrying...", len(missing), missing) | ||
|
|
||
| // Retry missing chunks sequentially to avoid flooding | ||
| for _, i := range missing { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the retry loop check ctx.Done() before each iteration? |
||
| payload := fmt.Sprintf("data %d", i) | ||
| logger.Infof("gsoc: retrying soc to node=%s, payload=%s", uploadClient.Name(), payload) | ||
| if err := uploadSoc(ctx, uploadClient, payload, resourceId, batches[i%2], privKey); err != nil { | ||
| logger.Errorf("gsoc: retry failed for %s: %v", payload, err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func uploadSoc(ctx context.Context, client *bee.Client, payload string, resourceId []byte, batchID string, privKey *ecdsa.PrivateKey) error { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should show a warning to user that we are changing number of chunks to 3 ?
Why 3 exactly ?