Refactor genesis.py
This commit is contained in:
parent
62c828bd4b
commit
bb63af53c9
|
@ -7,8 +7,8 @@ from eth2spec.utils import bls
|
||||||
|
|
||||||
from .exceptions import SkippedTest
|
from .exceptions import SkippedTest
|
||||||
from .helpers.constants import (
|
from .helpers.constants import (
|
||||||
PHASE0, ALTAIR, MERGE, SHARDING, CUSTODY_GAME, DAS,
|
PHASE0, ALTAIR,
|
||||||
ALL_PHASES,
|
ALL_PHASES, FORKS_BEFORE_ALTAIR,
|
||||||
)
|
)
|
||||||
from .helpers.genesis import create_genesis_state
|
from .helpers.genesis import create_genesis_state
|
||||||
from .utils import vector_test, with_meta_tags
|
from .utils import vector_test, with_meta_tags
|
||||||
|
@ -362,8 +362,6 @@ def with_configs(configs, reason=None):
|
||||||
|
|
||||||
|
|
||||||
def is_post_altair(spec):
|
def is_post_altair(spec):
|
||||||
# TODO: everything runs in parallel to Altair.
|
if spec.fork in FORKS_BEFORE_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]:
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -18,7 +18,9 @@ DAS = SpecForkName('das')
|
||||||
ALL_PHASES = (PHASE0, ALTAIR)
|
ALL_PHASES = (PHASE0, ALTAIR)
|
||||||
# The forks that output to the test vectors.
|
# The forks that output to the test vectors.
|
||||||
TESTGEN_FORKS = (PHASE0, ALTAIR)
|
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
|
# Config
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
from eth2spec.test.helpers.constants import (
|
||||||
|
ALTAIR,
|
||||||
|
FORKS_BEFORE_ALTAIR,
|
||||||
|
)
|
||||||
from eth2spec.test.helpers.keys import pubkeys
|
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
|
eth1_block_hash = b'\xda' * 32
|
||||||
current_version = spec.GENESIS_FORK_VERSION
|
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
|
current_version = spec.ALTAIR_FORK_VERSION
|
||||||
|
|
||||||
state = spec.BeaconState(
|
state = spec.BeaconState(
|
||||||
genesis_time=0,
|
genesis_time=0,
|
||||||
eth1_deposit_index=len(validator_balances),
|
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:
|
if validator.effective_balance >= activation_threshold:
|
||||||
validator.activation_eligibility_epoch = spec.GENESIS_EPOCH
|
validator.activation_eligibility_epoch = spec.GENESIS_EPOCH
|
||||||
validator.activation_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.previous_epoch_participation.append(spec.ParticipationFlags(0b0000_0000))
|
||||||
state.current_epoch_participation.append(spec.ParticipationFlags(0b0000_0000))
|
state.current_epoch_participation.append(spec.ParticipationFlags(0b0000_0000))
|
||||||
state.inactivity_scores.append(spec.uint64(0))
|
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
|
# Set genesis validators root for domain separation and chain versioning
|
||||||
state.genesis_validators_root = spec.hash_tree_root(state.validators)
|
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
|
# Fill in sync committees
|
||||||
state.current_sync_committee = spec.get_sync_committee(state, spec.get_current_epoch(state))
|
state.current_sync_committee = spec.get_sync_committee(state, spec.get_current_epoch(state))
|
||||||
state.next_sync_committee = (
|
state.next_sync_committee = (
|
||||||
|
|
Loading…
Reference in New Issue