From a0c2179827220f6713838b7be30a98132cd71156 Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Thu, 30 Apr 2020 15:50:17 +0300 Subject: [PATCH 1/4] unskip on a single shard --- beacon-chain/rpc/beacon/BUILD.bazel | 2 +- beacon-chain/rpc/beacon/blocks_test.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/beacon-chain/rpc/beacon/BUILD.bazel b/beacon-chain/rpc/beacon/BUILD.bazel index 387259b17cfa..db03e67784d4 100644 --- a/beacon-chain/rpc/beacon/BUILD.bazel +++ b/beacon-chain/rpc/beacon/BUILD.bazel @@ -71,7 +71,7 @@ go_test( "validators_test.go", ], embed = [":go_default_library"], - shard_count = 4, + shard_count = 1, deps = [ "//beacon-chain/blockchain/testing:go_default_library", "//beacon-chain/cache:go_default_library", diff --git a/beacon-chain/rpc/beacon/blocks_test.go b/beacon-chain/rpc/beacon/blocks_test.go index c1e560170a48..73ab0dc81a8e 100644 --- a/beacon-chain/rpc/beacon/blocks_test.go +++ b/beacon-chain/rpc/beacon/blocks_test.go @@ -194,7 +194,6 @@ func TestServer_ListBlocks_Pagination(t *testing.T) { db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) ctx := context.Background() - t.Skip("Re-check after PR#5650 is merged") count := uint64(100) blks := make([]*ethpb.SignedBeaconBlock, count) From 93e72b1b8fe4b1759d9092e7907f1aeb614ce54f Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Sat, 2 May 2020 00:26:33 +0300 Subject: [PATCH 2/4] fixes incorrect test state modification --- beacon-chain/rpc/beacon/BUILD.bazel | 1 + beacon-chain/rpc/beacon/attestations_test.go | 3 +- beacon-chain/rpc/beacon/beacon_test.go | 20 ++++ .../rpc/beacon/validators_stream_test.go | 12 ++- beacon-chain/rpc/beacon/validators_test.go | 8 -- shared/params/config.go | 98 ++++++++++++++++++- shared/params/config_test.go | 18 ++++ 7 files changed, 144 insertions(+), 16 deletions(-) create mode 100644 beacon-chain/rpc/beacon/beacon_test.go diff --git a/beacon-chain/rpc/beacon/BUILD.bazel b/beacon-chain/rpc/beacon/BUILD.bazel index ea27215267e2..f41b557f1d4f 100644 --- a/beacon-chain/rpc/beacon/BUILD.bazel +++ b/beacon-chain/rpc/beacon/BUILD.bazel @@ -65,6 +65,7 @@ go_test( srcs = [ "assignments_test.go", "attestations_test.go", + "beacon_test.go", "blocks_test.go", "committees_test.go", "config_test.go", diff --git a/beacon-chain/rpc/beacon/attestations_test.go b/beacon-chain/rpc/beacon/attestations_test.go index 6e2f5b4ce2cb..35e1c8055239 100644 --- a/beacon-chain/rpc/beacon/attestations_test.go +++ b/beacon-chain/rpc/beacon/attestations_test.go @@ -1018,7 +1018,8 @@ func TestServer_StreamIndexedAttestations_ContextCanceled(t *testing.T) { } func TestServer_StreamIndexedAttestations_OK(t *testing.T) { - params.UseMainnetConfig() + resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig()) + defer resetCfg() db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) exitRoutine := make(chan bool) diff --git a/beacon-chain/rpc/beacon/beacon_test.go b/beacon-chain/rpc/beacon/beacon_test.go new file mode 100644 index 000000000000..901d3bb17a9c --- /dev/null +++ b/beacon-chain/rpc/beacon/beacon_test.go @@ -0,0 +1,20 @@ +package beacon + +import ( + "os" + "testing" + + "github.com/prysmaticlabs/prysm/beacon-chain/flags" + "github.com/prysmaticlabs/prysm/shared/params" +) + +func TestMain(m *testing.M) { + // Use minimal config to reduce test setup time. + reset := params.OverrideBeaconConfigWithReset(params.MinimalSpecConfig()) + flags.Init(&flags.GlobalFlags{ + MaxPageSize: 250, + }) + retVal := m.Run() + reset() + os.Exit(retVal) +} diff --git a/beacon-chain/rpc/beacon/validators_stream_test.go b/beacon-chain/rpc/beacon/validators_stream_test.go index eef8d0242b81..cc0afd26ba9d 100644 --- a/beacon-chain/rpc/beacon/validators_stream_test.go +++ b/beacon-chain/rpc/beacon/validators_stream_test.go @@ -10,7 +10,8 @@ import ( ) func TestInfostream_EpochToTimestamp(t *testing.T) { - params.UseMainnetConfig() + resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig()) + defer resetCfg() tests := []struct { name string epoch uint64 @@ -48,7 +49,8 @@ func TestInfostream_EpochToTimestamp(t *testing.T) { } func TestInfostream_HandleSetValidatorKeys(t *testing.T) { - params.UseMainnetConfig() + resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig()) + defer resetCfg() tests := []struct { name string reqPubKeys [][]byte @@ -86,7 +88,8 @@ func TestInfostream_HandleSetValidatorKeys(t *testing.T) { } func TestInfostream_HandleAddValidatorKeys(t *testing.T) { - params.UseMainnetConfig() + resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig()) + defer resetCfg() tests := []struct { name string initialPubKeys [][]byte @@ -137,7 +140,8 @@ func TestInfostream_HandleAddValidatorKeys(t *testing.T) { } func TestInfostream_HandleRemoveValidatorKeys(t *testing.T) { - params.UseMainnetConfig() + resetCfg := params.OverrideBeaconConfigWithReset(params.MainnetConfig()) + defer resetCfg() tests := []struct { name string initialPubKeys [][]byte diff --git a/beacon-chain/rpc/beacon/validators_test.go b/beacon-chain/rpc/beacon/validators_test.go index 2ee2ad12acbc..51c3a591f32b 100644 --- a/beacon-chain/rpc/beacon/validators_test.go +++ b/beacon-chain/rpc/beacon/validators_test.go @@ -31,14 +31,6 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" ) -func init() { - // Use minimal config to reduce test setup time. - params.OverrideBeaconConfig(params.MinimalSpecConfig()) - flags.Init(&flags.GlobalFlags{ - MaxPageSize: 250, - }) -} - func TestServer_GetValidatorActiveSetChanges_CannotRequestFutureEpoch(t *testing.T) { db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) diff --git a/shared/params/config.go b/shared/params/config.go index b5a5c650ce97..9111a18b179f 100644 --- a/shared/params/config.go +++ b/shared/params/config.go @@ -205,9 +205,9 @@ var defaultBeaconConfig = &BeaconChainConfig{ PruneSlasherStoragePeriod: 10, // Fork related values. - GenesisForkVersion: []byte{0, 0, 0, 0}, - NextForkVersion: []byte{0, 0, 0, 0}, // Set to GenesisForkVersion unless there is a scheduled fork - NextForkEpoch: 1<<64 - 1, // Set to FarFutureEpoch unless there is a scheduled fork. + GenesisForkVersion: []byte{0, 0, 0, 0}, + NextForkVersion: []byte{0, 0, 0, 0}, // Set to GenesisForkVersion unless there is a scheduled fork + NextForkEpoch: 1<<64 - 1, // Set to FarFutureEpoch unless there is a scheduled fork. ForkVersionSchedule: map[uint64][]byte{ // Any further forks must be specified here by their epoch number. }, @@ -315,3 +315,95 @@ func UseMainnetConfig() { func OverrideBeaconConfig(c *BeaconChainConfig) { beaconConfig = c } + +// OverrideBeaconConfigWithReset replaces config and returns reset function +// that helps returning back to the previous state. Useful in tests. +func OverrideBeaconConfigWithReset(c *BeaconChainConfig) func() { + origConfig := beaconConfig.Copy() + OverrideBeaconConfig(c) + return func() { + OverrideBeaconConfig(origConfig) + } +} + +// Copy returns copy of the config object. +func (c *BeaconChainConfig) Copy() *BeaconChainConfig { + return &BeaconChainConfig{ + FarFutureEpoch: c.FarFutureEpoch, + BaseRewardsPerEpoch: c.BaseRewardsPerEpoch, + DepositContractTreeDepth: c.DepositContractTreeDepth, + MinGenesisDelay: c.MinGenesisDelay, + TargetCommitteeSize: c.TargetCommitteeSize, + MaxValidatorsPerCommittee: c.MaxValidatorsPerCommittee, + MaxCommitteesPerSlot: c.MaxCommitteesPerSlot, + MinPerEpochChurnLimit: c.MinPerEpochChurnLimit, + ChurnLimitQuotient: c.ChurnLimitQuotient, + ShuffleRoundCount: c.ShuffleRoundCount, + MinGenesisActiveValidatorCount: c.MinGenesisActiveValidatorCount, + MinGenesisTime: c.MinGenesisTime, + TargetAggregatorsPerCommittee: c.TargetAggregatorsPerCommittee, + HysteresisQuotient: c.HysteresisQuotient, + HysteresisDownwardMultiplier: c.HysteresisDownwardMultiplier, + HysteresisUpwardMultiplier: c.HysteresisUpwardMultiplier, + MinDepositAmount: c.MinDepositAmount, + MaxEffectiveBalance: c.MaxEffectiveBalance, + EjectionBalance: c.EjectionBalance, + EffectiveBalanceIncrement: c.EffectiveBalanceIncrement, + BLSWithdrawalPrefixByte: c.BLSWithdrawalPrefixByte, + ZeroHash: c.ZeroHash, + MinAttestationInclusionDelay: c.MinAttestationInclusionDelay, + SecondsPerSlot: c.SecondsPerSlot, + SlotsPerEpoch: c.SlotsPerEpoch, + MinSeedLookahead: c.MinSeedLookahead, + MaxSeedLookahead: c.MaxSeedLookahead, + EpochsPerEth1VotingPeriod: c.EpochsPerEth1VotingPeriod, + SlotsPerHistoricalRoot: c.SlotsPerHistoricalRoot, + MinValidatorWithdrawabilityDelay: c.MinValidatorWithdrawabilityDelay, + PersistentCommitteePeriod: c.PersistentCommitteePeriod, + MinEpochsToInactivityPenalty: c.MinEpochsToInactivityPenalty, + Eth1FollowDistance: c.Eth1FollowDistance, + SafeSlotsToUpdateJustified: c.SafeSlotsToUpdateJustified, + SecondsPerETH1Block: c.SecondsPerETH1Block, + EpochsPerHistoricalVector: c.EpochsPerHistoricalVector, + EpochsPerSlashingsVector: c.EpochsPerSlashingsVector, + HistoricalRootsLimit: c.HistoricalRootsLimit, + ValidatorRegistryLimit: c.ValidatorRegistryLimit, + BaseRewardFactor: c.BaseRewardFactor, + WhistleBlowerRewardQuotient: c.WhistleBlowerRewardQuotient, + ProposerRewardQuotient: c.ProposerRewardQuotient, + InactivityPenaltyQuotient: c.InactivityPenaltyQuotient, + MinSlashingPenaltyQuotient: c.MinSlashingPenaltyQuotient, + MaxProposerSlashings: c.MaxProposerSlashings, + MaxAttesterSlashings: c.MaxAttesterSlashings, + MaxAttestations: c.MaxAttestations, + MaxDeposits: c.MaxDeposits, + MaxVoluntaryExits: c.MaxVoluntaryExits, + DomainBeaconProposer: c.DomainBeaconProposer, + DomainRandao: c.DomainRandao, + DomainBeaconAttester: c.DomainBeaconAttester, + DomainDeposit: c.DomainDeposit, + DomainVoluntaryExit: c.DomainVoluntaryExit, + DomainSelectionProof: c.DomainSelectionProof, + DomainAggregateAndProof: c.DomainAggregateAndProof, + GweiPerEth: c.GweiPerEth, + LogBlockDelay: c.LogBlockDelay, + BLSSecretKeyLength: c.BLSSecretKeyLength, + BLSPubkeyLength: c.BLSPubkeyLength, + BLSSignatureLength: c.BLSSignatureLength, + DefaultBufferSize: c.DefaultBufferSize, + ValidatorPrivkeyFileName: c.ValidatorPrivkeyFileName, + WithdrawalPrivkeyFileName: c.WithdrawalPrivkeyFileName, + RPCSyncCheck: c.RPCSyncCheck, + GoerliBlockTime: c.GoerliBlockTime, + EmptySignature: c.EmptySignature, + DefaultPageSize: c.DefaultPageSize, + MaxPeersToSync: c.MaxPeersToSync, + SlotsPerArchivedPoint: c.SlotsPerArchivedPoint, + WeakSubjectivityPeriod: c.WeakSubjectivityPeriod, + PruneSlasherStoragePeriod: c.PruneSlasherStoragePeriod, + GenesisForkVersion: c.GenesisForkVersion, + NextForkVersion: c.NextForkVersion, + NextForkEpoch: c.NextForkEpoch, + ForkVersionSchedule: c.ForkVersionSchedule, + } +} diff --git a/shared/params/config_test.go b/shared/params/config_test.go index 7f7a0fe5bb8b..71bc89ced624 100644 --- a/shared/params/config_test.go +++ b/shared/params/config_test.go @@ -14,3 +14,21 @@ func TestOverrideBeaconConfig(t *testing.T) { t.Errorf("Shardcount in BeaconConfig incorrect. Wanted %d, got %d", 5, c.SlotsPerEpoch) } } + +func TestOverrideBeaconConfigWithReset(t *testing.T) { + cfg := params.BeaconConfig().Copy() + + origSlotsPerEpoch := cfg.SlotsPerEpoch + newSlotsPerEpoch := origSlotsPerEpoch + 42 + + cfg.SlotsPerEpoch = newSlotsPerEpoch + resetFunc := params.OverrideBeaconConfigWithReset(cfg) + if c := params.BeaconConfig(); c.SlotsPerEpoch != newSlotsPerEpoch { + t.Errorf("Config value is incorrect, want: %d, got %d", newSlotsPerEpoch, c.SlotsPerEpoch) + } + + resetFunc() + if c := params.BeaconConfig(); c.SlotsPerEpoch != origSlotsPerEpoch { + t.Errorf("Config value is incorrect, want: %d, got %d", origSlotsPerEpoch, c.SlotsPerEpoch) + } +} From 15ae58feda987724e02b2fcc88f34b238c7ba2c8 Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Sat, 2 May 2020 00:31:19 +0300 Subject: [PATCH 3/4] minor formatting --- shared/params/config_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/shared/params/config_test.go b/shared/params/config_test.go index 71bc89ced624..b01e51643691 100644 --- a/shared/params/config_test.go +++ b/shared/params/config_test.go @@ -17,7 +17,6 @@ func TestOverrideBeaconConfig(t *testing.T) { func TestOverrideBeaconConfigWithReset(t *testing.T) { cfg := params.BeaconConfig().Copy() - origSlotsPerEpoch := cfg.SlotsPerEpoch newSlotsPerEpoch := origSlotsPerEpoch + 42 From 60b4ae563df20300ce1e007466ab804b0be51ace Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Sat, 2 May 2020 00:54:48 +0300 Subject: [PATCH 4/4] set sharding back to 4 --- beacon-chain/rpc/beacon/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon-chain/rpc/beacon/BUILD.bazel b/beacon-chain/rpc/beacon/BUILD.bazel index f41b557f1d4f..26310ca6eca7 100644 --- a/beacon-chain/rpc/beacon/BUILD.bazel +++ b/beacon-chain/rpc/beacon/BUILD.bazel @@ -75,7 +75,7 @@ go_test( "validators_test.go", ], embed = [":go_default_library"], - shard_count = 1, + shard_count = 4, deps = [ "//beacon-chain/blockchain/testing:go_default_library", "//beacon-chain/cache:go_default_library",