diff --git a/activation/activation.go b/activation/activation.go index cfa1efb3f5..c423ed29c6 100644 --- a/activation/activation.go +++ b/activation/activation.go @@ -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"` } @@ -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 ) @@ -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), @@ -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) + return untilRoundStart + jitter } diff --git a/activation/activation_test.go b/activation/activation_test.go index 9f40809b58..2388fb026d 100644 --- a/activation/activation_test.go +++ b/activation/activation_test.go @@ -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 }{ @@ -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 { diff --git a/activation/nipost.go b/activation/nipost.go index c40899dd53..c477622aeb 100644 --- a/activation/nipost.go +++ b/activation/nipost.go @@ -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) diff --git a/activation/nipost_test.go b/activation/nipost_test.go index 93bb3a51b7..afdfd8549b 100644 --- a/activation/nipost_test.go +++ b/activation/nipost_test.go @@ -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, } @@ -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, } diff --git a/cmd/root.go b/cmd/root.go index d55dd23071..517598c67c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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", diff --git a/config/mainnet.go b/config/mainnet.go index abee02a74b..563f1a0a1d 100644 --- a/config/mainnet.go +++ b/config/mainnet.go @@ -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, }, diff --git a/config/presets/fastnet.go b/config/presets/fastnet.go index 8c08e30832..df1672bd60 100644 --- a/config/presets/fastnet.go +++ b/config/presets/fastnet.go @@ -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 diff --git a/config/presets/standalone.go b/config/presets/standalone.go index 41ace4a5cd..591aafd4a2 100644 --- a/config/presets/standalone.go +++ b/config/presets/standalone.go @@ -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