From 06eed71856ad4a838ff3d7831f4df29fb06a086e Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 15 Mar 2021 13:10:19 -0600 Subject: [PATCH] fix altair test generators --- .../eth2spec/test/altair/fork/test_fork.py | 4 ++++ .../pyspec/eth2spec/test/helpers/rewards.py | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/fork/test_fork.py b/tests/core/pyspec/eth2spec/test/altair/fork/test_fork.py index 9667c2e37..fb056b72a 100644 --- a/tests/core/pyspec/eth2spec/test/altair/fork/test_fork.py +++ b/tests/core/pyspec/eth2spec/test/altair/fork/test_fork.py @@ -1,7 +1,9 @@ from eth2spec.test.context import ( PHASE0, ALTAIR, + MINIMAL, with_phases, with_custom_state, + with_configs, spec_test, with_state, low_balances, misc_balances, large_validator_set, ) @@ -106,6 +108,8 @@ def test_fork_random_misc_balances(spec, phases, state): @with_phases(phases=[PHASE0], other_phases=[ALTAIR]) +@with_configs([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") @with_custom_state(balances_fn=large_validator_set, threshold_fn=lambda spec: spec.EJECTION_BALANCE) @spec_test @with_meta_tags(ALTAIR_FORK_TEST_META_TAGS) diff --git a/tests/core/pyspec/eth2spec/test/helpers/rewards.py b/tests/core/pyspec/eth2spec/test/helpers/rewards.py index 8d34500b6..9360392d4 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/rewards.py +++ b/tests/core/pyspec/eth2spec/test/helpers/rewards.py @@ -27,6 +27,26 @@ def has_enough_for_reward(spec, state, index): ) +def has_enough_for_leak_penalty(spec, state, index): + """ + Check if effective_balance and state of leak is high enough for a leak penalty. + + At very low balances / leak values, it is possible for a validator have a positive effective_balance + and be in a leak, but have zero leak penalty. + """ + + if is_post_altair(spec): + return ( + state.validators[index].effective_balance * state.inactivity_scores[index] + > spec.INACTIVITY_SCORE_BIAS * spec.INACTIVITY_PENALTY_QUOTIENT_ALTAIR + ) + else: + return ( + state.validators[index].effective_balance * spec.get_finality_delay(state) + > spec.INACTIVITY_PENALTY_QUOTIENT + ) + + def run_deltas(spec, state): """ Run all deltas functions yielding: @@ -213,7 +233,7 @@ def run_get_inactivity_penalty_deltas(spec, state): if not has_enough_for_reward(spec, state, index): assert penalties[index] == 0 - elif index in matching_attesting_indices: + elif index in matching_attesting_indices or not has_enough_for_leak_penalty(spec, state, index): assert penalties[index] == base_penalty else: assert penalties[index] > base_penalty