From a85bf9305dcdc4e9d5b2bfedfdb34ca12590d7d5 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sun, 12 Apr 2020 16:20:50 -0700 Subject: [PATCH] Fixed a bug in ActivatedValidatorIndices (#5400) --- beacon-chain/archiver/service_test.go | 4 ++-- beacon-chain/core/validators/validator.go | 3 +-- beacon-chain/core/validators/validator_test.go | 14 +++++++++----- beacon-chain/rpc/beacon/validators_test.go | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/beacon-chain/archiver/service_test.go b/beacon-chain/archiver/service_test.go index fda1806839..ac59b94450 100644 --- a/beacon-chain/archiver/service_test.go +++ b/beacon-chain/archiver/service_test.go @@ -317,8 +317,8 @@ func TestArchiverService_SavesActivatedValidatorChanges(t *testing.T) { if retrieved == nil { t.Fatal("Retrieved indices are nil") } - if !reflect.DeepEqual(retrieved.Activated, []uint64{4, 5}) { - t.Errorf("Wanted indices 4 5 activated, received %v", retrieved.Activated) + if len(retrieved.Activated) != 98 { + t.Error("Did not get wanted active length") } testutil.AssertLogsContain(t, hook, "Successfully archived") } diff --git a/beacon-chain/core/validators/validator.go b/beacon-chain/core/validators/validator.go index 16ccadf73e..03d57c57a2 100644 --- a/beacon-chain/core/validators/validator.go +++ b/beacon-chain/core/validators/validator.go @@ -169,10 +169,9 @@ func SlashValidator(state *stateTrie.BeaconState, slashedIdx uint64, whistleBlow // ActivatedValidatorIndices determines the indices activated during the given epoch. func ActivatedValidatorIndices(epoch uint64, validators []*ethpb.Validator) []uint64 { activations := make([]uint64, 0) - delayedActivationEpoch := helpers.ActivationExitEpoch(epoch) for i := 0; i < len(validators); i++ { val := validators[i] - if val.ActivationEpoch == delayedActivationEpoch { + if val.ActivationEpoch <= epoch && epoch < val.ExitEpoch { activations = append(activations, uint64(i)) } } diff --git a/beacon-chain/core/validators/validator_test.go b/beacon-chain/core/validators/validator_test.go index 46477b37bf..ace93e599b 100644 --- a/beacon-chain/core/validators/validator_test.go +++ b/beacon-chain/core/validators/validator_test.go @@ -223,16 +223,19 @@ func TestActivatedValidatorIndices(t *testing.T) { Slot: 0, Validators: []*ethpb.Validator{ { - ActivationEpoch: helpers.ActivationExitEpoch(0), + ActivationEpoch: 0, + ExitEpoch: 1, }, { - ActivationEpoch: helpers.ActivationExitEpoch(0), + ActivationEpoch: 0, + ExitEpoch: 1, }, { - ActivationEpoch: helpers.ActivationExitEpoch(5), + ActivationEpoch: 5, }, { - ActivationEpoch: helpers.ActivationExitEpoch(0), + ActivationEpoch: 0, + ExitEpoch: 1, }, }, }, @@ -254,7 +257,8 @@ func TestActivatedValidatorIndices(t *testing.T) { Slot: 0, Validators: []*ethpb.Validator{ { - ActivationEpoch: helpers.ActivationExitEpoch(0), + ActivationEpoch: 0, + ExitEpoch: 1, }, }, }, diff --git a/beacon-chain/rpc/beacon/validators_test.go b/beacon-chain/rpc/beacon/validators_test.go index 60c953b047..97eb17b8a3 100644 --- a/beacon-chain/rpc/beacon/validators_test.go +++ b/beacon-chain/rpc/beacon/validators_test.go @@ -1173,7 +1173,7 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) { balance := params.BeaconConfig().MaxEffectiveBalance // Mark indices divisible by two as activated. if i%2 == 0 { - activationEpoch = helpers.ActivationExitEpoch(0) + activationEpoch = 0 } else if i%3 == 0 { // Mark indices divisible by 3 as slashed. withdrawableEpoch = params.BeaconConfig().EpochsPerSlashingsVector