Fixed a bug in ActivatedValidatorIndices (#5400)

This commit is contained in:
terence tsao 2020-04-12 16:20:50 -07:00 committed by GitHub
parent c76034147e
commit a85bf9305d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 10 deletions

View File

@ -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")
}

View File

@ -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))
}
}

View File

@ -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,
},
},
},

View File

@ -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