Merge pull request #1653 from ethereum/head-match-target
Must match target to match head
This commit is contained in:
commit
d01d532062
12
setup.py
12
setup.py
|
@ -182,7 +182,17 @@ get_active_validator_indices = cache_this(
|
||||||
_get_beacon_committee = get_beacon_committee
|
_get_beacon_committee = get_beacon_committee
|
||||||
get_beacon_committee = cache_this(
|
get_beacon_committee = cache_this(
|
||||||
lambda state, slot, index: (state.validators.hash_tree_root(), state.randao_mixes.hash_tree_root(), slot, index),
|
lambda state, slot, index: (state.validators.hash_tree_root(), state.randao_mixes.hash_tree_root(), slot, index),
|
||||||
_get_beacon_committee)'''
|
_get_beacon_committee)
|
||||||
|
|
||||||
|
_get_matching_target_attestations = get_matching_target_attestations
|
||||||
|
get_matching_target_attestations = cache_this(
|
||||||
|
lambda state, epoch: (state.hash_tree_root(), epoch),
|
||||||
|
_get_matching_target_attestations)
|
||||||
|
|
||||||
|
_get_matching_head_attestations = get_matching_head_attestations
|
||||||
|
get_matching_head_attestations = cache_this(
|
||||||
|
lambda state, epoch: (state.hash_tree_root(), epoch),
|
||||||
|
_get_matching_head_attestations)'''
|
||||||
|
|
||||||
|
|
||||||
def objects_to_spec(spec_object: SpecObject, imports: str, fork: str) -> str:
|
def objects_to_spec(spec_object: SpecObject, imports: str, fork: str) -> str:
|
||||||
|
|
|
@ -1235,7 +1235,7 @@ def get_matching_target_attestations(state: BeaconState, epoch: Epoch) -> Sequen
|
||||||
```python
|
```python
|
||||||
def get_matching_head_attestations(state: BeaconState, epoch: Epoch) -> Sequence[PendingAttestation]:
|
def get_matching_head_attestations(state: BeaconState, epoch: Epoch) -> Sequence[PendingAttestation]:
|
||||||
return [
|
return [
|
||||||
a for a in get_matching_source_attestations(state, epoch)
|
a for a in get_matching_target_attestations(state, epoch)
|
||||||
if a.data.beacon_block_root == get_block_root_at_slot(state, a.data.slot)
|
if a.data.beacon_block_root == get_block_root_at_slot(state, a.data.slot)
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
|
@ -97,6 +97,29 @@ def test_full_attestations(spec, state):
|
||||||
assert state.balances[index] < pre_state.balances[index]
|
assert state.balances[index] < pre_state.balances[index]
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_full_attestations_random_incorrect_fields(spec, state):
|
||||||
|
attestations = prepare_state_with_full_attestations(spec, state)
|
||||||
|
for i, attestation in enumerate(state.previous_epoch_attestations):
|
||||||
|
if i % 3 == 0:
|
||||||
|
# Mess up some head votes
|
||||||
|
attestation.data.beacon_block_root = b'\x56' * 32
|
||||||
|
if i % 3 == 1:
|
||||||
|
# Message up some target votes
|
||||||
|
attestation.data.target.root = b'\x23' * 32
|
||||||
|
if i % 3 == 2:
|
||||||
|
# Keep some votes 100% correct
|
||||||
|
pass
|
||||||
|
|
||||||
|
yield from run_process_rewards_and_penalties(spec, state)
|
||||||
|
|
||||||
|
attesting_indices = spec.get_unslashed_attesting_indices(state, attestations)
|
||||||
|
assert len(attesting_indices) > 0
|
||||||
|
# No balance checks, non-trivial base on group rewards
|
||||||
|
# Mainly for consensus tests
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_test
|
@spec_test
|
||||||
@with_custom_state(balances_fn=misc_balances, threshold_fn=default_activation_threshold)
|
@with_custom_state(balances_fn=misc_balances, threshold_fn=default_activation_threshold)
|
||||||
|
|
Loading…
Reference in New Issue