From 3fe8afc602c5cd117fd7f1274751274f5d29c244 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Sun, 7 Apr 2019 13:06:06 +0800 Subject: [PATCH 1/8] add xiao long bao state machine --- .../forks/xiao_long_bao/__init__.py | 50 +++++++++++++++++++ .../forks/xiao_long_bao/configs.py | 22 ++++++++ 2 files changed, 72 insertions(+) create mode 100644 eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py create mode 100644 eth2/beacon/state_machines/forks/xiao_long_bao/configs.py diff --git a/eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py b/eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py new file mode 100644 index 0000000000..0bccb1cc8f --- /dev/null +++ b/eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py @@ -0,0 +1,50 @@ +from typing import ( # noqa: F401, + Type +) + +from eth2.beacon.state_machines.base import ( + BeaconStateMachine, +) +from eth2.beacon.state_machines.forks.serenity.blocks import ( + SerenityBeaconBlock, + create_serenity_block_from_parent, +) +from eth2.beacon.state_machines.forks.serenity.state_transitions import ( + SerenityStateTransition, +) +from eth2.beacon.state_machines.forks.serenity.states import ( + SerenityBeaconState, +) +from eth2.beacon.state_machines.state_transitions import ( # noqa: F401, + BaseStateTransition, +) +from eth2.beacon.types.blocks import ( # noqa: F401, + BaseBeaconBlock, +) +from eth2.beacon.types.states import ( # noqa: F401, + BeaconState, +) +from eth2.beacon.typing import ( + FromBlockParams, +) + +from .configs import ( + XIAO_LONG_BAO_CONFIG, +) + + +class XiaoLongBaoStateMachine(BeaconStateMachine): + # fork name + fork = 'xiao_long_bao' # type: str + + # classes + block_class = SerenityBeaconBlock # type: Type[BaseBeaconBlock] + state_class = SerenityBeaconState # type: Type[BeaconState] + state_transition_class = SerenityStateTransition # type: Type[BaseStateTransition] + config = XIAO_LONG_BAO_CONFIG + + # methods + @staticmethod + def create_block_from_parent(parent_block: BaseBeaconBlock, + block_params: FromBlockParams) -> BaseBeaconBlock: + return create_serenity_block_from_parent(parent_block, block_params) diff --git a/eth2/beacon/state_machines/forks/xiao_long_bao/configs.py b/eth2/beacon/state_machines/forks/xiao_long_bao/configs.py new file mode 100644 index 0000000000..7957b1eb29 --- /dev/null +++ b/eth2/beacon/state_machines/forks/xiao_long_bao/configs.py @@ -0,0 +1,22 @@ +from eth2.beacon.helpers import ( + slot_to_epoch, +) +from eth2.beacon.state_machines.forks.serenity.configs import ( + SERENITY_CONFIG, +) +from eth2.beacon.typing import ( + Slot, +) + +SLOTS_PER_EPOCH = 4 +GENESIS_SLOT = Slot(32) + + +XIAO_LONG_BAO_CONFIG = SERENITY_CONFIG._replace( + SLOTS_PER_EPOCH=SLOTS_PER_EPOCH, + GENESIS_SLOT=GENESIS_SLOT, + GENESIS_EPOCH=slot_to_epoch(GENESIS_SLOT, SLOTS_PER_EPOCH), + TARGET_COMMITTEE_SIZE=2, + SHARD_COUNT=2, + MIN_ATTESTATION_INCLUSION_DELAY=2, +) From a401923b7fcdfc8aa927bbe3471bee83e2e3e330 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Sun, 7 Apr 2019 21:10:48 +0800 Subject: [PATCH 2/8] add testnet chain --- eth2/beacon/chains/base.py | 16 ++++++------- eth2/beacon/chains/testnet/__init__.py | 32 +++++++++++++++++++++++++ eth2/beacon/chains/testnet/constants.py | 6 +++++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 eth2/beacon/chains/testnet/__init__.py create mode 100644 eth2/beacon/chains/testnet/constants.py diff --git a/eth2/beacon/chains/base.py b/eth2/beacon/chains/base.py index d09f30edf6..c7caf3f3a1 100644 --- a/eth2/beacon/chains/base.py +++ b/eth2/beacon/chains/base.py @@ -40,7 +40,7 @@ BlockClassError, StateMachineNotFound, ) -from eth2.beacon.state_machines.base import BaseBeaconStateMachine # noqa: F401 +from eth2.beacon.state_machines.base import BeaconStateMachine # noqa: F401 from eth2.beacon.types.blocks import ( BaseBeaconBlock, ) @@ -60,7 +60,7 @@ class BaseBeaconChain(Configurable, ABC): """ chaindb = None # type: BaseBeaconChainDB chaindb_class = None # type: Type[BaseBeaconChainDB] - sm_configuration = None # type: Tuple[Tuple[int, Type[BaseBeaconStateMachine]], ...] + sm_configuration = None # type: Tuple[Tuple[Slot, Type[BeaconStateMachine]], ...] chain_id = None # type: int # @@ -89,18 +89,18 @@ def from_genesis(cls, @abstractmethod def get_state_machine_class( cls, - block: BaseBeaconBlock) -> Type['BaseBeaconStateMachine']: + block: BaseBeaconBlock) -> Type['BeaconStateMachine']: pass @abstractmethod - def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BaseBeaconStateMachine': + def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BeaconStateMachine': pass @classmethod @abstractmethod def get_state_machine_class_for_block_slot( cls, - slot: Slot) -> Type['BaseBeaconStateMachine']: + slot: Slot) -> Type['BeaconStateMachine']: pass # @@ -224,7 +224,7 @@ def _from_genesis_block(cls, # StateMachine API # @classmethod - def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BaseBeaconStateMachine']: + def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BeaconStateMachine']: """ Returns the ``StateMachine`` instance for the given block slot number. """ @@ -233,7 +233,7 @@ def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BaseBeaconStat @classmethod def get_state_machine_class_for_block_slot( cls, - slot: Slot) -> Type['BaseBeaconStateMachine']: + slot: Slot) -> Type['BeaconStateMachine']: """ Return the ``StateMachine`` class for the given block slot number. """ @@ -246,7 +246,7 @@ def get_state_machine_class_for_block_slot( return sm_class raise StateMachineNotFound("No StateMachine available for block slot: #{0}".format(slot)) - def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BaseBeaconStateMachine': + def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BeaconStateMachine': """ Return the ``StateMachine`` instance for the given block number. """ diff --git a/eth2/beacon/chains/testnet/__init__.py b/eth2/beacon/chains/testnet/__init__.py new file mode 100644 index 0000000000..5036dadac3 --- /dev/null +++ b/eth2/beacon/chains/testnet/__init__.py @@ -0,0 +1,32 @@ +from typing import ( # noqa: F401 + Tuple, + Type, + ) + +from eth2.beacon.chains.base import ( + BeaconChain, +) +from eth2.beacon.state_machines.base import ( # noqa: F401 + BaseBeaconStateMachine, +) +from eth2.beacon.state_machines.forks.xiao_long_bao import ( + XiaoLongBaoStateMachine, +) +from eth2.beacon.typing import ( # noqa: F401 + Slot, +) + +from .constants import GENESIS_SLOT, TESTNET_CHAIN_ID + +TESTNET_SM_CONFIGURATION = ( + (GENESIS_SLOT, XiaoLongBaoStateMachine), +) + + +class BaseTestnetChain: + sm_configuration = TESTNET_SM_CONFIGURATION # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...] # noqa: E501 + chain_id = TESTNET_CHAIN_ID # type: int + + +class TestnetChain(BaseTestnetChain, BeaconChain): + pass diff --git a/eth2/beacon/chains/testnet/constants.py b/eth2/beacon/chains/testnet/constants.py new file mode 100644 index 0000000000..6f817b31ee --- /dev/null +++ b/eth2/beacon/chains/testnet/constants.py @@ -0,0 +1,6 @@ +from eth2.beacon.typing import ( + Slot, +) + +GENESIS_SLOT = Slot(2**32) +TESTNET_CHAIN_ID = 5566 From eef82725bae348ccbf2ea763de8cee6f4ebeb455 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Sun, 7 Apr 2019 21:11:43 +0800 Subject: [PATCH 3/8] add missing async chaindb method --- tests/core/p2p-proto/bcc/helpers.py | 1 + trinity/db/beacon/chain.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tests/core/p2p-proto/bcc/helpers.py b/tests/core/p2p-proto/bcc/helpers.py index 16fee14bb1..a566f78d03 100644 --- a/tests/core/p2p-proto/bcc/helpers.py +++ b/tests/core/p2p-proto/bcc/helpers.py @@ -54,6 +54,7 @@ def __init__(self, db: BaseAtomicDB) -> None: coro_get_canonical_block_by_slot = async_passthrough('get_canonical_block_by_slot') coro_get_canonical_block_root_by_slot = async_passthrough('get_canonical_block_root_by_slot') coro_get_canonical_head = async_passthrough('get_canonical_head') + coro_get_canonical_head_root = async_passthrough('get_canonical_head_root') coro_get_finalized_head = async_passthrough('get_finalized_head') coro_get_block_by_root = async_passthrough('get_block_by_root') coro_get_score = async_passthrough('get_score') diff --git a/trinity/db/beacon/chain.py b/trinity/db/beacon/chain.py index 550dc35b45..4f7e029247 100644 --- a/trinity/db/beacon/chain.py +++ b/trinity/db/beacon/chain.py @@ -63,6 +63,10 @@ async def coro_get_canonical_block_root_by_slot(self, slot: int) -> Hash32: async def coro_get_canonical_head(self, block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock: pass + @abstractmethod + async def coro_get_canonical_head_root(self)-> Hash32: + pass + @abstractmethod async def coro_get_finalized_head(self, block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock: pass @@ -124,6 +128,7 @@ class AsyncBeaconChainDBPreProxy(BaseAsyncBeaconChainDB): coro_get_canonical_block_by_slot = async_method('get_canonical_block_by_slot') coro_get_canonical_block_root_by_slot = async_method('get_canonical_block_root_by_slot') coro_get_canonical_head = async_method('get_canonical_head') + coro_get_canonical_head_root = async_method('get_canonical_head_root') coro_get_finalized_head = async_method('get_finalized_head') coro_get_block_by_root = async_method('get_block_by_root') coro_get_score = async_method('get_score') From ae03f0ccfd2d6bb4c283f342c596e561e2e14cd8 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Mon, 8 Apr 2019 10:51:59 +0800 Subject: [PATCH 4/8] test new state machine class and new chain class are well defined --- .../chains/{test_chain.py => test_beacon_chain.py} | 0 tests/eth2/beacon/chains/test_chains.py | 13 +++++++++++++ .../state_machines/forks/test_fork_classes.py | 13 +++++++++++++ 3 files changed, 26 insertions(+) rename tests/eth2/beacon/chains/{test_chain.py => test_beacon_chain.py} (100%) create mode 100644 tests/eth2/beacon/chains/test_chains.py create mode 100644 tests/eth2/beacon/state_machines/forks/test_fork_classes.py diff --git a/tests/eth2/beacon/chains/test_chain.py b/tests/eth2/beacon/chains/test_beacon_chain.py similarity index 100% rename from tests/eth2/beacon/chains/test_chain.py rename to tests/eth2/beacon/chains/test_beacon_chain.py diff --git a/tests/eth2/beacon/chains/test_chains.py b/tests/eth2/beacon/chains/test_chains.py new file mode 100644 index 0000000000..32347ab65a --- /dev/null +++ b/tests/eth2/beacon/chains/test_chains.py @@ -0,0 +1,13 @@ +import pytest +from eth2.beacon.chains.testnet import TestnetChain + + +@pytest.mark.parametrize( + "chain_klass", + ( + TestnetChain, + ) +) +def test_chain_class_well_defined(chain_klass): + chain = chain_klass(None) + assert chain.sm_configuration is not () diff --git a/tests/eth2/beacon/state_machines/forks/test_fork_classes.py b/tests/eth2/beacon/state_machines/forks/test_fork_classes.py new file mode 100644 index 0000000000..7733dd503f --- /dev/null +++ b/tests/eth2/beacon/state_machines/forks/test_fork_classes.py @@ -0,0 +1,13 @@ +import pytest +from eth2.beacon.state_machines.forks.xiao_long_bao import XiaoLongBaoStateMachine + + +@pytest.mark.parametrize( + "sm_klass", + ( + XiaoLongBaoStateMachine, + ) +) +def test_sm_class_well_defined(sm_klass): + state_machine = sm_klass(chaindb=None, block=None) + assert state_machine.get_block_class() From 150155df49c0c675c43cd195e2493e10395a1f36 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Tue, 16 Apr 2019 13:25:31 +1000 Subject: [PATCH 5/8] fix linting, typing, sort import --- eth2/beacon/chains/base.py | 54 ++++++++++--------- eth2/beacon/chains/testnet/__init__.py | 34 ++++++------ .../forks/xiao_long_bao/__init__.py | 20 ++----- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/eth2/beacon/chains/base.py b/eth2/beacon/chains/base.py index c7caf3f3a1..e7017ee84a 100644 --- a/eth2/beacon/chains/base.py +++ b/eth2/beacon/chains/base.py @@ -1,38 +1,38 @@ from abc import ( ABC, - abstractmethod + abstractmethod, ) +import logging from typing import ( + TYPE_CHECKING, Tuple, Type, ) -import logging - -from eth_typing import ( - Hash32, +from eth._utils.datatypes import ( + Configurable, ) -from eth_utils import ( - encode_hex, - ValidationError, +from eth.db.backends.base import ( + BaseAtomicDB, ) - -from eth.db.backends.base import BaseAtomicDB from eth.exceptions import ( BlockNotFound, ) from eth.validation import ( validate_word, ) - -from eth._utils.datatypes import ( - Configurable, +from eth_typing import ( + Hash32, +) +from eth_utils import ( + ValidationError, + encode_hex, ) + from eth2._utils.ssz import ( validate_imported_block_unchanged, ) - -from eth2.beacon.db.chain import ( # noqa: F401 +from eth2.beacon.db.chain import ( BaseBeaconChainDB, BeaconChainDB, ) @@ -40,11 +40,12 @@ BlockClassError, StateMachineNotFound, ) -from eth2.beacon.state_machines.base import BeaconStateMachine # noqa: F401 from eth2.beacon.types.blocks import ( BaseBeaconBlock, ) -from eth2.beacon.types.states import BeaconState +from eth2.beacon.types.states import ( + BeaconState, +) from eth2.beacon.typing import ( FromBlockParams, Slot, @@ -53,6 +54,11 @@ validate_slot, ) +if TYPE_CHECKING: + from eth2.beacon.state_machines.base import ( # noqa: F401 + BaseBeaconStateMachine, + ) + class BaseBeaconChain(Configurable, ABC): """ @@ -60,7 +66,7 @@ class BaseBeaconChain(Configurable, ABC): """ chaindb = None # type: BaseBeaconChainDB chaindb_class = None # type: Type[BaseBeaconChainDB] - sm_configuration = None # type: Tuple[Tuple[Slot, Type[BeaconStateMachine]], ...] + sm_configuration = None # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...] chain_id = None # type: int # @@ -89,18 +95,18 @@ def from_genesis(cls, @abstractmethod def get_state_machine_class( cls, - block: BaseBeaconBlock) -> Type['BeaconStateMachine']: + block: BaseBeaconBlock) -> Type['BaseBeaconStateMachine']: pass @abstractmethod - def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BeaconStateMachine': + def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BaseBeaconStateMachine': pass @classmethod @abstractmethod def get_state_machine_class_for_block_slot( cls, - slot: Slot) -> Type['BeaconStateMachine']: + slot: Slot) -> Type['BaseBeaconStateMachine']: pass # @@ -224,7 +230,7 @@ def _from_genesis_block(cls, # StateMachine API # @classmethod - def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BeaconStateMachine']: + def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BaseBeaconStateMachine']: """ Returns the ``StateMachine`` instance for the given block slot number. """ @@ -233,7 +239,7 @@ def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BeaconStateMac @classmethod def get_state_machine_class_for_block_slot( cls, - slot: Slot) -> Type['BeaconStateMachine']: + slot: Slot) -> Type['BaseBeaconStateMachine']: """ Return the ``StateMachine`` class for the given block slot number. """ @@ -246,7 +252,7 @@ def get_state_machine_class_for_block_slot( return sm_class raise StateMachineNotFound("No StateMachine available for block slot: #{0}".format(slot)) - def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BeaconStateMachine': + def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BaseBeaconStateMachine': """ Return the ``StateMachine`` instance for the given block number. """ diff --git a/eth2/beacon/chains/testnet/__init__.py b/eth2/beacon/chains/testnet/__init__.py index 5036dadac3..724c12cd5b 100644 --- a/eth2/beacon/chains/testnet/__init__.py +++ b/eth2/beacon/chains/testnet/__init__.py @@ -1,31 +1,35 @@ -from typing import ( # noqa: F401 - Tuple, - Type, - ) - +from typing import ( + TYPE_CHECKING, +) from eth2.beacon.chains.base import ( BeaconChain, ) -from eth2.beacon.state_machines.base import ( # noqa: F401 - BaseBeaconStateMachine, -) from eth2.beacon.state_machines.forks.xiao_long_bao import ( XiaoLongBaoStateMachine, ) -from eth2.beacon.typing import ( # noqa: F401 - Slot, -) - from .constants import GENESIS_SLOT, TESTNET_CHAIN_ID +if TYPE_CHECKING: + from eth2.beacon.typing import ( # noqa: F401 + Slot, + ) + from eth2.beacon.state_machines.base import ( # noqa: F401 + BaseBeaconStateMachine, + ) + from typing import ( # noqa: F401 + Tuple, + Type, + ) + + TESTNET_SM_CONFIGURATION = ( (GENESIS_SLOT, XiaoLongBaoStateMachine), -) +) # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...] class BaseTestnetChain: - sm_configuration = TESTNET_SM_CONFIGURATION # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...] # noqa: E501 - chain_id = TESTNET_CHAIN_ID # type: int + sm_configuration = TESTNET_SM_CONFIGURATION + chain_id = TESTNET_CHAIN_ID class TestnetChain(BaseTestnetChain, BeaconChain): diff --git a/eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py b/eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py index 0bccb1cc8f..b66262c6a3 100644 --- a/eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py +++ b/eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py @@ -1,7 +1,3 @@ -from typing import ( # noqa: F401, - Type -) - from eth2.beacon.state_machines.base import ( BeaconStateMachine, ) @@ -15,15 +11,9 @@ from eth2.beacon.state_machines.forks.serenity.states import ( SerenityBeaconState, ) -from eth2.beacon.state_machines.state_transitions import ( # noqa: F401, - BaseStateTransition, -) -from eth2.beacon.types.blocks import ( # noqa: F401, +from eth2.beacon.types.blocks import ( BaseBeaconBlock, ) -from eth2.beacon.types.states import ( # noqa: F401, - BeaconState, -) from eth2.beacon.typing import ( FromBlockParams, ) @@ -35,12 +25,12 @@ class XiaoLongBaoStateMachine(BeaconStateMachine): # fork name - fork = 'xiao_long_bao' # type: str + fork = 'xiao_long_bao' # classes - block_class = SerenityBeaconBlock # type: Type[BaseBeaconBlock] - state_class = SerenityBeaconState # type: Type[BeaconState] - state_transition_class = SerenityStateTransition # type: Type[BaseStateTransition] + block_class = SerenityBeaconBlock + state_class = SerenityBeaconState + state_transition_class = SerenityStateTransition config = XIAO_LONG_BAO_CONFIG # methods From 3fa905e4e919df0279024a32176abf529d1a58df Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Tue, 16 Apr 2019 14:39:12 +1000 Subject: [PATCH 6/8] don't define GENESIS_SLOT in custom chain and state machine now --- eth2/beacon/chains/testnet/__init__.py | 11 +++++++++-- eth2/beacon/chains/testnet/constants.py | 5 +---- .../state_machines/forks/xiao_long_bao/configs.py | 9 ++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/eth2/beacon/chains/testnet/__init__.py b/eth2/beacon/chains/testnet/__init__.py index 724c12cd5b..f56974b596 100644 --- a/eth2/beacon/chains/testnet/__init__.py +++ b/eth2/beacon/chains/testnet/__init__.py @@ -7,7 +7,13 @@ from eth2.beacon.state_machines.forks.xiao_long_bao import ( XiaoLongBaoStateMachine, ) -from .constants import GENESIS_SLOT, TESTNET_CHAIN_ID +from .constants import ( + TESTNET_CHAIN_ID, +) +from eth2.beacon.state_machines.forks.serenity.configs import ( + SERENITY_CONFIG, +) + if TYPE_CHECKING: from eth2.beacon.typing import ( # noqa: F401 @@ -23,7 +29,8 @@ TESTNET_SM_CONFIGURATION = ( - (GENESIS_SLOT, XiaoLongBaoStateMachine), + # FIXME: Shouldn't access GENESIS_SLOT from a particular state machine configs. + (SERENITY_CONFIG.GENESIS_SLOT, XiaoLongBaoStateMachine), ) # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...] diff --git a/eth2/beacon/chains/testnet/constants.py b/eth2/beacon/chains/testnet/constants.py index 6f817b31ee..ad449a21db 100644 --- a/eth2/beacon/chains/testnet/constants.py +++ b/eth2/beacon/chains/testnet/constants.py @@ -1,6 +1,3 @@ -from eth2.beacon.typing import ( - Slot, -) -GENESIS_SLOT = Slot(2**32) + TESTNET_CHAIN_ID = 5566 diff --git a/eth2/beacon/state_machines/forks/xiao_long_bao/configs.py b/eth2/beacon/state_machines/forks/xiao_long_bao/configs.py index 7957b1eb29..c221d668f0 100644 --- a/eth2/beacon/state_machines/forks/xiao_long_bao/configs.py +++ b/eth2/beacon/state_machines/forks/xiao_long_bao/configs.py @@ -4,18 +4,13 @@ from eth2.beacon.state_machines.forks.serenity.configs import ( SERENITY_CONFIG, ) -from eth2.beacon.typing import ( - Slot, -) -SLOTS_PER_EPOCH = 4 -GENESIS_SLOT = Slot(32) +SLOTS_PER_EPOCH = 4 XIAO_LONG_BAO_CONFIG = SERENITY_CONFIG._replace( SLOTS_PER_EPOCH=SLOTS_PER_EPOCH, - GENESIS_SLOT=GENESIS_SLOT, - GENESIS_EPOCH=slot_to_epoch(GENESIS_SLOT, SLOTS_PER_EPOCH), + GENESIS_EPOCH=slot_to_epoch(SERENITY_CONFIG.GENESIS_SLOT, SLOTS_PER_EPOCH), TARGET_COMMITTEE_SIZE=2, SHARD_COUNT=2, MIN_ATTESTATION_INCLUSION_DELAY=2, From af18ca989e36ca940387754fff8b8419d7abe4eb Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 18 Apr 2019 18:38:21 +0800 Subject: [PATCH 7/8] Update tests/eth2/beacon/chains/test_chains.py Co-Authored-By: ChihChengLiang --- tests/eth2/beacon/chains/test_chains.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/eth2/beacon/chains/test_chains.py b/tests/eth2/beacon/chains/test_chains.py index 32347ab65a..394fb52249 100644 --- a/tests/eth2/beacon/chains/test_chains.py +++ b/tests/eth2/beacon/chains/test_chains.py @@ -10,4 +10,4 @@ ) def test_chain_class_well_defined(chain_klass): chain = chain_klass(None) - assert chain.sm_configuration is not () + assert chain.sm_configuration is not () and chain.sm_configuration is not None From 0faeb2ddbd0fad4e3aea3345c2a70fc115a3f47d Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Thu, 18 Apr 2019 18:48:08 +0800 Subject: [PATCH 8/8] apply PR feedback --- eth2/beacon/chains/testnet/__init__.py | 7 +++---- .../beacon/state_machines/forks/test_fork_classes.py | 9 ++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/eth2/beacon/chains/testnet/__init__.py b/eth2/beacon/chains/testnet/__init__.py index f56974b596..53c51a611d 100644 --- a/eth2/beacon/chains/testnet/__init__.py +++ b/eth2/beacon/chains/testnet/__init__.py @@ -7,13 +7,12 @@ from eth2.beacon.state_machines.forks.xiao_long_bao import ( XiaoLongBaoStateMachine, ) -from .constants import ( - TESTNET_CHAIN_ID, -) from eth2.beacon.state_machines.forks.serenity.configs import ( SERENITY_CONFIG, ) - +from .constants import ( + TESTNET_CHAIN_ID, +) if TYPE_CHECKING: from eth2.beacon.typing import ( # noqa: F401 diff --git a/tests/eth2/beacon/state_machines/forks/test_fork_classes.py b/tests/eth2/beacon/state_machines/forks/test_fork_classes.py index 7733dd503f..e583057d1a 100644 --- a/tests/eth2/beacon/state_machines/forks/test_fork_classes.py +++ b/tests/eth2/beacon/state_machines/forks/test_fork_classes.py @@ -1,10 +1,17 @@ import pytest -from eth2.beacon.state_machines.forks.xiao_long_bao import XiaoLongBaoStateMachine + +from eth2.beacon.state_machines.forks.serenity import ( + SerenityStateMachine, +) +from eth2.beacon.state_machines.forks.xiao_long_bao import ( + XiaoLongBaoStateMachine, +) @pytest.mark.parametrize( "sm_klass", ( + SerenityStateMachine, XiaoLongBaoStateMachine, ) )