Skip to content

Commit

Permalink
Merge pull request #4975 from onflow/jordan/vn-test-block-rate-fix
Browse files Browse the repository at this point in the history
[Flaky Test] Modifies block rate in VN test to address sealing lagging finalization
  • Loading branch information
jordanschalm authored Nov 9, 2023
2 parents c8f0ef2 + 54bdfc2 commit 9f00fa6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion engine/access/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const DefaultMaxHeightRange = 250

// DefaultSnapshotHistoryLimit the amount of blocks to look back in state
// when recursively searching for a valid snapshot
const DefaultSnapshotHistoryLimit = 50
const DefaultSnapshotHistoryLimit = 500

// DefaultLoggedScriptsCacheSize is the default size of the lookup cache used to dedupe logs of scripts sent to ENs
// limiting cache size to 16MB and does not affect script execution, only for keeping logs tidy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cohort2

import (
"testing"
"time"

"github.com/stretchr/testify/suite"

Expand All @@ -20,6 +21,8 @@ type EpochJoinAndLeaveVNSuite struct {
func (s *EpochJoinAndLeaveVNSuite) SetupTest() {
// require approvals for seals to verify that the joining VN is producing valid seals in the second epoch
s.RequiredSealApprovals = 1
// slow down consensus, as sealing tends to lag behind
s.ConsensusProposalDuration = time.Millisecond * 250
// increase epoch length to account for greater sealing lag due to above
// NOTE: this value is set fairly aggressively to ensure shorter test times.
// If flakiness due to failure to complete staking operations in time is observed,
Expand All @@ -28,7 +31,7 @@ func (s *EpochJoinAndLeaveVNSuite) SetupTest() {
s.DKGPhaseLen = 100
s.EpochLen = 450
s.EpochCommitSafetyThreshold = 20
s.DynamicEpochTransitionSuite.SetupTest()
s.DynamicEpochTransitionSuite.Suite.SetupTest()
}

// TestEpochJoinAndLeaveVN should update verification nodes and assert healthy network conditions
Expand Down
18 changes: 13 additions & 5 deletions integration/tests/epochs/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ type Suite struct {
// Whether approvals are required for sealing (we only enable for VN tests because
// requiring approvals requires a longer DKG period to avoid flakiness)
RequiredSealApprovals uint // defaults to 0 (no approvals required)
// Consensus Node proposal duration
ConsensusProposalDuration time.Duration
}

// SetupTest is run automatically by the testing framework before each test case.
func (s *Suite) SetupTest() {
// If unset, use default value 100ms
if s.ConsensusProposalDuration == 0 {
s.ConsensusProposalDuration = time.Millisecond * 100
}

minEpochLength := s.StakingAuctionLen + s.DKGPhaseLen*3 + 20
// ensure epoch lengths are set correctly
Expand All @@ -85,7 +91,7 @@ func (s *Suite) SetupTest() {
testnet.WithLogLevel(zerolog.WarnLevel)}

consensusConfigs := []func(config *testnet.NodeConfig){
testnet.WithAdditionalFlag("--cruise-ctl-fallback-proposal-duration=100ms"),
testnet.WithAdditionalFlag(fmt.Sprintf("--cruise-ctl-fallback-proposal-duration=%s", s.ConsensusProposalDuration)),
testnet.WithAdditionalFlag(fmt.Sprintf("--required-verification-seal-approvals=%d", s.RequiredSealApprovals)),
testnet.WithAdditionalFlag(fmt.Sprintf("--required-construction-seal-approvals=%d", s.RequiredSealApprovals)),
testnet.WithLogLevel(zerolog.WarnLevel)}
Expand Down Expand Up @@ -451,18 +457,20 @@ func (s *Suite) getContainerToReplace(role flow.Role) *testnet.Container {

// AwaitEpochPhase waits for the given phase, in the given epoch.
func (s *Suite) AwaitEpochPhase(ctx context.Context, expectedEpoch uint64, expectedPhase flow.EpochPhase, waitFor, tick time.Duration) {
var actualEpoch uint64
var actualPhase flow.EpochPhase
condition := func() bool {
snapshot, err := s.Client.GetLatestProtocolSnapshot(ctx)
require.NoError(s.T(), err)

actualEpoch, err := snapshot.Epochs().Current().Counter()
actualEpoch, err = snapshot.Epochs().Current().Counter()
require.NoError(s.T(), err)
actualPhase, err := snapshot.Phase()
actualPhase, err = snapshot.Phase()
require.NoError(s.T(), err)

return actualEpoch == expectedEpoch && actualPhase == expectedPhase
}
require.Eventuallyf(s.T(), condition, waitFor, tick, "did not reach expectedEpoch %d phase %s within %s", expectedEpoch, expectedPhase, waitFor)
require.Eventuallyf(s.T(), condition, waitFor, tick, "did not reach expectedEpoch %d phase %s within %s. Last saw epoch=%d and phase=%s", expectedEpoch, expectedPhase, waitFor, actualEpoch, actualPhase)
}

// AssertInEpochPhase checks if we are in the phase of the given epoch.
Expand Down Expand Up @@ -640,7 +648,7 @@ func (s *Suite) RunTestEpochJoinAndLeave(role flow.Role, checkNetworkHealth node

// wait for epoch setup phase before we start our container and pause the old container
s.TimedLogf("waiting for EpochSetup phase of first epoch to begin")
s.AwaitEpochPhase(s.Ctx, 0, flow.EpochPhaseSetup, 3*time.Minute, 500*time.Millisecond)
s.AwaitEpochPhase(s.Ctx, 0, flow.EpochPhaseSetup, time.Minute, 500*time.Millisecond)
s.TimedLogf("successfully reached EpochSetup phase of first epoch")

// get the latest snapshot and start new container with it
Expand Down
20 changes: 10 additions & 10 deletions integration/tests/lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,28 +220,28 @@ func WithChainID(chainID flow.ChainID) func(tx *sdk.Transaction) {

// LogStatus logs current information about the test network state.
func LogStatus(t *testing.T, ctx context.Context, log zerolog.Logger, client *testnet.Client) {
// retrieves latest FINALIZED snapshot
snapshot, err := client.GetLatestProtocolSnapshot(ctx)
if err != nil {
log.Err(err).Msg("failed to get sealed snapshot")
return
}
finalized, err := client.GetLatestFinalizedBlockHeader(ctx)
if err != nil {
log.Err(err).Msg("failed to get finalized header")
log.Err(err).Msg("failed to get finalized snapshot")
return
}

sealed, err := snapshot.Head()
sealingSegment, err := snapshot.SealingSegment()
require.NoError(t, err)
sealed := sealingSegment.Sealed()
finalized := sealingSegment.Finalized()

phase, err := snapshot.Phase()
require.NoError(t, err)
epoch := snapshot.Epochs().Current()
counter, err := epoch.Counter()
require.NoError(t, err)

log.Info().Uint64("final_height", finalized.Height).
Uint64("sealed_height", sealed.Height).
Uint64("sealed_view", sealed.View).
log.Info().Uint64("final_height", finalized.Header.Height).
Uint64("final_view", finalized.Header.View).
Uint64("sealed_height", sealed.Header.Height).
Uint64("sealed_view", sealed.Header.View).
Str("cur_epoch_phase", phase.String()).
Uint64("cur_epoch_counter", counter).
Msg("test run status")
Expand Down

0 comments on commit 9f00fa6

Please sign in to comment.