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),
|
rng=random.Random(5566),
|
||||||
fraction=0.25,
|
fraction=0.25,
|
||||||
exit_epoch=10,
|
exit_epoch=10,
|
||||||
forward=False,
|
from_epoch=spec.get_current_epoch(state),
|
||||||
)
|
)
|
||||||
|
|
||||||
transition_until_fork(spec, state, fork_epoch)
|
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),
|
rng=random.Random(5566),
|
||||||
fraction=0.25,
|
fraction=0.25,
|
||||||
exit_epoch=fork_epoch,
|
exit_epoch=fork_epoch,
|
||||||
forward=False,
|
from_epoch=spec.get_current_epoch(state),
|
||||||
)
|
)
|
||||||
|
|
||||||
transition_until_fork(spec, state, fork_epoch)
|
transition_until_fork(spec, state, fork_epoch)
|
||||||
|
|
|
@ -25,17 +25,18 @@ def set_some_new_deposits(spec, state, rng):
|
||||||
return deposited_indices
|
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.
|
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 exit_epoch is configured, use the given exit_epoch. Otherwise, randomly set exit_epoch and withdrawable_epoch.
|
||||||
"""
|
"""
|
||||||
if forward:
|
if from_epoch is None:
|
||||||
if spec.get_current_epoch(state) < 5:
|
from_epoch = spec.MAX_SEED_LOOKAHEAD + 1
|
||||||
# Move epochs forward to allow for some validators already exited/withdrawable
|
epoch_diff = from_epoch - spec.get_current_epoch(state)
|
||||||
for _ in range(5):
|
for _ in range(epoch_diff):
|
||||||
next_epoch(spec, state)
|
# NOTE: if `epoch_diff` is negative, then this loop body does not execute.
|
||||||
|
next_epoch(spec, state)
|
||||||
|
|
||||||
current_epoch = spec.get_current_epoch(state)
|
current_epoch = spec.get_current_epoch(state)
|
||||||
exited_indices = []
|
exited_indices = []
|
||||||
|
|
Loading…
Reference in New Issue