-
Notifications
You must be signed in to change notification settings - Fork 145
Add testnet chain and Xiao Long Bao state machine #489
Changes from 6 commits
3fe8afc
a401923
eef8272
ae03f0c
150155d
3fa905e
af18ca9
0faeb2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import ( | ||
TYPE_CHECKING, | ||
) | ||
from eth2.beacon.chains.base import ( | ||
BeaconChain, | ||
) | ||
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, | ||
) | ||
|
||
|
||
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 = ( | ||
# FIXME: Shouldn't access GENESIS_SLOT from a particular state machine configs. | ||
(SERENITY_CONFIG.GENESIS_SLOT, XiaoLongBaoStateMachine), | ||
) # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...] | ||
|
||
|
||
class BaseTestnetChain: | ||
sm_configuration = TESTNET_SM_CONFIGURATION | ||
chain_id = TESTNET_CHAIN_ID | ||
|
||
|
||
class TestnetChain(BaseTestnetChain, BeaconChain): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
TESTNET_CHAIN_ID = 5566 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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.types.blocks import ( | ||
BaseBeaconBlock, | ||
) | ||
from eth2.beacon.typing import ( | ||
FromBlockParams, | ||
) | ||
|
||
from .configs import ( | ||
XIAO_LONG_BAO_CONFIG, | ||
) | ||
|
||
|
||
class XiaoLongBaoStateMachine(BeaconStateMachine): | ||
# fork name | ||
fork = 'xiao_long_bao' | ||
|
||
# classes | ||
block_class = SerenityBeaconBlock | ||
state_class = SerenityBeaconState | ||
state_transition_class = SerenityStateTransition | ||
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from eth2.beacon.helpers import ( | ||
slot_to_epoch, | ||
) | ||
from eth2.beacon.state_machines.forks.serenity.configs import ( | ||
SERENITY_CONFIG, | ||
) | ||
|
||
|
||
SLOTS_PER_EPOCH = 4 | ||
|
||
XIAO_LONG_BAO_CONFIG = SERENITY_CONFIG._replace( | ||
ChihChengLiang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SLOTS_PER_EPOCH=SLOTS_PER_EPOCH, | ||
GENESIS_EPOCH=slot_to_epoch(SERENITY_CONFIG.GENESIS_SLOT, SLOTS_PER_EPOCH), | ||
TARGET_COMMITTEE_SIZE=2, | ||
SHARD_COUNT=2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I understand, do we need to specify 16 validators somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah just that in #465 we use 8 validators. Not a problem. Ignore me. 😅 |
||
MIN_ATTESTATION_INCLUSION_DELAY=2, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 () | ||
ChihChengLiang marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
from eth2.beacon.state_machines.forks.xiao_long_bao import XiaoLongBaoStateMachine | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"sm_klass", | ||
( | ||
XiaoLongBaoStateMachine, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It passes the test. |
||
) | ||
) | ||
def test_sm_class_well_defined(sm_klass): | ||
state_machine = sm_klass(chaindb=None, block=None) | ||
assert state_machine.get_block_class() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it after
from eth2.beacon.state_machines.forks.serenity.configs import ...
.