Skip to content

Commit

Permalink
Rename Grace Period
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Sep 11, 2023
1 parent 61d308f commit 18d4050
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
16 changes: 8 additions & 8 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
type PoetConfig struct {
PhaseShift time.Duration `mapstructure:"phase-shift"`
CycleGap time.Duration `mapstructure:"cycle-gap"`
GracePeriod time.Duration `mapstructure:"grace-period"`
RequestTimeout time.Duration `mapstructure:"grace-period"`
RequestRetryDelay time.Duration `mapstructure:"retry-delay"`
MaxRequestRetries int `mapstructure:"retry-max"`
}
Expand All @@ -50,9 +50,9 @@ const (
defaultPoetRetryInterval = 5 * time.Second

// Jitter added to the wait time before building a nipost challenge.
// It's expressed as % of poet grace period which translates to:
// mainnet (grace period 1h) -> 36s
// systest (grace period 10s) -> 0.1s
// It is expressed as ‰ (1/1000) of PoET cycle gap which translates to:
// mainnet (cycle gap 12h) -> 43.20s
// systest (grace gap 30s) -> 0.03s
maxNipostChallengeBuildJitter = 1.0
)

Expand Down Expand Up @@ -440,7 +440,7 @@ func (b *Builder) buildNIPostChallenge(ctx context.Context) (*types.NIPostChalle
ErrATXChallengeExpired, current, -until)
}
metrics.PublishOntimeWindowLatency.Observe(until.Seconds())
wait := timeToWaitToBuildNipostChallenge(until, b.poetCfg.GracePeriod)
wait := timeToWaitToBuildNipostChallenge(until, b.poetCfg.CycleGap)
if wait >= 0 {
b.log.WithContext(ctx).With().Debug("waiting for fresh atxs",
log.Duration("till poet round", until),
Expand Down Expand Up @@ -726,7 +726,7 @@ func SignAndFinalizeAtx(signer *signing.EdSigner, atx *types.ActivationTx) error
return atx.Initialize()
}

func timeToWaitToBuildNipostChallenge(untilRoundStart, gracePeriod time.Duration) time.Duration {
jitter := randomDurationInRange(time.Duration(0), gracePeriod*maxNipostChallengeBuildJitter/100.0)
return untilRoundStart + jitter - gracePeriod
func timeToWaitToBuildNipostChallenge(untilRoundStart, cycleGap time.Duration) time.Duration {
jitter := randomDurationInRange(time.Duration(0), cycleGap * maxNipostChallengeBuildJitter/1000.0)

Check failure on line 730 in activation/activation.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/spacemeshos/go-spacemesh) (gci)
return untilRoundStart + jitter
}
8 changes: 4 additions & 4 deletions activation/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,8 @@ func TestBuilder_UpdatePoetsUnstable(t *testing.T) {
func TestWaitPositioningAtx(t *testing.T) {
genesis := time.Now()
for _, tc := range []struct {
desc string
shift, grace time.Duration
desc string
shift, timeout time.Duration

expect string
}{
Expand All @@ -1239,8 +1239,8 @@ func TestWaitPositioningAtx(t *testing.T) {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
tab := newTestBuilder(t, WithPoetConfig(PoetConfig{
PhaseShift: tc.shift,
GracePeriod: tc.grace,
PhaseShift: tc.shift,
RequestTimeout: tc.timeout,
}))
tab.mclock.EXPECT().CurrentLayer().Return(types.LayerID(0)).AnyTimes()
tab.mclock.EXPECT().LayerToTime(gomock.Any()).DoAndReturn(func(lid types.LayerID) time.Time {
Expand Down
4 changes: 1 addition & 3 deletions activation/nipost.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,7 @@ func (nb *NIPostBuilder) getBestProof(ctx context.Context, challenge types.Hash3
case <-time.After(time.Until(waitDeadline)):
}

// TODO(mafa): this should be renamed from GracePeriod to something like RequestTimeout
// and should be much shorter (e.g. 10 seconds instead of 1 hour on mainnet)
getProofsCtx, cancel := context.WithTimeout(ctx, nb.poetCfg.GracePeriod)
getProofsCtx, cancel := context.WithTimeout(ctx, nb.poetCfg.RequestTimeout)
defer cancel()

proof, members, err := client.Proof(getProofsCtx, round)
Expand Down
4 changes: 2 additions & 2 deletions activation/nipost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func buildNIPost(tb testing.TB, postProvider *testPostManager, nipostChallenge t
poetCfg := PoetConfig{
PhaseShift: epoch / 5,
CycleGap: epoch / 10,
GracePeriod: epoch / 10,
RequestTimeout: epoch / 20,
RequestRetryDelay: epoch / 100,
MaxRequestRetries: 10,
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestNewNIPostBuilderNotInitialized(t *testing.T) {
poetCfg := PoetConfig{
PhaseShift: epoch / 5,
CycleGap: epoch / 10,
GracePeriod: epoch / 10,
RequestTimeout: epoch / 20,
RequestRetryDelay: epoch / 100,
MaxRequestRetries: 10,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ func AddCommands(cmd *cobra.Command) {
cfg.POET.PhaseShift, "phase shift of poet server")
cmd.PersistentFlags().DurationVar(&cfg.POET.CycleGap, "cycle-gap",
cfg.POET.CycleGap, "cycle gap of poet server")
cmd.PersistentFlags().DurationVar(&cfg.POET.GracePeriod, "grace-period",
cfg.POET.GracePeriod, "propagation time for ATXs in the network")
cmd.PersistentFlags().DurationVar(&cfg.POET.RequestTimeout, "poet-request-timeout",
cfg.POET.RequestTimeout, "timeout for poet requests")

/**======================== bootstrap data updater Flags ========================== **/
cmd.PersistentFlags().StringVar(&cfg.Bootstrap.URL, "bootstrap-url",
Expand Down
2 changes: 1 addition & 1 deletion config/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func MainnetConfig() Config {
POET: activation.PoetConfig{
PhaseShift: 240 * time.Hour,
CycleGap: 12 * time.Hour,
GracePeriod: 1 * time.Hour,
RequestTimeout: 10 * time.Second,
RequestRetryDelay: 10 * time.Second,
MaxRequestRetries: 10,
},
Expand Down
2 changes: 1 addition & 1 deletion config/presets/fastnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func fastnet() config.Config {
conf.Beacon.BeaconSyncWeightUnits = 10
conf.Beacon.VotesLimit = 100

conf.POET.GracePeriod = 10 * time.Second
conf.POET.RequestTimeout = 5 * time.Second
conf.POET.CycleGap = 30 * time.Second
conf.POET.PhaseShift = 30 * time.Second

Expand Down
2 changes: 1 addition & 1 deletion config/presets/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func standalone() config.Config {
conf.Beacon.VotesLimit = 100

conf.PoETServers = []string{"http://0.0.0.0:10010"}
conf.POET.GracePeriod = 5 * time.Second
conf.POET.RequestTimeout = 5 * time.Second
conf.POET.CycleGap = 30 * time.Second
conf.POET.PhaseShift = 30 * time.Second

Expand Down

0 comments on commit 18d4050

Please sign in to comment.