From dbc1183c0ad34eb5be246edfacc49f8278741674 Mon Sep 17 00:00:00 2001 From: Matthias Fasching <5011972+fasmat@users.noreply.github.com> Date: Mon, 27 Nov 2023 08:40:54 +0000 Subject: [PATCH] Fix timings in e2e tests (#5304) ## Motivation Fix flaky tests in `activation/e2e`. Test would randomly fail with the NIPostBuilder failing to fetch a poet proof. ## Changes - ensure that the spawned PoET and the nipost builder use the same genesis time instead of `time.Now()` - update PoET config to ensure that there is enough time to fetch a proof from PoET and retry in case PoET is slightly slow to generate the proof and the first request by NIPostBuilder fails ## Test Plan n/a ## TODO - [x] Explain motivation or link existing issue(s) - [x] Test changes and document test plan - [x] Update documentation as needed - [x] Update [changelog](../CHANGELOG.md) as needed --- activation/e2e/nipost_test.go | 24 ++++++++++++------------ activation/e2e/validation_test.go | 8 ++++---- common/types/poet.go | 6 +++--- config/presets/fastnet.go | 1 - 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/activation/e2e/nipost_test.go b/activation/e2e/nipost_test.go index eb780d32e4..645f9cea2f 100644 --- a/activation/e2e/nipost_test.go +++ b/activation/e2e/nipost_test.go @@ -134,10 +134,12 @@ func TestNIPostBuilderWithClients(t *testing.T) { opts.Scrypt.N = 2 // Speedup initialization in tests. initPost(t, logger.Named("manager"), mgr, opts) + // ensure that genesis aligns with layer timings + genesis := time.Now().Add(layerDuration).Round(layerDuration) epoch := layersPerEpoch * layerDuration poetCfg := activation.PoetConfig{ PhaseShift: epoch / 2, - CycleGap: epoch / 5, + CycleGap: epoch / 4, GracePeriod: epoch / 5, RequestTimeout: epoch / 5, RequestRetryDelay: epoch / 50, @@ -145,7 +147,7 @@ func TestNIPostBuilderWithClients(t *testing.T) { } poetProver := spawnPoet( t, - WithGenesis(time.Now()), + WithGenesis(genesis), WithEpochDuration(epoch), WithPhaseShift(poetCfg.PhaseShift), WithCycleGap(poetCfg.CycleGap), @@ -154,8 +156,6 @@ func TestNIPostBuilderWithClients(t *testing.T) { mclock := activation.NewMocklayerClock(ctrl) mclock.EXPECT().LayerToTime(gomock.Any()).AnyTimes().DoAndReturn( func(got types.LayerID) time.Time { - // time.Now() ~= currentLayer - genesis := time.Now().Add(-time.Duration(postGenesisEpoch.FirstLayer()) * layerDuration) return genesis.Add(layerDuration * time.Duration(got)) }, ) @@ -266,18 +266,20 @@ func TestNewNIPostBuilderNotInitialized(t *testing.T) { mgr, err := activation.NewPostSetupManager(sig.NodeID(), cfg, logger, cdb, goldenATX) require.NoError(t, err) + // ensure that genesis aligns with layer timings + genesis := time.Now().Add(layerDuration).Round(layerDuration) epoch := layersPerEpoch * layerDuration poetCfg := activation.PoetConfig{ - PhaseShift: epoch / 5, - CycleGap: epoch / 10, - GracePeriod: epoch / 10, - RequestTimeout: epoch / 10, - RequestRetryDelay: epoch / 100, + PhaseShift: epoch / 2, + CycleGap: epoch / 4, + GracePeriod: epoch / 5, + RequestTimeout: epoch / 5, + RequestRetryDelay: epoch / 50, MaxRequestRetries: 10, } poetProver := spawnPoet( t, - WithGenesis(time.Now()), + WithGenesis(genesis), WithEpochDuration(epoch), WithPhaseShift(poetCfg.PhaseShift), WithCycleGap(poetCfg.CycleGap), @@ -286,8 +288,6 @@ func TestNewNIPostBuilderNotInitialized(t *testing.T) { mclock := activation.NewMocklayerClock(ctrl) mclock.EXPECT().LayerToTime(gomock.Any()).AnyTimes().DoAndReturn( func(got types.LayerID) time.Time { - // time.Now() ~= currentLayer - genesis := time.Now().Add(-time.Duration(postGenesisEpoch.FirstLayer()) * layerDuration) return genesis.Add(layerDuration * time.Duration(got)) }, ) diff --git a/activation/e2e/validation_test.go b/activation/e2e/validation_test.go index 7e4b505a2c..4ba2ed8bf7 100644 --- a/activation/e2e/validation_test.go +++ b/activation/e2e/validation_test.go @@ -41,10 +41,12 @@ func TestValidator_Validate(t *testing.T) { opts.Scrypt.N = 2 // Speedup initialization in tests. initPost(t, logger.Named("manager"), mgr, opts) + // ensure that genesis aligns with layer timings + genesis := time.Now().Add(layerDuration).Round(layerDuration) epoch := layersPerEpoch * layerDuration poetCfg := activation.PoetConfig{ PhaseShift: epoch / 2, - CycleGap: epoch / 5, + CycleGap: epoch / 4, GracePeriod: epoch / 5, RequestTimeout: epoch / 5, RequestRetryDelay: epoch / 50, @@ -52,7 +54,7 @@ func TestValidator_Validate(t *testing.T) { } poetProver := spawnPoet( t, - WithGenesis(time.Now()), + WithGenesis(genesis), WithEpochDuration(epoch), WithPhaseShift(poetCfg.PhaseShift), WithCycleGap(poetCfg.CycleGap), @@ -61,8 +63,6 @@ func TestValidator_Validate(t *testing.T) { mclock := activation.NewMocklayerClock(ctrl) mclock.EXPECT().LayerToTime(gomock.Any()).AnyTimes().DoAndReturn( func(got types.LayerID) time.Time { - // time.Now() ~= currentLayer - genesis := time.Now().Add(-time.Duration(postGenesisEpoch.FirstLayer()) * layerDuration) return genesis.Add(layerDuration * time.Duration(got)) }, ) diff --git a/common/types/poet.go b/common/types/poet.go index 5e4ef821b0..167c3ec97c 100644 --- a/common/types/poet.go +++ b/common/types/poet.go @@ -111,11 +111,11 @@ func (p *PoetProofMessage) MarshalLogObject(encoder log.ObjectEncoder) error { } // Ref returns the reference to the PoET proof message. It's the blake3 sum of the entire proof message. -func (proofMessage *PoetProofMessage) Ref() (PoetProofRef, error) { - poetProofBytes, err := codec.Encode(&proofMessage.PoetProof) +func (p *PoetProofMessage) Ref() (PoetProofRef, error) { + poetProofBytes, err := codec.Encode(&p.PoetProof) if err != nil { return PoetProofRef{}, fmt.Errorf("failed to marshal poet proof for poetId %x round %v: %w", - proofMessage.PoetServiceID, proofMessage.RoundID, err) + p.PoetServiceID, p.RoundID, err) } h := CalcHash32(poetProofBytes) return (PoetProofRef)(h), nil diff --git a/config/presets/fastnet.go b/config/presets/fastnet.go index 767c838051..ac98f720f0 100644 --- a/config/presets/fastnet.go +++ b/config/presets/fastnet.go @@ -22,7 +22,6 @@ func fastnet() config.Config { conf.BaseConfig.OptFilterThreshold = 90 conf.BaseConfig.DatabasePruneInterval = time.Minute - conf.ATXGradeDelay = 1 * time.Second // set for systest TestEquivocation conf.BaseConfig.MinerGoodAtxsPercent = 50