Skip to content

Commit

Permalink
fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ConvallariaMaj committed Aug 14, 2024
1 parent b7fcf55 commit 3ac16db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ such and the node will continue to scan new ATXs for their validity.

* [#6142](https://github.com/spacemeshos/go-spacemesh/pull/6142) Fix node not dropping peers that are broadcasting
invalid ATXs.

## Release v1.6.3

### Improvements
Expand Down
9 changes: 5 additions & 4 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ var (
type PoetConfig struct {
// Offset from the epoch start when the poet round starts
PhaseShift time.Duration `mapstructure:"phase-shift"`
// A gap between end of old PoET round and start of new one
// CycleGap gives the duration between the end of a PoET round and the start of the next
CycleGap time.Duration `mapstructure:"cycle-gap"`
// Time duration measured from the end of cycle gap, when we start to build the NiPoST challenge.
// The later we start (the smaller this value is)
// the higher is the chance for getting a good positioning ATX.
// GracePeriod defines the time before the start of the next PoET round until the node
// waits before building its NiPoST challenge. Shorter durations allow the node to
// possibly pick a better positioning ATX, but come with the risk that the node might
// not be able to validate that ATX and has to fall back to using its own previous ATX.
GracePeriod time.Duration `mapstructure:"grace-period"`
RequestTimeout time.Duration `mapstructure:"poet-request-timeout"`
RequestRetryDelay time.Duration `mapstructure:"retry-delay"`
Expand Down
23 changes: 6 additions & 17 deletions activation/poet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"io"
"math"
"math/rand"
"math/rand/v2"
"net/http"
"net/url"
"sync"
Expand Down Expand Up @@ -129,22 +129,11 @@ func WithLogger(logger *zap.Logger) PoetClientOpts {
}
}

func customLinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
attemptNum++
func customLinearJitterBackoff(min, max time.Duration, _ int, _ *http.Response) time.Duration {
if max <= min {
return min * time.Duration(attemptNum)
return min
}

source := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))

jitter := source.Float64() * float64(max-min)
jitterMin := int64(jitter) + int64(min)

sleep := time.Duration(jitterMin * int64(attemptNum))
if sleep > max {
sleep = max
}
return sleep
return min + rand.N(max-min)

Check warning on line 136 in activation/poet.go

View check run for this annotation

Codecov / codecov/patch

activation/poet.go#L136

Added line #L136 was not covered by tests
}

// NewHTTPPoetClient returns new instance of HTTPPoetClient connecting to the specified url.
Expand All @@ -153,15 +142,15 @@ func NewHTTPPoetClient(server types.PoetServer, cfg PoetConfig, opts ...PoetClie
RetryMax: cfg.MaxRequestRetries,
RetryWaitMin: cfg.RequestRetryDelay,
RetryWaitMax: 2 * cfg.RequestRetryDelay,
Backoff: customLinearJitterBackoff,
Backoff: retryablehttp.LinearJitterBackoff,
CheckRetry: checkRetry,
}

submitChallengeClient := &retryablehttp.Client{
RetryMax: math.MaxInt,
RetryWaitMin: cfg.RequestRetryDelay,
RetryWaitMax: 2 * cfg.RequestRetryDelay,
Backoff: retryablehttp.DefaultBackoff,
Backoff: customLinearJitterBackoff,
CheckRetry: retryablehttp.DefaultRetryPolicy,
}

Expand Down

0 comments on commit 3ac16db

Please sign in to comment.