diff --git a/specs/phase0/beacon-chain.md b/specs/phase0/beacon-chain.md index 82fbb2856..fe8fcc9bd 100644 --- a/specs/phase0/beacon-chain.md +++ b/specs/phase0/beacon-chain.md @@ -1370,8 +1370,8 @@ def get_attestation_component_deltas(state: BeaconState, """ Helper with shared logic for use by get source, target, and head deltas functions """ - rewards = [Gwei(0) for _ in range(len(state.validators))] - penalties = [Gwei(0) for _ in range(len(state.validators))] + rewards = [Gwei(0)] * len(state.validators) + penalties = [Gwei(0)] * len(state.validators) total_balance = get_total_active_balance(state) unslashed_attesting_indices = get_unslashed_attesting_indices(state, attestations) attesting_balance = get_total_balance(state, unslashed_attesting_indices) diff --git a/tests/core/pyspec/eth2spec/test/helpers/rewards.py b/tests/core/pyspec/eth2spec/test/helpers/rewards.py index deee1b120..6e470d9e9 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/rewards.py +++ b/tests/core/pyspec/eth2spec/test/helpers/rewards.py @@ -1,12 +1,13 @@ from random import Random +from eth2spec.phase0 import spec as spec_phase0 from eth2spec.test.helpers.attestations import prepare_state_with_full_attestations from eth2spec.utils.ssz.ssz_typing import Container, uint64, List -# HACK to get the generators outputting correctly class Deltas(Container): - delta_list: List[uint64, 2**30] + rewards: List[uint64, spec_phase0.VALIDATOR_REGISTRY_LIMIT] + penalties: List[uint64, spec_phase0.VALIDATOR_REGISTRY_LIMIT] def has_enough_for_reward(spec, state, index): @@ -33,8 +34,7 @@ def run_attestation_component_deltas(spec, state, component_delta_fn, matching_a rewards, penalties = component_delta_fn(state) - yield 'rewards', Deltas(delta_list=rewards) - yield 'penalties', Deltas(delta_list=penalties) + yield 'deltas', Deltas(rewards=rewards, penalties=penalties) matching_attestations = matching_att_fn(state, spec.get_previous_epoch(state)) matching_indices = spec.get_unslashed_attesting_indices(state, matching_attestations) diff --git a/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inactivity_penalty_deltas.py b/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inactivity_penalty_deltas.py index fb24e09d8..657acbdbb 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inactivity_penalty_deltas.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inactivity_penalty_deltas.py @@ -1,13 +1,8 @@ from eth2spec.test.context import with_all_phases, spec_state_test from eth2spec.test.helpers.rewards import has_enough_for_reward from eth2spec.test.helpers.state import next_epoch +from eth2spec.test.helpers.rewards import Deltas import eth2spec.test.helpers.rewards as rewards_helpers -from eth2spec.utils.ssz.ssz_typing import Container, uint64, List - - -# HACK to get the generators outputting correctly -class Deltas(Container): - delta_list: List[uint64, 2**30] def run_get_inactivity_penalty_deltas(spec, state): @@ -22,8 +17,7 @@ def run_get_inactivity_penalty_deltas(spec, state): rewards, penalties = spec.get_inactivity_penalty_deltas(state) - yield 'rewards', Deltas(delta_list=rewards) - yield 'penalties', Deltas(delta_list=penalties) + yield 'deltas', Deltas(rewards=rewards, penalties=penalties) matching_attestations = spec.get_matching_target_attestations(state, spec.get_previous_epoch(state)) matching_attesting_indices = spec.get_unslashed_attesting_indices(state, matching_attestations) diff --git a/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inclusion_delay_deltas.py b/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inclusion_delay_deltas.py index 9eda75290..320f59a9d 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inclusion_delay_deltas.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/rewards/test_get_inclusion_delay_deltas.py @@ -2,14 +2,8 @@ from random import Random from eth2spec.test.context import with_all_phases, spec_state_test from eth2spec.test.helpers.attestations import prepare_state_with_full_attestations -from eth2spec.test.helpers.rewards import has_enough_for_reward +from eth2spec.test.helpers.rewards import Deltas, has_enough_for_reward import eth2spec.test.helpers.rewards as rewards_helpers -from eth2spec.utils.ssz.ssz_typing import Container, uint64, List - - -# HACK to get the generators outputting correctly -class Deltas(Container): - delta_list: List[uint64, 2**30] def run_get_inclusion_delay_deltas(spec, state): @@ -24,8 +18,7 @@ def run_get_inclusion_delay_deltas(spec, state): rewards, penalties = spec.get_inclusion_delay_deltas(state) - yield 'rewards', Deltas(delta_list=rewards) - yield 'penalties', Deltas(delta_list=penalties) + yield 'deltas', Deltas(rewards=rewards, penalties=penalties) eligible_attestations = spec.get_matching_source_attestations(state, spec.get_previous_epoch(state)) attesting_indices = spec.get_unslashed_attesting_indices(state, eligible_attestations) diff --git a/tests/formats/rewards/README.md b/tests/formats/rewards/README.md index dce2b5ac8..bffe2e7de 100644 --- a/tests/formats/rewards/README.md +++ b/tests/formats/rewards/README.md @@ -4,7 +4,6 @@ The different rewards deltas sub-functions are testing individually with the tes There is no "change" factor, the rewards/penalties outputs are pure functions with just the pre-state as input. Hence, the format is shared between each test-handler. (See test condition documentation on how to run the tests.) - ## Test case format ### `meta.yaml` @@ -12,23 +11,29 @@ Hence, the format is shared between each test-handler. (See test condition docum ```yaml description: string -- Optional description of test case, purely for debugging purposes. Tests should use the directory name of the test case as identifier, not the description. -bls_setting: int -- see general test-format spec. ``` +_Note_: No signature verification happens within rewards sub-functions. These + tests can safely be run with or without BLS enabled. + ### `pre.yaml` A YAML-encoded `BeaconState`, the state before running the rewards sub-function. Also available as `pre.ssz`. +### `deltas.yaml` -### `rewards.yaml` +A YAML-encoded `Deltas` representing the rewards and penalties returned by the rewards sub-function -A YAML-encoded list of integers representing the 0th item in the return value (i.e. the rewards deltas) +Where `Deltas` is defined as: +```python +class Deltas(Container): + rewards: List[uint64, VALIDATOR_REGISTRY_LIMIT] + penalties: List[uint64, VALIDATOR_REGISTRY_LIMIT] +``` -### `penalties.yaml` - -A YAML-encoded list of integers representing the 1st item in the return value (i.e. the penalties deltas) +Also available as `rewards.ssz`. ## Condition @@ -38,10 +43,10 @@ This excludes all other parts of `process_rewards_and_penalties` The provided pre-state is ready to be input into the designated handler. -The resulting `rewards`/`penalties` should match the return values of the -handler. Specifically the following must hold true: +The provided `deltas` should match the return values of the + handler. Specifically the following must hold true: ```python - rewards == handler(state)[0] - penalties == handler(state)[1] + deltas.rewards == handler(state)[0] + deltas.penalties == handler(state)[1] ```