Skip to content

Commit

Permalink
clean up more phase1 test references
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Mar 26, 2021
1 parent a6c01f8 commit 0c94be4
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 159 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ check_toc: $(MARKDOWN_FILES:=.toc)
codespell:
codespell . --skip ./.git -I .codespell-whitelist

# TODO: add future merge, sharding, etc. packages to linting.
lint: pyspec
. venv/bin/activate; cd $(PY_SPEC_DIR); \
flake8 --config $(LINTER_CONFIG_FILE) ./eth2spec \
&& mypy --config-file $(LINTER_CONFIG_FILE) -p eth2spec.phase0 -p eth2spec.phase1 -p eth2spec.altair
&& mypy --config-file $(LINTER_CONFIG_FILE) -p eth2spec.phase0 -p eth2spec.altair

lint_generators: pyspec
. venv/bin/activate; cd $(TEST_GENERATORS_DIR); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
compute_aggregate_sync_committee_signature,
)
from eth2spec.test.context import (
PHASE0, PHASE1,
PHASE0,
MAINNET, MINIMAL,
expect_assertion_error,
with_all_phases_except,
Expand Down Expand Up @@ -60,7 +60,7 @@ def get_committee_indices(spec, state, duplicates=False):
state.randao_mixes[randao_index] = hash(state.randao_mixes[randao_index])


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
@always_bls
def test_invalid_signature_missing_participant(spec, state):
Expand All @@ -82,7 +82,7 @@ def test_invalid_signature_missing_participant(spec, state):
yield from run_sync_committee_processing(spec, state, block, expect_exception=True)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
@always_bls
def test_invalid_signature_extra_participant(spec, state):
Expand Down Expand Up @@ -191,7 +191,7 @@ def run_successful_sync_committee_test(spec, state, committee, committee_bits):
)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@with_configs([MINIMAL], reason="to create nonduplicate committee")
@spec_state_test
def test_sync_committee_rewards_nonduplicate_committee(spec, state):
Expand All @@ -207,7 +207,7 @@ def test_sync_committee_rewards_nonduplicate_committee(spec, state):
yield from run_successful_sync_committee_test(spec, state, committee, committee_bits)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@with_configs([MAINNET], reason="to create duplicate committee")
@spec_state_test
def test_sync_committee_rewards_duplicate_committee(spec, state):
Expand All @@ -223,7 +223,7 @@ def test_sync_committee_rewards_duplicate_committee(spec, state):
yield from run_successful_sync_committee_test(spec, state, committee, committee_bits)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
@always_bls
def test_sync_committee_rewards_not_full_participants(spec, state):
Expand All @@ -234,7 +234,7 @@ def test_sync_committee_rewards_not_full_participants(spec, state):
yield from run_successful_sync_committee_test(spec, state, committee, committee_bits)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
@always_bls
def test_invalid_signature_past_block(spec, state):
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_invalid_signature_past_block(spec, state):
yield from run_sync_committee_processing(spec, state, invalid_block, expect_exception=True)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@with_configs([MINIMAL], reason="to produce different committee sets")
@spec_state_test
@always_bls
Expand Down Expand Up @@ -310,7 +310,7 @@ def test_invalid_signature_previous_committee(spec, state):
yield from run_sync_committee_processing(spec, state, block, expect_exception=True)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
@always_bls
@with_configs([MINIMAL], reason="too slow")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from eth2spec.test.context import (
PHASE0, PHASE1,
PHASE0,
MINIMAL,
spec_state_test,
with_all_phases_except,
Expand All @@ -11,7 +11,7 @@
)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
@with_configs([MINIMAL], reason="too slow")
def test_sync_committees_progress(spec, state):
Expand Down
16 changes: 8 additions & 8 deletions tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
compute_aggregate_sync_committee_signature,
)
from eth2spec.test.context import (
PHASE0, PHASE1,
PHASE0,
with_all_phases_except,
spec_state_test,
)
Expand Down Expand Up @@ -40,46 +40,46 @@ def run_sync_committee_sanity_test(spec, state, fraction_full=1.0):
yield 'post', state


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
def test_full_sync_committee_committee(spec, state):
next_epoch(spec, state)
yield from run_sync_committee_sanity_test(spec, state, fraction_full=1.0)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
def test_half_sync_committee_committee(spec, state):
next_epoch(spec, state)
yield from run_sync_committee_sanity_test(spec, state, fraction_full=0.5)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
def test_empty_sync_committee_committee(spec, state):
next_epoch(spec, state)
yield from run_sync_committee_sanity_test(spec, state, fraction_full=0.0)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
def test_full_sync_committee_committee_genesis(spec, state):
yield from run_sync_committee_sanity_test(spec, state, fraction_full=1.0)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
def test_half_sync_committee_committee_genesis(spec, state):
yield from run_sync_committee_sanity_test(spec, state, fraction_full=0.5)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
def test_empty_sync_committee_committee_genesis(spec, state):
yield from run_sync_committee_sanity_test(spec, state, fraction_full=0.0)


@with_all_phases_except([PHASE0, PHASE1])
@with_all_phases_except([PHASE0])
@spec_state_test
def test_inactivity_scores(spec, state):
for _ in range(spec.MIN_EPOCHS_TO_INACTIVITY_PENALTY + 2):
Expand Down
7 changes: 6 additions & 1 deletion tests/core/pyspec/eth2spec/test/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def wrapper(*args, **kw):
return None
run_phases = [phase]

if PHASE0 not in run_phases and ALTAIR not in run_phases:
dump_skipping_message("none of the recognized phases are executable, skipping test.")
return None

available_phases = set(run_phases)
if other_phases is not None:
available_phases |= set(other_phases)
Expand All @@ -346,7 +350,8 @@ def wrapper(*args, **kw):
if ALTAIR in available_phases:
phase_dir[ALTAIR] = spec_altair

# return is ignored whenever multiple phases are ran. If
# return is ignored whenever multiple phases are ran.
# This return is for test generators to emit python generators (yielding test vector outputs)
if PHASE0 in run_phases:
ret = fn(spec=spec_phase0, phases=phase_dir, *args, **kw)
if ALTAIR in run_phases:
Expand Down
47 changes: 9 additions & 38 deletions tests/core/pyspec/eth2spec/test/helpers/attestations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from typing import List

from eth2spec.test.context import expect_assertion_error, PHASE1, is_post_altair
from eth2spec.test.context import expect_assertion_error, is_post_altair
from eth2spec.test.helpers.state import state_transition_and_sign_block, next_epoch, next_slot
from eth2spec.test.helpers.block import build_empty_block_for_next_slot
from eth2spec.test.helpers.shard_transitions import get_shard_transition_of_committee
from eth2spec.test.helpers.keys import privkeys
from eth2spec.utils import bls
from eth2spec.utils.ssz.ssz_typing import Bitlist
Expand Down Expand Up @@ -51,7 +50,7 @@ def run_attestation_processing(spec, state, attestation, valid=True):
yield 'post', state


def build_attestation_data(spec, state, slot, index, shard=None, shard_transition=None, on_time=True):
def build_attestation_data(spec, state, slot, index, shard=None, on_time=True):
assert state.slot >= slot

if slot == state.slot:
Expand Down Expand Up @@ -82,32 +81,11 @@ def build_attestation_data(spec, state, slot, index, shard=None, shard_transitio
target=spec.Checkpoint(epoch=spec.compute_epoch_at_slot(slot), root=epoch_boundary_root),
)

if spec.fork == PHASE1:
if shard is None:
shard = spec.compute_shard_from_committee_index(state, data.index, data.slot)
data.shard = shard

if shard_transition is not None:
last_offset_index = len(shard_transition.shard_data_roots) - 1
data.shard_head_root = shard_transition.shard_states[last_offset_index].latest_block_root
data.shard_transition_root = shard_transition.hash_tree_root()
else:
if on_time:
if data.slot == spec.GENESIS_SLOT:
data.shard_head_root = spec.Root()
data.shard_transition_root = spec.ShardTransition().hash_tree_root()
else:
shard_transition = spec.get_shard_transition(state, shard, shard_blocks=[])
last_offset_index = len(shard_transition.shard_data_roots) - 1
data.shard_head_root = shard_transition.shard_states[last_offset_index].latest_block_root
data.shard_transition_root = shard_transition.hash_tree_root()
else:
data.shard_head_root = state.shard_states[shard].latest_block_root
data.shard_transition_root = spec.Root()
# if spec.fork == SHARDING # TODO: add extra data for shard voting
return data


def get_valid_on_time_attestation(spec, state, slot=None, index=None, shard_transition=None, signed=False):
def get_valid_on_time_attestation(spec, state, slot=None, index=None, signed=False):
'''
Construct on-time attestation for next slot
'''
Expand All @@ -121,13 +99,12 @@ def get_valid_on_time_attestation(spec, state, slot=None, index=None, shard_tran
state,
slot=slot,
index=index,
shard_transition=shard_transition,
signed=signed,
on_time=True,
)


def get_valid_late_attestation(spec, state, slot=None, index=None, signed=False, shard_transition=None):
def get_valid_late_attestation(spec, state, slot=None, index=None, signed=False):
'''
Construct on-time attestation for next slot
'''
Expand All @@ -137,15 +114,14 @@ def get_valid_late_attestation(spec, state, slot=None, index=None, signed=False,
index = 0

return get_valid_attestation(spec, state, slot=slot, index=index,
signed=signed, on_time=False, shard_transition=shard_transition)
signed=signed, on_time=False)


def get_valid_attestation(spec,
state,
slot=None,
index=None,
filter_participant_set=None,
shard_transition=None,
signed=False,
on_time=True):
# If filter_participant_set filters everything, the attestation has 0 participants, and cannot be signed.
Expand All @@ -156,7 +132,7 @@ def get_valid_attestation(spec,
index = 0

attestation_data = build_attestation_data(
spec, state, slot=slot, index=index, shard_transition=shard_transition, on_time=on_time
spec, state, slot=slot, index=index, on_time=on_time
)

beacon_committee = spec.get_beacon_committee(
Expand Down Expand Up @@ -258,16 +234,11 @@ def next_epoch_with_attestations(spec,
committees_per_slot = spec.get_committee_count_per_slot(state, spec.compute_epoch_at_slot(slot_to_attest))
if slot_to_attest >= spec.compute_start_slot_at_epoch(spec.get_current_epoch(post_state)):
for index in range(committees_per_slot):
if spec.fork == PHASE1:
shard = spec.compute_shard_from_committee_index(post_state, index, slot_to_attest)
shard_transition = get_shard_transition_of_committee(spec, post_state, index)
block.body.shard_transitions[shard] = shard_transition
else:
shard_transition = None
# if spec.fork == SHARDING: TODO: add shard data to attestation, include shard headers in block

cur_attestation = get_valid_attestation(
spec, post_state, slot_to_attest,
shard_transition=shard_transition, index=index, signed=True, on_time=True
index=index, signed=True, on_time=True
)
block.body.attestations.append(cur_attestation)

Expand Down
10 changes: 6 additions & 4 deletions tests/core/pyspec/eth2spec/test/helpers/block_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def get_process_calls(spec):
lambda state, block: for_ops(state, block.body.proposer_slashings, spec.process_proposer_slashing),
'process_attester_slashing':
lambda state, block: for_ops(state, block.body.attester_slashings, spec.process_attester_slashing),
'process_shard_header':
lambda state, block: for_ops(state, block.body.shard_headers, spec.process_shard_header),
'process_attestation':
lambda state, block: for_ops(state, block.body.attestations, spec.process_attestation),
'process_deposit':
Expand All @@ -25,12 +27,12 @@ def get_process_calls(spec):
# Altair
'process_sync_committee':
lambda state, block: spec.process_sync_committee(state, block.body.sync_aggregate),
# PHASE1
# Merge
'process_application_payload':
lambda state, block: spec.process_application_payload(state, block.body),
# Proof of custody
'process_custody_game_operations':
lambda state, block: spec.process_custody_game_operations(state, block.body),
'process_shard_transitions':
lambda state, block: spec.process_shard_transitions(
state, block.body.shard_transitions, block.body.attestations),
}


Expand Down
15 changes: 10 additions & 5 deletions tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@


def get_process_calls(spec):
# unrecognized processing functions will be ignored.
# This sums up the aggregate of processing functions of all phases.
# Note: make sure to explicitly remove/override a processing function in later phases,
# or the old function will stick around.
return [
# PHASE0
'process_justification_and_finalization',
'process_rewards_and_penalties',
'process_registry_updates',
'process_reveal_deadlines',
'process_challenge_deadlines',
'process_reveal_deadlines', # proof of custody
'process_challenge_deadlines', # proof of custody
'process_slashings',
'process_pending_header.', # sharding
'charge_confirmed_header_fees', # sharding
'reset_pending_headers', # sharding
'process_eth1_data_reset',
'process_effective_balance_updates',
'process_slashings_reset',
Expand All @@ -21,8 +27,7 @@ def get_process_calls(spec):
'process_participation_record_updates'
),
'process_sync_committee_updates',
# PHASE1
'process_phase_1_final_updates',
'process_shard_epoch_increment' # sharding
]


Expand Down
Loading

0 comments on commit 0c94be4

Please sign in to comment.