address PR feedback from @protolambda

This commit is contained in:
Danny Ryan 2020-05-05 15:37:14 -06:00
parent b2dfb6cebe
commit 4f401133e1
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
5 changed files with 26 additions and 34 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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
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]
```