Refactor genesis.py

This commit is contained in:
Hsiao-Wei Wang 2021-04-13 23:21:40 +08:00
parent 62c828bd4b
commit bb63af53c9
No known key found for this signature in database
GPG Key ID: 1111A8A81778319E
3 changed files with 15 additions and 9 deletions

View File

@ -7,8 +7,8 @@ from eth2spec.utils import bls
from .exceptions import SkippedTest
from .helpers.constants import (
PHASE0, ALTAIR, MERGE, SHARDING, CUSTODY_GAME, DAS,
ALL_PHASES,
PHASE0, ALTAIR,
ALL_PHASES, FORKS_BEFORE_ALTAIR,
)
from .helpers.genesis import create_genesis_state
from .utils import vector_test, with_meta_tags
@ -362,8 +362,6 @@ def with_configs(configs, reason=None):
def is_post_altair(spec):
# TODO: everything runs in parallel to Altair.
# After features are rebased on the Altair fork, this can be reduced to just PHASE0.
if spec.fork in [PHASE0, MERGE, SHARDING, CUSTODY_GAME, DAS]:
if spec.fork in FORKS_BEFORE_ALTAIR:
return False
return True

View File

@ -18,7 +18,9 @@ DAS = SpecForkName('das')
ALL_PHASES = (PHASE0, ALTAIR)
# The forks that output to the test vectors.
TESTGEN_FORKS = (PHASE0, ALTAIR)
# TODO: everything runs in parallel to Altair.
# After features are rebased on the Altair fork, this can be reduced to just PHASE0.
FORKS_BEFORE_ALTAIR = (PHASE0, MERGE, SHARDING, CUSTODY_GAME, DAS)
#
# Config

View File

@ -1,3 +1,7 @@
from eth2spec.test.helpers.constants import (
ALTAIR,
FORKS_BEFORE_ALTAIR,
)
from eth2spec.test.helpers.keys import pubkeys
@ -21,8 +25,10 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
eth1_block_hash = b'\xda' * 32
current_version = spec.GENESIS_FORK_VERSION
if spec.fork == 'altair': # TODO: fix `context.py` dependency
if spec.fork == ALTAIR:
current_version = spec.ALTAIR_FORK_VERSION
state = spec.BeaconState(
genesis_time=0,
eth1_deposit_index=len(validator_balances),
@ -50,7 +56,7 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
if validator.effective_balance >= activation_threshold:
validator.activation_eligibility_epoch = spec.GENESIS_EPOCH
validator.activation_epoch = spec.GENESIS_EPOCH
if spec.fork != 'phase0': # TODO: fix `context.py` dependency
if spec.fork not in FORKS_BEFORE_ALTAIR:
state.previous_epoch_participation.append(spec.ParticipationFlags(0b0000_0000))
state.current_epoch_participation.append(spec.ParticipationFlags(0b0000_0000))
state.inactivity_scores.append(spec.uint64(0))
@ -58,7 +64,7 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
# Set genesis validators root for domain separation and chain versioning
state.genesis_validators_root = spec.hash_tree_root(state.validators)
if spec.fork != 'phase0': # TODO: fix `context.py` dependency
if spec.fork not in FORKS_BEFORE_ALTAIR:
# Fill in sync committees
state.current_sync_committee = spec.get_sync_committee(state, spec.get_current_epoch(state))
state.next_sync_committee = (