Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

v0.5.1 state tests #552

Merged
merged 9 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "fixtures"]
path = fixtures
url = https://github.com/ethereum/tests.git
[submodule "eth2-fixtures"]
path = eth2-fixtures
url = [email protected]:ethereum/eth2.0-tests.git
1 change: 1 addition & 0 deletions eth2-fixtures
Submodule eth2-fixtures added at 33e762
2 changes: 2 additions & 0 deletions eth2/beacon/epoch_processing_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def _filter_attestations_by_latest_crosslinks_and_shard(
shard: Shard) -> Iterable[PendingAttestation]:
for attestation in attestations:
is_latest_crosslink_matched = attestation.data.previous_crosslink == latest_crosslink
# NOTE: v0.5.1 doesn't check is_shard_matched but it's fixed in v0.6.0
# We implemented ahead here.
is_shard_matched = attestation.data.shard == shard
if is_latest_crosslink_matched and is_shard_matched:
yield attestation
Expand Down
15 changes: 8 additions & 7 deletions eth2/beacon/state_machines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
Type,
)

from eth_typing import (
Hash32,
)

from eth._utils.datatypes import (
Configurable,
)
Expand Down Expand Up @@ -45,7 +41,8 @@ class BaseBeaconStateMachine(Configurable, ABC):
@abstractmethod
def __init__(self,
chaindb: BaseBeaconChainDB,
block_root: Hash32) -> None:
block: BaseBeaconBlock,
state: BeaconState=None) -> None:
pass

@classmethod
Expand Down Expand Up @@ -87,9 +84,13 @@ def create_block_from_parent(parent_block: BaseBeaconBlock,
class BeaconStateMachine(BaseBeaconStateMachine):
def __init__(self,
chaindb: BaseBeaconChainDB,
block: BaseBeaconBlock) -> None:
block: BaseBeaconBlock,
state: BeaconState=None) -> None:
self.chaindb = chaindb
self.block = block
if state is not None:
self._state = state
else:
self.block = block

@property
def state(self) -> BeaconState:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def process_block_header(state: BeaconState,
validate_proposer_signature(
state,
block,
beacon_chain_shard_number=config.BEACON_CHAIN_SHARD_NUMBER,
committee_config=CommitteeConfig(config),
)

Expand Down
2 changes: 0 additions & 2 deletions eth2/beacon/state_machines/forks/serenity/block_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
from eth2.beacon.typing import (
Bitfield,
Epoch,
Shard,
Slot,
ValidatorIndex,
)
Expand Down Expand Up @@ -101,7 +100,6 @@ def validate_block_previous_root(state: BeaconState,
#
def validate_proposer_signature(state: BeaconState,
block: BaseBeaconBlock,
beacon_chain_shard_number: Shard,
committee_config: CommitteeConfig) -> None:
message_hash = block.signing_root

Expand Down
17 changes: 9 additions & 8 deletions eth2/beacon/state_machines/forks/serenity/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@
# Misc
SHARD_COUNT=2**10, # (= 1,024) shards
TARGET_COMMITTEE_SIZE=2**7, # (= 128) validators
EJECTION_BALANCE=Gwei(2**4 * GWEI_PER_ETH), # (= 16,000,000,000) Gwei
MAX_BALANCE_CHURN_QUOTIENT=2**5, # (= 32)
BEACON_CHAIN_SHARD_NUMBER=Shard(2**64 - 1),
MAX_INDICES_PER_SLASHABLE_VOTE=2**12, # (= 4,096) votes
MAX_EXIT_DEQUEUES_PER_EPOCH=2**2, # (= 4)
SHUFFLE_ROUND_COUNT=90,
# State list lengths
SLOTS_PER_HISTORICAL_ROOT=2**13, # (= 8,192) slots
LATEST_ACTIVE_INDEX_ROOTS_LENGTH=2**13, # (= 8,192) epochs
LATEST_RANDAO_MIXES_LENGTH=2**13, # (= 8,192) epochs
LATEST_SLASHED_EXIT_LENGTH=2**13, # (= 8,192) epochs
# Deposit contract
DEPOSIT_CONTRACT_ADDRESS=ZERO_ADDRESS, # TBD
DEPOSIT_CONTRACT_TREE_DEPTH=2**5, # (= 32)
# Gwei values
MIN_DEPOSIT_AMOUNT=Gwei(2**0 * GWEI_PER_ETH), # (= 1,000,000,000) Gwei
MAX_DEPOSIT_AMOUNT=Gwei(2**5 * GWEI_PER_ETH), # (= 32,000,000,00) Gwei
# Genesis values
FORK_CHOICE_BALANCE_INCREMENT=Gwei(2**0 * GWEI_PER_ETH), # (= 1,000,000,000) Gwei
EJECTION_BALANCE=Gwei(2**4 * GWEI_PER_ETH), # (= 16,000,000,000) Gwei
# Initial values
GENESIS_FORK_VERSION=0,
GENESIS_SLOT=GENESIS_SLOT,
GENESIS_EPOCH=slot_to_epoch(GENESIS_SLOT, SLOTS_PER_EPOCH),
Expand All @@ -53,6 +49,11 @@
EPOCHS_PER_ETH1_VOTING_PERIOD=2**4, # (= 16) epochs
MIN_VALIDATOR_WITHDRAWABILITY_DELAY=2**8, # (= 256) epochs
PERSISTENT_COMMITTEE_PERIOD=2**11, # (= 2,048) epochs
# State list lengths
SLOTS_PER_HISTORICAL_ROOT=2**13, # (= 8,192) slots
LATEST_ACTIVE_INDEX_ROOTS_LENGTH=2**13, # (= 8,192) epochs
LATEST_RANDAO_MIXES_LENGTH=2**13, # (= 8,192) epochs
LATEST_SLASHED_EXIT_LENGTH=2**13, # (= 8,192) epochs
# Reward and penalty quotients
BASE_REWARD_QUOTIENT=2**10, # (= 1,024)
WHISTLEBLOWER_REWARD_QUOTIENT=2**9, # (= 512)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def apply_state_transition(self,
else:
raise Exception(
f"Invariant: state.slot ({state.slot}) should be less "
"than block.slot ({block.slot}) so that state transition terminates"
f"than block.slot ({block.slot}) so that state transition terminates"
)
return state

Expand Down
21 changes: 11 additions & 10 deletions eth2/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,25 @@
# Misc
('SHARD_COUNT', int),
('TARGET_COMMITTEE_SIZE', int),
('EJECTION_BALANCE', Gwei),
('MAX_BALANCE_CHURN_QUOTIENT', int),
('BEACON_CHAIN_SHARD_NUMBER', Shard),
('MAX_INDICES_PER_SLASHABLE_VOTE', int),
('MAX_EXIT_DEQUEUES_PER_EPOCH', int),
('SHUFFLE_ROUND_COUNT', int),
# State list lengths
('SLOTS_PER_HISTORICAL_ROOT', int),
('LATEST_ACTIVE_INDEX_ROOTS_LENGTH', int),
('LATEST_RANDAO_MIXES_LENGTH', int),
('LATEST_SLASHED_EXIT_LENGTH', int),
# EMPTY_SIGNATURE is defined in constants.py
# Deposit contract
('DEPOSIT_CONTRACT_ADDRESS', Address),
('DEPOSIT_CONTRACT_TREE_DEPTH', int),
# Gwei values,
('MIN_DEPOSIT_AMOUNT', Gwei),
('MAX_DEPOSIT_AMOUNT', Gwei),
# ZERO_HASH (ZERO_HASH32) is defined in constants.py
# Genesis values
('FORK_CHOICE_BALANCE_INCREMENT', Gwei),
('EJECTION_BALANCE', Gwei),
# Initial values
('GENESIS_FORK_VERSION', int),
('GENESIS_SLOT', Slot),
('GENESIS_EPOCH', Epoch),
('GENESIS_START_SHARD', Shard),
# `FAR_FUTURE_EPOCH`, `EMPTY_SIGNATURE` `ZERO_HASH (ZERO_HASH32)`
# are defined in constants.py
('BLS_WITHDRAWAL_PREFIX_BYTE', bytes),
# Time parameters
('SECONDS_PER_SLOT', Second),
Expand All @@ -53,6 +49,11 @@
('EPOCHS_PER_ETH1_VOTING_PERIOD', int),
('MIN_VALIDATOR_WITHDRAWABILITY_DELAY', int),
('PERSISTENT_COMMITTEE_PERIOD', int),
# State list lengths
('SLOTS_PER_HISTORICAL_ROOT', int),
('LATEST_ACTIVE_INDEX_ROOTS_LENGTH', int),
('LATEST_RANDAO_MIXES_LENGTH', int),
('LATEST_SLASHED_EXIT_LENGTH', int),
# Reward and penalty quotients
('BASE_REWARD_QUOTIENT', int),
('WHISTLEBLOWER_REWARD_QUOTIENT', int),
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@
"pytest-cov==2.5.1",
"pytest-watch>=4.1.0,<5",
"pytest-xdist==1.18.1",
"pytest-mock==1.10.4",
# only needed for p2p
"pytest-asyncio-network-simulator==0.1.0a2;python_version>='3.6'",
# only for eth2
"ruamel.yaml>=0.15.87,<0.16",
],
'lint': [
"flake8==3.5.0",
Expand Down
70 changes: 35 additions & 35 deletions tests/eth2/beacon/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,11 @@ def target_committee_size():
return SERENITY_CONFIG.TARGET_COMMITTEE_SIZE


@pytest.fixture
def ejection_balance():
return SERENITY_CONFIG.EJECTION_BALANCE


@pytest.fixture
def max_balance_churn_quotient():
return SERENITY_CONFIG.MAX_BALANCE_CHURN_QUOTIENT


@pytest.fixture
def beacon_chain_shard_number():
return SERENITY_CONFIG.BEACON_CHAIN_SHARD_NUMBER


@pytest.fixture
def max_indices_per_slashable_vote():
return SERENITY_CONFIG.MAX_INDICES_PER_SLASHABLE_VOTE
Expand All @@ -482,21 +472,6 @@ def slots_per_historical_root():
return SERENITY_CONFIG.SLOTS_PER_HISTORICAL_ROOT


@pytest.fixture
def latest_active_index_roots_length():
return SERENITY_CONFIG.LATEST_ACTIVE_INDEX_ROOTS_LENGTH


@pytest.fixture
def latest_randao_mixes_length():
return SERENITY_CONFIG.LATEST_RANDAO_MIXES_LENGTH


@pytest.fixture
def latest_slashed_exit_length():
return SERENITY_CONFIG.LATEST_SLASHED_EXIT_LENGTH


@pytest.fixture
def deposit_contract_address():
return SERENITY_CONFIG.DEPOSIT_CONTRACT_ADDRESS
Expand All @@ -517,6 +492,16 @@ def max_deposit_amount():
return SERENITY_CONFIG.MAX_DEPOSIT_AMOUNT


@pytest.fixture
def fork_choice_balance_increment():
return SERENITY_CONFIG.FORK_CHOICE_BALANCE_INCREMENT


@pytest.fixture
def ejection_balance():
return SERENITY_CONFIG.EJECTION_BALANCE


@pytest.fixture
def genesis_fork_version():
return SERENITY_CONFIG.GENESIS_FORK_VERSION
Expand Down Expand Up @@ -582,6 +567,21 @@ def persistent_committee_period():
return SERENITY_CONFIG.PERSISTENT_COMMITTEE_PERIOD


@pytest.fixture
def latest_active_index_roots_length():
return SERENITY_CONFIG.LATEST_ACTIVE_INDEX_ROOTS_LENGTH


@pytest.fixture
def latest_randao_mixes_length():
return SERENITY_CONFIG.LATEST_RANDAO_MIXES_LENGTH


@pytest.fixture
def latest_slashed_exit_length():
return SERENITY_CONFIG.LATEST_SLASHED_EXIT_LENGTH


@pytest.fixture
def base_reward_quotient():
return SERENITY_CONFIG.BASE_REWARD_QUOTIENT
Expand Down Expand Up @@ -724,20 +724,17 @@ def genesis_balances(init_validator_pubkeys, max_deposit_amount):
def config(
shard_count,
target_committee_size,
ejection_balance,
max_balance_churn_quotient,
beacon_chain_shard_number,
max_indices_per_slashable_vote,
max_exit_dequeues_per_epoch,
shuffle_round_count,
slots_per_historical_root,
latest_active_index_roots_length,
latest_randao_mixes_length,
latest_slashed_exit_length,
deposit_contract_address,
deposit_contract_tree_depth,
min_deposit_amount,
max_deposit_amount,
fork_choice_balance_increment,
ejection_balance,
genesis_fork_version,
genesis_slot,
genesis_epoch,
Expand All @@ -751,6 +748,9 @@ def config(
epochs_per_eth1_voting_period,
min_validator_withdrawability_delay,
persistent_committee_period,
latest_active_index_roots_length,
latest_randao_mixes_length,
latest_slashed_exit_length,
base_reward_quotient,
whistleblower_reward_quotient,
attestation_inclusion_reward_quotient,
Expand All @@ -766,20 +766,17 @@ def config(
return Eth2Config(
SHARD_COUNT=shard_count,
TARGET_COMMITTEE_SIZE=target_committee_size,
EJECTION_BALANCE=ejection_balance,
MAX_BALANCE_CHURN_QUOTIENT=max_balance_churn_quotient,
BEACON_CHAIN_SHARD_NUMBER=beacon_chain_shard_number,
MAX_INDICES_PER_SLASHABLE_VOTE=max_indices_per_slashable_vote,
MAX_EXIT_DEQUEUES_PER_EPOCH=max_exit_dequeues_per_epoch,
SHUFFLE_ROUND_COUNT=shuffle_round_count,
SLOTS_PER_HISTORICAL_ROOT=slots_per_historical_root,
LATEST_ACTIVE_INDEX_ROOTS_LENGTH=latest_active_index_roots_length,
LATEST_RANDAO_MIXES_LENGTH=latest_randao_mixes_length,
LATEST_SLASHED_EXIT_LENGTH=latest_slashed_exit_length,
DEPOSIT_CONTRACT_ADDRESS=deposit_contract_address,
DEPOSIT_CONTRACT_TREE_DEPTH=deposit_contract_tree_depth,
MIN_DEPOSIT_AMOUNT=min_deposit_amount,
MAX_DEPOSIT_AMOUNT=max_deposit_amount,
FORK_CHOICE_BALANCE_INCREMENT=fork_choice_balance_increment,
EJECTION_BALANCE=ejection_balance,
GENESIS_FORK_VERSION=genesis_fork_version,
GENESIS_SLOT=genesis_slot,
GENESIS_EPOCH=genesis_epoch,
Expand All @@ -793,6 +790,9 @@ def config(
EPOCHS_PER_ETH1_VOTING_PERIOD=epochs_per_eth1_voting_period,
MIN_VALIDATOR_WITHDRAWABILITY_DELAY=min_validator_withdrawability_delay,
PERSISTENT_COMMITTEE_PERIOD=persistent_committee_period,
LATEST_ACTIVE_INDEX_ROOTS_LENGTH=latest_active_index_roots_length,
LATEST_RANDAO_MIXES_LENGTH=latest_randao_mixes_length,
LATEST_SLASHED_EXIT_LENGTH=latest_slashed_exit_length,
BASE_REWARD_QUOTIENT=base_reward_quotient,
WHISTLEBLOWER_REWARD_QUOTIENT=whistleblower_reward_quotient,
ATTESTATION_INCLUSION_REWARD_QUOTIENT=attestation_inclusion_reward_quotient,
Expand Down
Loading