PR feedback on `exit_random_validators` helper
This commit is contained in:
parent
be6d2017bb
commit
40869d6e39
|
@ -39,7 +39,7 @@ def test_transition_with_one_fourth_exiting_validators_exit_post_fork(state,
|
|||
rng=random.Random(5566),
|
||||
fraction=0.25,
|
||||
exit_epoch=10,
|
||||
forward=False,
|
||||
from_epoch=spec.get_current_epoch(state),
|
||||
)
|
||||
|
||||
transition_until_fork(spec, state, fork_epoch)
|
||||
|
@ -97,7 +97,7 @@ def test_transition_with_one_fourth_exiting_validators_exit_at_fork(state,
|
|||
rng=random.Random(5566),
|
||||
fraction=0.25,
|
||||
exit_epoch=fork_epoch,
|
||||
forward=False,
|
||||
from_epoch=spec.get_current_epoch(state),
|
||||
)
|
||||
|
||||
transition_until_fork(spec, state, fork_epoch)
|
||||
|
|
|
@ -25,16 +25,17 @@ def set_some_new_deposits(spec, state, rng):
|
|||
return deposited_indices
|
||||
|
||||
|
||||
def exit_random_validators(spec, state, rng, fraction=0.5, exit_epoch=None, withdrawable_epoch=None, forward=True):
|
||||
def exit_random_validators(spec, state, rng, fraction=0.5, exit_epoch=None, withdrawable_epoch=None, from_epoch=None):
|
||||
"""
|
||||
Set some validators' exit_epoch and withdrawable_epoch.
|
||||
|
||||
If exit_epoch is configured, use the given exit_epoch. Otherwise, randomly set exit_epoch and withdrawable_epoch.
|
||||
"""
|
||||
if forward:
|
||||
if spec.get_current_epoch(state) < 5:
|
||||
# Move epochs forward to allow for some validators already exited/withdrawable
|
||||
for _ in range(5):
|
||||
if from_epoch is None:
|
||||
from_epoch = spec.MAX_SEED_LOOKAHEAD + 1
|
||||
epoch_diff = from_epoch - spec.get_current_epoch(state)
|
||||
for _ in range(epoch_diff):
|
||||
# NOTE: if `epoch_diff` is negative, then this loop body does not execute.
|
||||
next_epoch(spec, state)
|
||||
|
||||
current_epoch = spec.get_current_epoch(state)
|
||||
|
|
Loading…
Reference in New Issue