prevent validator exit reentrance (#2443)

This commit is contained in:
terence tsao 2019-04-29 16:25:31 -07:00 committed by GitHub
parent 3f742d79c0
commit 7a7b4e55c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -206,11 +206,10 @@ func InitiateValidatorExit(state *pb.BeaconState, idx uint64) *pb.BeaconState {
func ExitValidator(state *pb.BeaconState, idx uint64) *pb.BeaconState {
validator := state.ValidatorRegistry[idx]
exitEpoch := entryExitEffectEpoch(helpers.CurrentEpoch(state))
if validator.ExitEpoch <= exitEpoch {
if validator.ExitEpoch != params.BeaconConfig().FarFutureEpoch {
return state
}
validator.ExitEpoch = exitEpoch
validator.ExitEpoch = entryExitEffectEpoch(helpers.CurrentEpoch(state))
return state
}

View File

@ -430,14 +430,14 @@ func TestExitValidator_OK(t *testing.T) {
func TestExitValidator_AlreadyExited(t *testing.T) {
state := &pb.BeaconState{
Slot: 1,
Slot: params.BeaconConfig().GenesisEpoch + 1000,
ValidatorRegistry: []*pb.Validator{
{ExitEpoch: params.BeaconConfig().ActivationExitDelay},
},
}
state = ExitValidator(state, 0)
if len(state.ValidatorRegistry) != 1 {
t.Error("Expected validator to have failed exiting")
if state.ValidatorRegistry[0].ExitEpoch != params.BeaconConfig().ActivationExitDelay {
t.Error("Expected exited validator to stay exited")
}
}